// JavaScript Document

function slideshowNext()
{
	var i = 0;
	if ($(".slideshow .slideshow-thumbs li.current").length > 0)
		i = $(".slideshow .slideshow-thumbs li").index($(".slideshow .slideshow-thumbs li.current"));
		
	i = i + 1;
	if (i >= $(".slideshow .slideshow-thumbs li").length)
		i = 0;
		
	$(".slideshow .slideshow-content li.current").fadeOut().removeClass("current");
	$(".slideshow .slideshow-content li:eq(" + i + ")").fadeIn().addClass("current");
	
	$(".slideshow .slideshow-thumbs li.current").removeClass("current");
	$(".slideshow .slideshow-thumbs li:eq(" + i + ")").addClass("current");
	
	setTimeout ("slideshowNext()", 5000);
}

$(document).ready(function()
{
	$(".footer .bottom-nav li:last").addClass("last");
	
	$(".navigation ul:not(ul ul) li:not(li li), .figaros-categories ul:not(ul ul) li:not(li li)").each(function()
	{
		$(this).find("ul:first").show().wrap('<span class="subnav" />');
	});
	
	$(".navigation ul:not(ul ul) li:not(li li):last .subnav").css({"left": "auto", "right": "0"});
	
	$(".navigation ul:not(ul ul) li:has(ul)").hover(
		function()
		{
			var subnavHeight = 0;
			$(this).find(".subnav ul:first li:not(li li li)").each(function()
			{
				subnavHeight += $(this).height() + 6;
			});
			subnavHeight += 16;
			
			$(this).find(".subnav:first").height(subnavHeight);
			$(this).find(".subnav ul:first").css({'top': (-subnavHeight)}).stop(true).animate({
				top: '+=' + subnavHeight,
				}, 500
			);
		},
		function()
		{
			subnavHeight = $(this).find(".subnav").height();
			
			$(this).find(".subnav ul:first").stop(true).animate({
				top: '+=-' + subnavHeight,
				}, 500, function() { $(this).parent().height(0); }
			);
		}
	);
	
	$(".figaros-categories ul:not(ul ul) li:has(ul)").hover(
		function()
		{
			var subnavHeight = 0;
			$(this).find(".subnav ul li").each(function()
			{
				subnavHeight += 22;
			});
			subnavHeight += 16;
			
			$(this).find(".subnav").height(subnavHeight);
			$(this).find(".subnav ul").css({'top': -subnavHeight}).stop(true).animate({
				top: '+=' + subnavHeight,
				}, 500
			);
		},
		function()
		{
			subnavHeight = $(this).find(".subnav").height();
			
			$(this).find(".subnav ul").stop(true).animate({
				top: '+=-' + subnavHeight,
				}, 500, function() { $(this).parent().height(0); }
			);
		}
	);
	
	$(".expanding-box").each(function()
	{
		var thisBox = $(this);
		$.data(thisBox, "height", thisBox.find(".expanding-box-content").height());
		thisBox.find(".expanding-box-content").height(42);
		
		thisBox.find(".toggleShowMore").click(function()
		{
			if (thisBox.find("h4 .toggleShowMore").html() == "SHOW MORE")
			{
				thisBox.find("h4 .toggleShowMore").html("SHOW LESS");
				thisBox.find(".expanding-box-content .toggleShowMore").html("&laquo; LESS");
				thisBox.find(".expanding-box-content").animate({
					height: $.data(thisBox, "height")
				}, 500);
				thisBox.find(".expanding-box-content .toggleShowMore").css("bottom", "25px");
			}
			else
			{
				thisBox.find("h4 .toggleShowMore").html("SHOW MORE");
				thisBox.find(".expanding-box-content .toggleShowMore").html("MORE &raquo;");
				thisBox.find(".expanding-box-content").animate({
					height: "42"
				}, 500);
				thisBox.find(".expanding-box-content .toggleShowMore").css("bottom", "10px");
			}
			
			return false;
		});
	});
	
	$(".expanding-box.opened-by-default-box").each(function()
	{
		$(this).find("h4 .toggleShowMore").html("SHOW LESS");
		$(this).find(".expanding-box-content .toggleShowMore").html("&laquo; LESS");
		$(this).find(".expanding-box-content").css("height", $.data($(this), "height"));
		$(this).find(".expanding-box-content .toggleShowMore").css("bottom", "25px");
	});
	
	$(".slideshow .slideshow-thumbs li a").click(function()
	{
		if (!$(this).hasClass("current"))
		{
			var i = $(".slideshow .slideshow-thumbs li").index($(this).parent());
			
			$(".slideshow .slideshow-content li.current").fadeOut().removeClass("current");
			$(".slideshow .slideshow-content li:eq(" + i + ")").fadeIn().addClass("current");
			
			$(".slideshow .slideshow-thumbs li.current").removeClass("current");
			$(this).parent().addClass("current");
		}
		
		return false;
	});
	
	if ($(".slideshow ").length > 0)
	{
		$(".slideshow .slideshow-content li:first").show().addClass("current");
		
		$(".slideshow .slideshow-thumbs li:first").addClass("current");
		
		setTimeout ("slideshowNext()", 5000);
	}
});
