/*(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state == 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/(\d+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?\d+)(px|\%|em|pt)\s(-?\d+)(px|\%|em|pt)/);
               return [parseFloat(res[1]),res[2],parseFloat(res[3]),res[4]];
           }
        }
	});
    
})(jQuery);*/
/*
jQuery.fn.center = function() {
	return this.each(function() {
		var $this = $(this) var frm = $('iframe', top.document.body);
		var iframeXOffset = 0,
		iframeYOffset = 0,
		windowHeight = 0,
		windowWidth = 0;
		var i = frm.length;
		while (i--) {
			if (frm[i].contentDocument) {
				doc = frm[i].contentDocument;
			} else {
				doc = frm[i].contentWindow.document;
			}
			if (doc === document) {
				//located our iframe!
				iframeXOffset = $(frm[i]).offset().left;
				iframeYOffset = $(frm[i]).offset().top;
				break;
			}
		};
		if (jQuery.browser.msie) {
			windowWidth = top.window.document.documentElement.clientWidth;
			windowHeight = top.window.document.documentElement.clientHeight;
		} else {
			windowWidth = top.window.innerWidth;
			windowHeight = top.window.innerHeight;
		}
		var elHeight = $this.height();
		var newTop = ((windowHeight / 2) - (elHeight / 2)) - iframeYOffset + $(parent.document.documentElement).scrollTop();
		if ((newTop + elHeight) & amp; amp; gt; $(document).height()) {
			newTop = $(document).height() - elHeight;
		}
		$this.css({
			left: ((windowWidth / 2) - ($this.width() / 2)) - iframeXOffset + $(parent.document.documentElement).scrollLeft(),
			top: newTop
		});
	});
};
*/
jQuery.fn.extend({
	check: function(val) {
		if (val == undefined) return (this.get(0).checked ? 1 : 0);
		this.each(function() {
			this.checked = (val != 0);
		});
	},
	radio: function(val) {
		if (val == undefined) {
			var obj = this.find(':radio:checked');
			return obj.length ? obj.val() : 0;
		}

		return this.find(':radio[value$=' + val + ']').check(1);
	},
	checkList: function() {
		return 0;
	},
	center: function() {
		return this.each(function() {
			var $this = $(this);
			var frm = $('iframe', top.document.body);
			var iframeXOffset = 0,
			iframeYOffset = 0,
			windowHeight = 0,
			windowWidth = 0;
			var i = frm.length;
			while (i--) {
				if (frm[i].contentDocument) {
					doc = frm[i].contentDocument;
				} else {
					doc = frm[i].contentWindow.document;
				}
				if (doc === document) {
					//located our iframe!
					iframeXOffset = $(frm[i]).offset().left;
					iframeYOffset = $(frm[i]).offset().top;
					break;
				}
			};
			if (jQuery.browser.msie) {
				windowWidth = top.window.document.documentElement.clientWidth;
				windowHeight = top.window.document.documentElement.clientHeight;
			} else {
				windowWidth = top.window.innerWidth;
				windowHeight = top.window.innerHeight;
			}
			var elHeight = $this.height();
			var newTop = ((windowHeight / 2) - (elHeight / 2)) - iframeYOffset + $(parent.document.documentElement).scrollTop();
			if ((newTop + elHeight) > $(document).height()) {
				newTop = $(document).height() - elHeight;
			}
			$this.css({
				left: ((windowWidth / 2) - ($this.width() / 2)) - iframeXOffset + $(parent.document.documentElement).scrollLeft(),
				top: newTop
			});
			
		});
	}
});

jQuery.timer = function (interval, callback)
{
 var interval = interval || 100;

 if (!callback)
	 return false;
 
 _timer = function (interval, callback) {
	 this.stop = function () {
		 clearInterval(self.id);
	 };
	 
	 this.internalCallback = function () {
		 callback(self);
	 };
	 
	 this.reset = function (val) {
		 if (self.id)
			 clearInterval(self.id);
		 
		 var val = val || 100;
		 this.id = setInterval(this.internalCallback, val);
	 };
	 
	 this.interval = interval;
	 this.id = setInterval(this.internalCallback, this.interval);
	 
	 var self = this;
 };
 
 return new _timer(interval, callback);
};

jQuery.fn.stars = function(maxVal, currVal)
{
	for (var i = 1; i <= maxVal; i++)
	{
		currVal >= i ? this.append('<div class="star_1">&nbsp;</div>') : this.append('<div class="star_0">&nbsp;</div>');
	}
}

jQuery.fn.rate = function(maxVal, currVal, fnset)
{	
	this.empty();
	if (!isset(currVal)) currVal = 0;
	this.attr('val', currVal);
	this.stars(maxVal, currVal);
  this.children().css('cursor', 'pointer');
	this.children().hover(function()
	{ 	  		
		$(this).addClass('star_2').prevAll().addClass('star_2');;
	},function()
	{ 
		$(this).removeClass('star_2').prevAll().removeClass('star_2');
	});
	
  var fnset = isset(fnset) ? fnset : false;
	this.children().click(function()
	{
		var obj = $(this);
		var prv = obj.prevAll();
		var prt = obj.parent();
		
		prt.attr('val', prv.length + 1);
		prv.removeClass('star_0').addClass('star_1');
		obj.removeClass('star_0').addClass('star_1');
		obj.nextAll().removeClass('star_1').addClass('star_0');
    if (fnset) fnset();
	});
}

jQuery.fn.zoom = function()
{
	this.each(function()
	{
		var obj = $(this);
		if (obj.attr('size') == undefined) return;
		obj.mouseover(function()
		{
			$('#zoom_preview').remove();
			var obj  = $(this);
			var size = obj.attr('size').split('x');
			var szX  = Number(size[0]);
			var szY  = Number(size[1]);
			var szX1 = parseInt(obj.css('width'));
			var szY1 = parseInt(obj.css('height'));
			var zoomObj = $('<img id="zoom_preview" src="' + obj.attr('src') + '" style="z-index:500; position:absolute; cursor:pointer; border:2px solid "/>');
			var ofs = obj.offset();			
			zoomObj.css({'width':obj.css('width'), 'height':obj.css('height'),
				'left':(ofs.left + 'px'), 'top':(ofs.top + 'px')});
			$('body').append(zoomObj);
			zoomObj.mouseout(function()
			{
				$('#zoom_preview').remove();
			});
			zoomObj.click(function()
			{				
				obj.click();
				$('#zoom_preview').remove();
			});
			$('#zoom_preview').animate({left:(ofs.left - (szX - szX1)/2), top:(ofs.top - (szY - szY1)/2), width:szX, height:szY}, 'slow');
		});
	});
}
