//style
jQuery.fn.classswitch = function (_class) { $(this).removeClass(); $(this).addClass(_class); }
jQuery.fn.cssmargin = function() { return 'margin:' + $(this).css('margin-top') + ' ' + $(this).css('margin-right') + ' ' + $(this).css('margin-bottom') + ' ' + $(this).css('margin-left'); }
jQuery.fn.csspadding = function() { return 'padding:' + $(this).css('padding-top') + ' ' + $(this).css('padding-right') + ' ' + $(this).css('padding-bottom') + ' ' + $(this).css('padding-left'); }
jQuery.fn.cssint = function(_attribute) { var _value = parseInt($(this).css(_attribute)); if (isNaN(_value)) { _value = 0; } return _value; }
jQuery.fn.cssZindex = function (_value) { 
	if (_value == '+' || _value == '-') { 
		_zindex = $(this).css('zIndex');
		if (_zindex == null) { _zindex == 0; }
		if ($(this).css('position') != 'absolute') { $(this).css({'position': 'relative'}); }
		if (_zindex == 0) { if ( _value == '+') { $(this).css({'zIndex': 1}); } else if (_value == '-') { $(this).css({'zIndex': 'auto'}); } }
		else { if ( _value == '+') { $(this).css({'zIndex': _z-index + 1}); } else if ( _value == '-') { $(this).css({'zIndex': _z-index - 1}); } } }
	else { $(this).css({'zIndex': _value}); } }
jQuery.fn.cssopacity = function (_value) { $(this).css({opacity: _value}); }
jQuery.fn.cssheight = function (_value) { $(this).css({height: _value + 'px'}); }
jQuery.fn.csswidth = function (_value) { $(this).css({width: _value + 'px'}); }

jQuery.fn.centerY = function (_parent) { if (_parent == 'body') { $(this).css({'marginTop':document.documentElement.clientHeight/2 - $(this).heightplus('box')/2 }); } else { $(this).css({'marginTop':_parent.heightplus('box')/2 - $(this).heightplus('box')/2 }); } }
jQuery.fn.pageheight = function (_offset) { var _height = document.documentElement.clientHeight - _offset; $(this).css({'height': _height  + 'px'}); }
jQuery.fn.hiddenheight = function () { if ($(this).is(':hidden')) { $(this).show(); var _height = $(this).height(); $(this).hide(); } else { var _height = $(this).height(); } return _height; }
jQuery.fn.hiddenwidth = function () { if ($(this).is(':hidden')) { $(this).show(); var _width = $(this).width(); $(this).hide(); } else { var _width = $(this).width(); } return _width; }

jQuery.fn.heightplus = function (_attribute) { 
	if ($(this).is(':hidden')) { $(this).show(); var _hide = "yes"; }
	var _height = $(this).height();
	if (_attribute == "box") { _attribute = 'bp'; }
	else if (_attribute == "footprint") { _attribute = 'bmpt'; }
	var _array = _attribute.split('');
	for (_item in _array) {
		if (_array[_item] == 'b') { _height += ($(this).cssint('border-bottom-width') + $(this).cssint('border-top-width')); }
		else if (_array[_item] == 'm') { _height += ($(this).cssint('margin-bottom') + $(this).cssint('margin-top')); }
		else if (_array[_item] == 'p') { _height += ($(this).cssint('padding-bottom') + $(this).cssint('padding-top')); }
		else if (_array[_item] == 't') { _height += $(this).cssint('top'); }
		else if (_array[_item] == '-') { _height -= $(this).height(); } }
	if (_hide == "yes") { $(this).hide(); } 
	 return _height; }
jQuery.fn.widthplus = function (_attribute) { 
	if ($(this).is(':hidden')) { $(this).show(); var _hide = "yes"; }
	var _width = $(this).width();
	if (_attribute == "box") { _attribute = 'bp'; }
	else if (_attribute == "footprint") { _attribute = 'blmp'; }
	var _array = _attribute.split('');
	for (var _item in _array) {
		if (_array[_item] == 'b') { _width += ($(this).cssint('border-left-width') + $(this).cssint('border-right-width')); }
		else if (_array[_item] == 'l') { _width += $(this).cssint('left'); }
		else if (_array[_item] == 'm') { _width += ($(this).cssint('margin-left') + $(this).cssint('margin-right')); }
		else if (_array[_item] == 'p') { _width += ($(this).cssint('padding-left') + $(this).cssint('padding-right')); }
		else if (_array[_item] == '-') { _width -= $(this).width(); } }
	if (_hide == "yes") { $(this).hide(); } 
	return _width; }

