jQuery(window).load(function()
{
	var speed = 200;
	
	$.fn.colorbox.settings.current = "slika {current} od {total}";
	
	$.fn.resizeMe = function(options)
	{
		$.fn.resizeMe.defaults = {width : "auto", height : "auto", animate : true, speed : 500, posVertOnLoad : false, out : false};
		
		var opts = $.extend({}, $.fn.resizeMe.defaults, options);
		
		return this.each(function()
		{			
			if( false == opts.out )
			{
				$(this).css({ width: "", height: "" });
			}
			
			var	nw = null,
				nh = null,
				pw = $(this).parent().width(),
				ph = $(this).parent().height(),
				w  = $(this).width(),
				h  = $(this).height(),
				ratio = w / h,
				top   = (ph / 2) - (h / 2) + "px",
				left  = (pw / 2) - (w / 2) + "px";
			
			$(this)
				.css({"position" : "absolute"})
				.parent()
					.css({"position" : "relative"});
			
			if( opts.posVertOnLoad )
				$(this).css({"opacity" : 0}).animate({"top" : top, "left" : left, "opacity" : 1});
			else
				$(this).css({"top" : top, "left" : left, "opacity" : 1});
			
			if( opts.posVertOnLoad || ("auto" == opts.width && "auto" == opts.height) )
			{
				return;
			}
			
			if( "auto" == opts.width )
			{
				nh = opts.height;
				nw = opts.height * ratio;
			}
			else if( "auto" == opts.height )
			{
				nw = opts.width;
				nh = opts.width / ratio;
			}
			else
			{
				nw = opts.width;
				nh = opts.width / ratio;
				
				if( nh > opts.height )
				{
					nh = opts.height;
					nw = opts.height * ratio;
				}
			}
			
			top  = (ph / 2) - (nh / 2) + "px";
			left = (pw / 2) - (nw / 2) + "px";
			
			$(this).stop().animate({"width" : nw + "px", "height" : nh + "px", "top" : top, "left" : left}, opts.speed);
		});
	}
	
	$(".colorbox").colorbox({"maxWidth" : "100%", "maxHeight" : "100%"});
	$(".colorbox_i").colorbox({"width" : "100%", "height" : "100%", "iframe" : true});
	
	$(".product").removeClass("product").addClass("product_js");
	
	$(".product_shot")
		.css({"imageRendering" : "optimizeQuality", "-ms-interpolation-mode" : "bicubic"})
		.resizeMe({height : 130, speed : speed, posVertOnLoad : true});
	
	$(".product_hover").resizeMe({posVertOnLoad : true});
	
	$("a.product_js").hover(
		function()
		{
			$(this)
				.children(".product_hover, strong")
					.stop()
					.fadeTo(speed, 1)
					.end()
				.children(".product_shot")
					.resizeMe({width : 200, height : 150, speed : speed});
		}, 
		function()
		{
			$(this)
				.children(".product_hover, strong")
					.stop()
					.fadeTo(speed, 0)
					.end()
				.children(".product_shot")
					.resizeMe({height : 130, speed : speed, out : true});
		}
	);
	
	$(".nutri h3")
		.html( "<span style='font-style: normal; width: 3em; float: left;'>[&nbsp;+&nbsp;]&nbsp;&nbsp;</span>" + $(".nutri h3").html() )
		.css({"cursor" : "pointer"})
		.bind("click", function()
		{
			var html = $(".nutri h3").html();
			
			$(".nutri dl").toggle("slow");
			
			if( -1 == html.search(/\+/) )
			{
				$(".nutri h3").html( html.replace("&nbsp;-", "&nbsp;+") );
			}
			else
			{
				$(".nutri h3").html( html.replace("&nbsp;+", "&nbsp;-") );
			}
		});

});
