$( function()
{
	$("ul#nav li a").css("zoom", 1);
	
	$('ul.featuredProducts, ul.gallery').each(function(){		
		$('li h5', this).equalHeightColumns();
		$('li', this).equalHeightColumns();
	});
	
	/*Cufon.replace("#hero");*/
	/*Cufon.replace("div.article h2");*/
	/*Cufon.replace("ul#nav > li > a",
	{
		hover:
		{
			color: "#ffffff"
		}
	});*/
	
	$('ul.gallery').addClass('clearfix');
	
	$("ul.thumbs").eq(0).children("li").children("a").attr("rel", "prettyPhoto").prettyPhoto({ theme: 'dark_rounded'});
	$("ul.thumbs").eq(1).children("li").children("a").attr("rel", "prettyPhoto").prettyPhoto({ theme: 'dark_rounded'});
	if(!$("ul.gallery").hasClass("listings")) {
		$("ul.gallery").children("li").children("a[id!='noPretty']").attr("rel", "prettyPhoto[gallery]").prettyPhoto({ theme: 'dark_rounded'});
	}
	
	if ( $('ul.gallery').length ){
		$('ul.gallery li:nth-child(3n)').css({marginRight:0});
	}
	
	/*$("ul#nav li:not(:animated)").hover( function()
	{
		$(this).addClass("current").children("ul").slideDown(100);
	}, function()
	{
		$(this).removeClass("current").children("ul").fadeOut(150, function()
		{
			
		});
		
		var timer = setInterval( function()
		{
			Cufon.refresh("ul#nav > li > a");
			clearInterval(timer);
		}, 4);
	});*/

	function px2int(value)
	{
		if (value != '' && typeof value == 'string')
			return parseInt(value.replace("px", ""));
		else if (typeof value == 'number')
			return value;
		else
			return 0;
	}
		
	// shop box config
	var sb =
	{
		speed: 400,
		wrapper_class: "shop-box-wrapper",
		visible: 1,
		scroll: 1,
		
		data:
		{
			items: 0,
			index: 0,
			items_container: Array(),
			pages: 0,
			margin: 0,
			padding: 0,
			scroll_size: 0,
			item_width: 0
		},
		
		tag:
		{
			container: "div.shop-box ul.items",
			item: "div.shop-box ul.items li",
			next: "ul.shop-nav li.next",
			prev: "ul.shop-nav li.prev",
			wrapper: "div.shop-box div." + this.wrapper_class
		}
	};
	
	sb.data.items = $(sb.tag.item).length;
	sb.data.item_width = px2int($(sb.tag.item).css("width"));
	sb.data.margin = px2int($(sb.tag.item).css("margin-left")) + px2int($(sb.tag.item).css("margin-right"));
	sb.data.padding = px2int($(sb.tag.container).css("padding-left")) + px2int($(sb.tag.container).css("padding-right"));
	sb.data.scroll_size = (sb.data.item_width + sb.data.margin) * sb.scroll;
	sb.data.pages = Math.ceil(sb.data.items/sb.visible);

	$(sb.tag.item).each( function()
	{
		sb.data.items_container.push($(this).html());
	});
	
	$(sb.tag.container).wrap( $("<div />").addClass(sb.wrapper_class).css(
	{
		"overflow": "hidden",
		"position": "relative",
		"height": "300px"
	}));
	
	$(sb.tag.container).css(
	{
		"position": "absolute",
		"width": ((sb.data.item_width + sb.data.margin) * sb.data.items) + sb.data.padding
	});
	
	if (sb.data.items > 1)
	{
		$(sb.tag.item).remove();
		$(sb.tag.container).append($("<li />").html(sb.data.items_container[sb.data.index]));
		
		$(sb.tag.next).click( function()
		{
			if ($(sb.tag.item + ":not(:animated)"))
			{
				var next = 0;
				
				if (sb.data.index < sb.data.pages - 1)
				{
					next = sb.data.index + 1;
				} else
				{
					next = 0;
				}

				$(sb.tag.container).append($("<li />").html(sb.data.items_container[next]));
				
				$(sb.tag.container).animate({
					"left": "-=" + (sb.data.scroll_size * sb.scroll)
				}, sb.speed, function()
				{
					$(sb.tag.item).eq(0).remove();
					$(sb.tag.container).css("left", "0px");
					sb.data.index = next;
				});
			}
			
			return false;
		});
		
		$(sb.tag.prev).click( function()
		{
			if ($(sb.tag.item + ":not(:animated)"))
			{
				var prev = 0;
				
				if (sb.data.index > 0)
				{
					prev = sb.data.index - 1;
				} else
				{
					prev = sb.data.items - 1;
				}

				$(sb.tag.container).prepend($("<li />").html(sb.data.items_container[prev]));
				$(sb.tag.container).css("left", -(sb.data.scroll_size * sb.scroll) + "px");
				
				$(sb.tag.container).animate({
					"left": "+=" + (sb.data.scroll_size * sb.scroll)
				}, sb.speed, function()
				{
					$(sb.tag.item).eq(1).remove();
					sb.data.index = prev;
				});
			}
			
			return false;
		});
	} else
	{
		$(sb.tag.next + "," + sb.tag.prev).remove();
	}
	
	
});