//cookie (_days: -1:delete, null:none)
jQuery.cookiewrite = function (_name, _value, _days) { _value.toString(); if (_days) { var _date = new Date(); _date.setTime(_date.getTime()+(_days*24*60*60*1000)); var _expires = '; expires='+_date.toGMTString(); } else { var _expires = ''; } document.cookie = _name + '=' + _value + _expires + '; path=/'; }	
jQuery.cookieread = function (_name) { var _array = document.cookie.split(';'); for (var _item in _array) { var _this = $.trim(_array[_item]); if (_this.substring(0, _name.length + 1) == (_name + '=')) { return decodeURIComponent(_this.substring(_name.length + 1)); } } }		
jQuery.cookiearray = function (_name) {	if ($.cookieread(_name)) { var _array = $.cookieread(_name).split(','); } else { _array = new Array; } return _array; }
jQuery.cookieupdate = function (_cookie, _add, _delete) { var _current = $.cookiearray(_cookie); if (_delete) { $.arraydelete(_current, _delete); } if (_add) { $.arrayadd(_current, _add); } $.cookiewrite(_cookie, _current); }

//array
jQuery.arrayforce = function (_var) { if (_var instanceof Array == false) { return new Array(_var); } else { return _var; } }
jQuery.arraydelete = function (_haystack, _needle) { $.each($.arrayforce(_needle), function(_key, _value) { _index = $.inArray(_value, _haystack); if (_index != -1) { _haystack.splice(_index, 1); } }); return _haystack; }
jQuery.arrayadd = function (_haystack, _needle) { $.each($.arrayforce(_needle), function(_key, _value) { _index = $.inArray(_value, _haystack); if (_index == -1) { _haystack.push(_value); } }); return _haystack; }
jQuery.idarray = function (_selector) { _array = new Array; $.each(_selector, function(_key, _value) { _array[_key] = _selector.eq(_key).attr('id'); }); return _array; }

//height & width
jQuery.fn.matchheight = function () { var _height = 0; $(this).each(function() { if ($(this).height() > _height) { _height = $(this).height(); } }); $(this).css({'height': _height + 'px'}); }
jQuery.fn.matchwidth = function () { var _width = 0; $(this).each(function() { if ($(this).width() > _width) { _width = $(this).width(); } }); $(this).css({'width': _width + 'px'}); }
jQuery.fn.matchsize = function () { $(this).matchheight(); $(this).matchwidth(); }

//img
jQuery.fn.imgsquare = function() {
	$(this).each(function() {
		var _padding = parseInt($(this).css('padding-top')); var _width = $(this).attr('width'); var _height = $(this).attr('height');
		if (_width > _height) { _buffer = ((_width - _height) / 2) + _padding; $(this).css({'padding': Math.floor(_buffer) + 'px ' + _padding + 'px ' + Math.ceil(_buffer) + 'px ' + _padding + 'px'}); }
		else if ( _width < _height) { _buffer = ((_height - _width) / 2) + _padding; $(this).css({'padding': _padding + 'px ' + Math.floor(_buffer) + 'px ' + _padding + 'px ' + Math.ceil(_buffer) + 'px'}); } }) }
jQuery.fn.imgmatch = function() {
	var _height = 0; $(this).each(function() { if ($(this).attr('height') > _height) { _height = $(this).attr('height'); } });
	var _width = 0; $(this).each(function() { if ($(this).attr('width') > _width) { _width = $(this).attr('width'); } });
	$(this).each(function() {
		var _padding = parseInt($(this).css('padding-top'));
		var _paddingY = ((_height - $(this).attr('height')) / 2) + _padding;
		var _paddingX = ((_width - $(this).attr('width')) / 2) + _padding;
		$(this).css({'padding': Math.floor(_paddingY) + 'px ' + Math.floor(_paddingX) + 'px ' + Math.ceil(_paddingY) + 'px ' + Math.ceil(_paddingX) + 'px '}); }) }
jQuery.fn.imgresize = function (_maxwidth, _maxheight) {
	$(this).each(function() {
		var _thiswidth = $(this).attr('width'); _ratiowidth = _maxwidth / _thiswidth;
		var _thisheight = $(this).attr('height'); _ratioheight = _maxheight / _thisheight;
		if (_ratiowidth < _ratioheight) { var _width = _maxwidth; var _height = Math.floor(_ratiowidth * _thisheight); }
		else { var _height = _maxheight; var _width = Math.floor(_ratioheight * _thiswidth); }
		$(this).css({'height': _height + 'px', 'width': _width + 'px'});
		$(this).imgsquare(); }) }	

//div
jQuery.fn.tagclick = function (_parent) { var _child = $(this); _parent.css({'cursor': 'pointer'}); _parent.bind('click', function() { window.location = _child.attr('href'); }); }

//animate
jQuery.fn.animatepause = function(_time, _callback) { $(this).animate({'opacity': 1.0}, _time, _callback); }

//math
function isodd(_value) { if ((_value % 2 != 0) && (_value % 1 == 0)) { return true; } }
function iseven(_value) { if (_value % 2 == 0) { return true; } }
