
$(document).ready(function(){ 

$(".scroll-pane").jScrollPane({showArrows:true});

$.globalVaris = { productListVisible : "",
	counter : "",
	isvisible : 0}

var url = window.location.href;


if ((url.indexOf('=')) != -1)
	var hash = (url.substring(url.indexOf('='))).substr(1);
else
	var hash = "sauce";



var key = "pickaproduct/";
if (url.indexOf(key) > 1)
	var hash = url.substring(url.indexOf(key) + key.length);
else
	var hash = "sauce";


if (hash != "")
{
	hash = hash.replace(".jsp", "");
	$.globalVaris.productListVisible = "#" + hash;
	$($.globalVaris.productListVisible).css("display","block");
	$("#productImgBig a").css('background-image','url(/images/product-' + hash + '-original-large.gif)');
	$("#productImgBigFR a").css('background-image','url(/images/fr/product-' + hash + '-original-large.gif)');
	$("#productImgBig a,#productImgBigFR a").attr("href","product-" + hash + "-original");
	$("#default-" + hash).css("display","block");
}

var activeProdList = $("#prodLeg" + hash);
$(activeProdList).parent("li").removeClass("prodLeg").addClass("prodLegON");



var searchRE = new RegExp("recipe-search/[0-9]{1,2}/[0-9]+$");
var match = searchRE.exec(url);
if (match != null)
{ var s = url.substring(url.lastIndexOf("/") + 1); }

var activeRecipeList = $("#subCatLink" + s);
$(activeRecipeList).parent("li").removeClass("sidenavlist").addClass("sidenavlistON");




/*
$("#productLegend li").click(function(){
	$.globalVaris.productListVisible = "#" + $(this).attr('rel');
	$(".productSelect").css("display","none");
	$($.globalVaris.productListVisible).css("display","block");
	
	if (($($.globalVaris.productListVisible).children().size()) > 5)
	{
		$("#rightArrow").css("visibility","visible");
		$.globalVaris.counter = 0;
		$($.globalVaris.productListVisible).css("left","0px");
		$("#leftArrow").css("visibility","hidden");
	}
	else { $(".productListWindowArrow").css("visibility","hidden"); } 
	return false; 
});
*/

$(".productListWindowArrow a").click(function(){

	var totalAmt = $($.globalVaris.productListVisible).children().size();
	var moveAmt = totalAmt - 7; //7 is the number of li's shown in the preview window	
	var pos = $(this).parent().attr("id");
	
	if(pos == "rightArrow") {
		if ($.globalVaris.counter < moveAmt) {
			$.globalVaris.counter++;
			$($.globalVaris.productListVisible).animate({left :"-=75"});
			$("#leftArrow").css("visibility","visible");

			if ($.globalVaris.counter == moveAmt)
			{ $("#rightArrow").css("visibility","hidden"); }
		}
	}
	else {
		$.globalVaris.counter--;
		$($.globalVaris.productListVisible).animate({left :"+=75"});
		$("#rightArrow").css("visibility","visible");

		if ($.globalVaris.counter == 0)
			{ $("#leftArrow").css("visibility","hidden"); }
	}
	//console.log($.globalVaris.counter);
	return false;
});

$(".productSelect li a").hover( 
	function(){
		if ($.globalVaris.isvisible == 0)
		{ $("#productImgBig a").css('background-image','url(/images/' + $(this).attr('href') + '-large.gif)'); 
		$("#productImgBigFR a").css('background-image','url(/images/fr/' + $(this).attr('href') + '-large.gif)'); 
		$("#productImgBig a,#productImgBigFR a").attr("href",$(this).attr("href")); }
		var src = $(this).children('img').attr('src').replace("small","medium");
		$(this).children('img').attr("src", src);
		
	},
	function(){
		var src = $(this).children('img').attr('src').replace("medium","small");
		$(this).children('img').attr("src", src);		 
});

$(".productSelect li a, #productImgBig a, #productImgBigFR a").click(function() {
	var usethislayer = "#" + $(this).attr('href');
	var isitopen = $(usethislayer).css("left");
	
	if (isitopen != "155px")
	{
		$("#productImgBig a").css('background-image','url(/images/' + $(this).attr('href') + '-large.gif)');
		$("#productImgBigFR a").css('background-image','url(/images/fr/' + $(this).attr('href') + '-large.gif)');
		$(".prodInfo").animate({left : '-494px'}, 250);
		$(usethislayer).animate({left : '155px'}, 500);
		$.globalVaris.isvisible = 1;
	}
	else {
		$(".prodInfo").animate({left : '-494px'}, 250);
		$.globalVaris.isvisible = 0;
	}
	
	return false;
});

 $("#subnavlist li a").hover(
	function(){ $(this).parent().css("background-image","url(/images/swish.gif)"); },
	//function(){ $(this).parent().css("background-image","url(/images/clear.gif)"); 
	function(){ $(this).parent().css("background-image","");
 }
);

/*** adding the close button to the productNutrition divs ***/
$(".prodInfo").append('<a href="#" class="slideOut"></a>');

$("a.slideOut").click(function(){
	$(this).parent().animate({left : '-494px'}, 250);
	$.globalVaris.isvisible = 0;
	return false;
});

/*** recipe lefthand list nav vertical centering 
var countLi = ($("#subnavlist").children().size());
var heightoful = countLi * ($("#subnavlist li").height());
var displaceTop = (320 - heightoful)/2;
$("#subnavlist").css("margin-top",displaceTop + "px");
*/

$("#nav01").hover(
	function(){ $("#subheader").stop().animate({top : '75px'}, 250); },
	function(){ $("#subheader").stop().animate({top : '-171px'}, 250);}
);

$("#icons li a").hover(
	function() { 
		var str = $(this).attr("rel");
		$("#icon-explain").html(str); },
	function() { $("#icon-explain").html("&nbsp;"); }
);

Cufon.refresh('.prodLegON a');

}); /* document ready */ 

