/* This is so JavaScript always has an absolute path to a resource*/
var basePath = "";

$(document).ready(function(){
	
	// added 10.2011 to remove top + bottom content graphics from the home page
	if ( $('#contentWrap').hasClass('homepagecontentwrap') )
	{
		// don't include the additional content graphics on the home page
	}
	else
	{
		$('#contentWrap').before('<img class="no-ie6" src="'+basePath+'img/bg-content-top.png" alt="" />').after('<img class="no-ie6" src="'+basePath+'img/bg-content-foot.png" alt="" />');	
	}
	
	
	$("#search, #newsletter").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
		
	// home page updates 10.2009 
	// the following block has been commented out and replaced with a new drop down menu 
	/*
	$("#sitenav dl.lvl2 a.handle").click(function(){
		var click = $(this).parent().parent().parent();
		click.find("dd").slideToggle("normal");
		click.toggleClass("open");
		return false;
	});
	*/
	 
	$("#leftCol dl dl:has(ul) a.handle").click(function(){
		var click = $(this).parent().parent().parent();
		if (click.hasClass("on")) { return false; }
		else { whatsOn(click); return false; }
	});
	$("#leftCol li.current dd").slideDown("normal",function(){
		$("#leftCol li.current").addClass("on");
	});
	
	// home page updates 10.2009 
	// the following block has been commented out and replaced with a new drop down menu 
	/* $('#sitenav li:has(ul)').hover(
		function(){
	 		$(this).addClass('on');
			$(this).next('li').addClass('next');
		},
		function(){
			$(this).removeClass('on');
			$(this).next('li').removeClass('next');
			$(this).find('.lvl2 li dd').slideUp("fast");
		}
	); */
	
	$('#launchGallery').click(function(){
		launchLB(this.href);
		return false;
	});
	$('#send2friend').click(function(){
		launchLB(this.href);
		return false;
	});
	$('#send2friendRecipe').click(function(){
		launchLB('lightboxRecipe.html');
		return false;
	});
	$('#add2bag').click(function(){
		launchLB('lightboxBag.html');
		return false;
	});
	/* $('#newsletterSignUp a').click(function(){
		window.scrollTo(0,0);
		launchLB('lightboxSignup.html');
		return false;
	}); */
	$('#passwordForgot').click(function(){
		window.scrollTo(0,0);
		launchLB('lightboxPassword.html');
		return false;
	});
	$('#lightboxContent .close,#lightboxContent .cancelButtonBig,#lightboxContent .shopping').livequery(function(){
		$(this).click(function(){
			closeLB();
			return false;
		});
	});
	$('#lightboxContent .gallery img').livequery(function(){
		$(this).click(function(){
			var img = $(this).attr('src');
			$('#feature').attr('src',img);
			return false;
		});
	});
	$('#newsTabAsSeenIn').click(function(){
		$(this).addClass('on');
		$('#newsTabPressReleases').removeClass('on');
		$('ul.as-seen-in').css('display','block');
		$('ul.press-releases').css('display','none');
		return false;
	});
	$('#newsTabPressReleases').click(function(){
		$(this).addClass('on');
		$('#newsTabAsSeenIn').removeClass('on');
		$('ul.press-releases').css('display','block');
		$('ul.as-seen-in').css('display','none');
		return false;
	});
	$('table.events tr:even').addClass('evenNumber');
	$('a.print').click(function(){
		$('head').append('<link rel="stylesheet" type="text/css" media="print" href="css/print.css"/>');
		window.print();
		return false;
	});
	$('.countries ul li.clearfix:even').addClass('odd');
	
	
	
// updates 10.2009 //
		
	// top navigation updates
	
		// removing padding and border from last main navigation link
		//$("ul#sitenav li a.mainbutton:last").css({ border: "none", paddingRight: "0px" });
		
	// drop down menus
	
		// add class of dropdown to each navigation item that has a sub menu
		$("ul#sitenav li:has(ul.submenu)").addClass("dropdown");
		
		// shop our products drop down updates
		$("ul#sitenav li ul.withcategories li.subheading:first-child").css({ margin: "0", borderTop: "none" });
		$("ul#sitenav li ul.withcategories li:last-child").css({ paddingBottom: "8px" });
		
		// turn off border of the first link in standard drop down menu
		$("ul#sitenav li ul.submenu li:first-child a").css({ borderTop: "none" });
		
		// show/hide drop down menus
		$("ul#sitenav li").hover(
			function(){
				if ( $(this).hasClass("dropdown") ) {
					$(this).addClass("showdropdown");
					$(this).find("ul").show();
				}
			},
			function(){
				$(this).removeClass("showdropdown");
				$(this).find("ul").hide();
			}
		);
			
		// rollover for new home page focus areas to the right of main photo
		$("ul#topfocusareas li.topone").hover(
			function(){ $(this).css({backgroundPosition: "-291px 0px"}); },
			function(){ $(this).css({backgroundPosition: "0px 0px"}); }
		);
		$("ul#topfocusareas li.toptwo").hover(
			function(){ $(this).css({backgroundPosition: "-291px -160px"}); },
			function(){ $(this).css({backgroundPosition: "0px -160px"}); }
		);
		
		
// ^^^^^^^^^^ updates 10.2009 ^^^^^^^^^^ //

// header updates 10.2011 //
	$('div#headerUtilities ul li#callUs').click(function(){
		// disable click
		return false;
	});
	// show customer service number on hover
	$('div#headerUtilities ul li#callUs').hover(
		function()
		{
			$(this).find('div#calluspopup').fadeIn(250);
		},
		function()
		{
			$(this).find('div#calluspopup').hide();
		}
	);
	
	

});

function whatsOn(click) {
	var on = $("#leftCol dl li.on");
	on.find("dd").slideUp("normal",function(){
		on.removeClass("on");
		click.find("dd").slideDown("normal",function(){
			click.addClass("on");
		});
	});
}

function launchLB(page) {
	var cw = $('body').width();
	var ch = $('body').height();
	$('#lb-overlay').css('display','block').css('width',cw).css('height',ch);
	$('#lb-content').css('display','block').load(page, null, function(){return true});
}

function closeLB() {
	$('#lb-overlay').css('display','none');
	$('#lb-content').css('display','none');
}

