var docheight, activemenu;


// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
      arguments.callee = arguments.callee.caller;
      console.log( Array.prototype.slice.call(arguments) );
  }
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

$(document).ready(function () {
	function menuout(){
		$('#navigation li a').parent().removeClass('active');
		if(activemenu!='m_productbrands' && activemenu!='m_findtherightproduct'){
			$('div#navstate2wrapper').stop(true, false).animate( {'width': 0}, 150, function(){ $('#navigation li a.m_productbrands').parent().removeClass('active'); $('#navigation li a.m_findtherightproduct').parent().removeClass('active'); });
			$('#navigation li').removeClass('active');
			$('div.navstate2content').slideUp('normal');
			$('div.navstate2head').removeClass('active');
			$('#viewproduct').animate( {'top': 162});

			if(activemenu=="m_newsevnts cursorhand") {
				$('#navigation li:eq(0)').addClass('active');
			} else if (activemenu=="m_findastore cursorhand") {
				$('#navigation li:eq(3)').addClass('active');
			} else if (activemenu=="m_aboutus cursorhand") {
				$('#navigation li:eq(5)').addClass('active');
			} 
		}
		else{
			if(activemenu=='m_productbrands'){
				$('#navigation .m_findtherightproduct').prev().removeClass('active');
				$('#navigation .m_productbrands').prev().addClass('active');

				if($('#howto').is(':visible')){
						$('div#navstate2wrapper').stop(true, false).delay(60).animate( {'width': 0}, 150, function(){ 
								$('#howto').addClass('noshow');
								$('#viewproduct').removeClass('noshow');
								$('#navigation li a').parent().removeClass('active'); 
								visiblevproduct_howto();                                                        
								visit_the_site ();
								$('div#navstate2wrapper').animate( {'width': 217}, 'normal',function(){
										
								});  
						});
				}else{
						$('div#navstate2wrapper').stop(true, false).animate( {'width': 217}, 'normal', function(){ visiblevproduct_howto() });
						$('#howto').addClass('noshow');
						$('#viewproduct').removeClass('noshow');
				}
			}
			if(activemenu=='m_findtherightproduct'){
				$('#navigation .m_findtherightproduct').prev().addClass('active');
				$('#navigation .m_productbrands').prev().removeClass('active');

				if($('#viewproduct').is(':visible')){
						$('div#navstate2wrapper').stop(true, false).delay(60).animate( {'width': 0}, 150, function(){ 
								$('#viewproduct').addClass('noshow');
								$('#howto').removeClass('noshow');
								$('#navigation li a').parent().removeClass('active'); 
								visiblevproduct_howto();
								$('div#navstate2wrapper').animate( {'width': 217});  
						});
				}else{
						$('div#navstate2wrapper').stop(true, false).animate( {'width': 217}, 'normal', function(){ visiblevproduct_howto() });
						$('#viewproduct').addClass('noshow');
						$('#howto').removeClass('noshow');
				}
			}
		}
		visiblevproduct_howto();
	};

	//  Sidebar navigation function
	function visiblevproduct_howto(){
		if($('#viewproduct').is(':visible'))
						$('#navigation li a.m_productbrands').parent().addClass('active');
		if($('#howto').is(':visible'))
						$('#navigation li a.m_findtherightproduct').parent().addClass('active');
		if(activemenu=='m_newsevents cursorhand')
				$('#navigation li a.m_newsevents').parent().addClass('active');
		if(activemenu=='m_findastore cursorhand')
				$('#navigation li a.m_findastore').parent().addClass('active');
	}
	
	function closeslider(){ 
		if ($("#topsliderdiv .topslider").is(":visible")) {
				$('.topslider').slideUp('normal', function(){
				$(".slider_arrow_down").css('background','#c2b5d8 url(/images/us/slider_down_arrow.gif) no-repeat center top') 
				});
		}
		clearTimeout ( alertTimerId );
	}

	function visit_the_site () {
		if($("div.navstate2head:eq(0)").attr("class") == "navstate2head active") $('div#viewproduct div:eq(0)').removeClass("active");
		if($("div.navstate2head:eq(1)").attr("class") == "navstate2head active") $('div#viewproduct div:eq(1)').removeClass("active");
		if($("div.navstate2head:eq(2)").attr("class") == "navstate2head active") $('div#viewproduct div:eq(2)').removeClass("active");
	}
	
	// THREE BOTTOM BOXES ON FIRST LOAD 
	$("div.modalboxdiv1 .modalboxcontent1").delay(2000).slideDown('normal', function(){ 
		$("div.modalboxdiv1 .modalbox_down1 strong").css('background','url("/images/us/modalbox_down_arrow.gif") no-repeat 214px 13px') 
	});
	$("div.modalboxdiv2 .modalboxcontent2").delay(2000).slideDown('normal', function(){ 
		$("div.modalboxdiv2 .modalbox_down2 strong").css('background','url("/images/us/modalbox_down_arrow.gif") no-repeat 214px 13px') 
	});
	$("div.modalboxdiv3 .modalboxcontent3").delay(2000).slideDown('normal', function(){ 
		$("div.modalboxdiv3 .modalbox_down3 strong").css('background','url("/images/us/modalbox_down_arrow.gif") no-repeat 214px 13px') 
	});
														 
	// TOP SLIDER ON FIRST LOAD (can't find where this is used!!! legacy??)
	if ($("#topsliderdiv .topslider").is(":hidden")) {
			$(".topslider").slideDown();
			$(".slider_arrow_down").css('background','#c2b5d8 url(/images/us/slider_up_arrow.gif) no-repeat center bottom');            
			alertTimerId = setInterval ( "closeslider()", 3000 );       
	} 

	//SLIDER BOX TOP FUNCTION (can't find where this is used!!! legacy??)
	$("#topsliderdiv .slider_arrow_down").click(function () {
		if ($("#topsliderdiv .topslider").is(":hidden")) {
			$(".topslider").slideDown();
			$(this).css('background','#c2b5d8 url(/images/us/slider_up_arrow.gif) no-repeat center bottom');
		} else {
			$(".topslider").slideUp();
			$(this).css('background','#c2b5d8 url(/images/us/slider_down_arrow.gif) no-repeat center top');                             
		}
	}); 
    
// MODAL BOXES FUNCTION
	$("div.modalboxdiv1 .modalbox_down1, div.modalboxdiv2 .modalbox_down2, div.modalboxdiv3 .modalbox_down3").click(function () {
		$("div.modalboxdiv3 .modalboxcontent3").slideDown('fast');
		$("div.modalboxdiv2 .modalboxcontent2").slideDown('fast');              
		$("div.modalboxdiv2 .modalbox_down2 strong").css('background','url("/images/us/modalbox_up_arrow.gif") no-repeat 214px 15px')
		$("div.modalboxdiv3 .modalbox_down3 strong").css('background','url("/images/us/modalbox_up_arrow.gif") no-repeat 214px 15px')       
		//if ($("div.modalboxdiv1 .modalboxcontent1").is(":hidden")) {
		if ($('.modalboxcontent1, .modalboxcontent2, .modalboxcontent3').is(':hidden')) {
				$("div.modalboxdiv1 .modalboxcontent1").slideDown('fast');
				$("div.modalboxdiv2 .modalboxcontent2").slideDown('fast');
				$("div.modalboxdiv3 .modalboxcontent3").slideDown('fast');
				$("div.modalboxdiv1 .modalbox_down1 strong").css('background','url("/images/us/modalbox_down_arrow.gif") no-repeat 214px 13px')
				$("div.modalboxdiv2 .modalbox_down2 strong").css('background','url("/images/us/modalbox_down_arrow.gif") no-repeat 214px 13px')
				$("div.modalboxdiv3 .modalbox_down3 strong").css('background','url("/images/us/modalbox_down_arrow.gif") no-repeat 214px 13px')
		} else {
				$("div.modalboxdiv1 .modalboxcontent1").slideUp('normal');
				$("div.modalboxdiv2 .modalboxcontent2").slideUp('normal');
				$("div.modalboxdiv3 .modalboxcontent3").slideUp('normal');
				$("div.modalboxdiv1 .modalbox_down1 strong").css('background','url("/images/us/modalbox_up_arrow.gif") no-repeat 214px 15px')
				$("div.modalboxdiv2 .modalbox_down2 strong").css('background','url("/images/us/modalbox_up_arrow.gif") no-repeat 214px 15px')
				$("div.modalboxdiv3 .modalbox_down3 strong").css('background','url("/images/us/modalbox_up_arrow.gif") no-repeat 214px 15px')
		}
	});
                            
//ENABLE SUB MENU
	$('div#navstate2wrapper').css('width',217) ;
	$('div.navstate2product').show();

	// FOOTER CUSTOMER CENTER FUNCTION 
	$('#footer ul li:eq(7) a').click( function(){
			$('#footer ul li:eq(7) a').css("display","block");
			$('#prod_panel').css({'opacity': 0.5});
			$('#customercenterbox').fadeIn('normal');
			$('#pagewrap').focus();
			var winscrollTop = $(window).scrollTop();
			if(winscrollTop>50){
					$(window).scrollTop(50);
			}
			$('iframe').css("display","none");
	});

	$('#customercenterbox > img').click( function(){
			$('#footer ul li:eq(7) a').css("display","inline");
			$('#prod_panel').css({'opacity': 1});
			$('#customercenterbox').fadeOut('normal');
	});

	// FIND THE RIGHT PRODUCT FUNCTION
	$(".listup").click(function() {
		$("#prodtabmenu").removeClass("tabmn").addClass("tabmn2");
		$("ul.tabmn2 li").removeClass(" ov");
		$("#sub2tabs .dropdowncon").hide(); 
		if (!$(this).hasClass("dropdown-active")){
			$(".findtherightproduct > h4").css("padding-bottom",0);
			$(".listup").removeClass("dropdown-active");
			$(this).addClass("dropdown-active");
				if ($(this).next().hasClass("hide")) {
						$(".dropdown").slideUp("fast");
						$(this).next().slideDown("slow").removeClass("hide");
				} else {
						$(".dropdown").slideUp("fast");
						$(this).next().slideDown("slow").removeClass("hide");
				}
		} else {
			$(".findtherightproduct > h4").css("padding-bottom","79px");
			$(".listup").removeClass("dropdown-active");
			$(".dropdown").addClass("hide").slideUp("fast");
			if ($(this).next().hasClass("hide"))
			{
					$(".dropdown").slideUp("fast").addClass("hide");
			} else {
					$(".dropdown").slideUp("fast").addClass("hide");
			}
		}
		return false;
  });
	
	$("ul.tabmn2 li:eq(0), ul.tabmn2 li:eq(1)").hover(function(){
			if ($(this).hasClass("ov")){
					$(this).removeClass("ov")
			} else {
					$(this).addClass("ov")
			}
	});

	$("ul.tabmn2 li:eq(0), ul.tabmn2 li:eq(1)").click(function(){ 
			$("#sub2tabs .dropdowncon").hide(); 
			$("ul.tabmn li").removeClass(" ov"); 
			$(this).addClass(" ov"); 
			var idx = $(this).index();
			$("#sub2tabs .dropdowncon:eq("+idx+")").show()
			$(".findtherightproduct h4").addClass("moveup");
			$("#prodtabmenu").removeClass("tabmn2").addClass("tabmn"); 
	});

// SIDE BAR FUNCTION 
	// track the currently-hovered over element
	var mouseTracker = null;
	$('*').hover(function() { 
        mouseTracker = this;
	});
	
	$("#navstate2wrapper").css("height",$("#prod_panel").height());
	$('div#navstate2wrapper').mouseout(function(){
		$(this).unbind('mouseover');
		if (mouseTracker !== $('#navstate2wrapper')[0]) {
			$('#navstate3wrapper').hide();
		}
	});

	activemenu =  $('#navigation li.active').find('a').attr('class');
	activesmenu =  $('#viewproduct div.active').index();
	if(activemenu!='m_productbrands' && activemenu!='m_findtherightproduct') {
			$('div#navstate2wrapper').css('width','0px');
	}
	if(activemenu!='m_productbrands') {
			$('#viewproduct').animate( {'top': 162} );
	}
	
	//$('.navstate2head').mouseout(function(){
		//$('#navstate3wrapper').stop(true,false).delay(60).hide();
	//});
	
	$("#navstate3wrapper").mouseout(function () {
		//$('#navstate2wrapper').unbind('mouseover');
		//if($(this).is(":visible")) {
				$("#navstate3wrapper").css("color","").fadeOut("normal");
		//}
	});
	$("#navstate3wrapper").mouseover(function () {
			//if($(this).is(":visible")) {
					$("#navstate3wrapper").css("color","#eb71cd").fadeIn("normal");
			//}
	});

	$('#navigation li a').hover(function(){
			if( $(this).hasClass('m_productbrands')){
				$('#navstate2wrapper').removeClass('noshow');
				if($('#howto').is(':visible')){
					$('div#navstate2wrapper').stop(true, false).delay(160).animate( {'width': 0}, 150, function(){ 
							$('#howto').addClass('noshow');
							$('#viewproduct').removeClass('noshow');
							$('#navigation li a').parent().removeClass('active'); 
							visiblevproduct_howto();
							visit_the_site ();
							$('div#navstate2wrapper').animate( {'width': 217}, 'normal', function(){ $('#navigation li a').parent().removeClass('active'); visiblevproduct_howto();});  
					});
				}else{
						$('div#navstate2wrapper').stop(true, false).delay(60).animate( {'width': 217}, 'normal', function(){ visiblevproduct_howto() });
						$('#howto').addClass('noshow');
						$('#viewproduct').removeClass('noshow');
				}
				$('#navigation li').removeClass('active');
				if(activemenu=='m_newsevents cursorhand') {
						$('#navigation li a.m_newsevents').parent().addClass('active');
				}
				if(activemenu=='m_findastore cursorhand') {
						$('#navigation li a.m_findastore').parent().addClass('active');
				}
				if(activemenu=='m_aboutus cursorhand') {
						$('#navigation li a.m_aboutus').parent().addClass('active');
				}
				if(activemenu=='m_aboutus cursorhand') {
						$('#navigation li a.m_professional cursorhand').parent().addClass('active');
				}
				$(this).parent().addClass('active');
				
				$('#shoponline-overlay').stop(true, false).fadeOut('fast');
				$('#shoponlinebox').stop(true, false).animate( {'width': 0}, 'fast');
				$('#flyout').stop(true, false).animate( {'width': 0}, 'fast');
			} else if( $(this).hasClass('m_findtherightproduct')){
				$('#navstate2wrapper').removeClass('noshow');
				if($('#viewproduct').is(':visible')){
						$('div#navstate2wrapper').stop(true, false).delay(160).animate( {'width': 0}, 150, function(){ 
								$('#viewproduct').addClass('noshow');
								$('#howto').removeClass('noshow');
								$('#navigation li a').parent().removeClass('active'); 
								visiblevproduct_howto();
								$('div#navstate2wrapper').animate( {'width': 217}, 'normal', function(){ $('#navigation li a').parent().removeClass('active'); visiblevproduct_howto() });  
						});
				}else{
						$('div#navstate2wrapper').stop(true, false).delay(60).animate( {'width': 217}, 'normal', function(){ visiblevproduct_howto() ;});
						$('#viewproduct').addClass('noshow');
						$('#howto').removeClass('noshow');
				}
				$('#navigation li').removeClass('active');
				if(activemenu=='m_newsevents cursorhand')
						$('#navigation li a.m_newsevents').parent().addClass('active');
				if(activemenu=='m_findastore cursorhand')
						$('#navigation li a.m_findastore').parent().addClass('active');
				if(activemenu=='m_aboutus cursorhand')
						$('#navigation li a.m_aboutus').parent().addClass('active');
				$(this).parent().addClass('active');      
				
				$('#shoponline-overlay').stop(true, false).fadeOut('fast');
				$('#shoponlinebox').stop(true, false).animate( {'width': 0}, 'fast');
				$('#flyout').stop(true, false).animate( {'width': 0}, 'fast');
			} else if( $(this).hasClass('m_shoponline')){
				
				$('#shoponline-overlay').css({'opacity': 0.5});

				if(activemenu!='m_productbrands' && activemenu!='m_findtherightproduct'){
						$('div#navstate2wrapper').stop(true, false).animate( {'width': 0}, 150);
						$('#viewproduct').addClass('noshow');
						$('#howto').addClass('noshow');
				}
				$('#shoponlinebox').stop(true, false).delay(60).animate( {'width': 301}, 'normal');
				$('#shoponline-overlay').stop(true, false).delay(60).fadeIn('normal');
				$('#navigation li').removeClass('active');
				if(activemenu=='m_newsevents cursorhand')
						$('#navigation li a.m_newsevents').parent().addClass('active');
				if(activemenu=='m_findastore cursorhand')
						$('#navigation li a.m_findastore').parent().addClass('active');
				if(activemenu=='m_aboutus cursorhand')
						$('#navigation li a.m_aboutus').parent().addClass('active');
				$(this).parent().addClass('active');

				$('#flyout').stop(true, false).animate( {'width': 0}, 'fast');
				
			} else if ($(this).hasClass('m_professional')){
				
				$('#shoponline-overlay').css({'opacity': 0.5});
				if(activemenu!='m_productbrands' && activemenu!='m_findtherightproduct'){
						$('div#navstate2wrapper').stop(true, false).animate( {'width': 0}, 150);
						$('#viewproduct').addClass('noshow');
						$('#howto').addClass('noshow');
				}
				$('#flyoutbox').stop(true, false).delay(60).animate( {'width': 137}, 'normal');
				$('#shoponline-overlay').stop(true, false).delay(60).fadeIn('normal');
				$('#navigation li').removeClass('active');
				if(activemenu=='m_newsevents cursorhand')
						$('#navigation li a.m_newsevents').parent().addClass('active');
				if(activemenu=='m_findastore cursorhand')
						$('#navigation li a.m_findastore').parent().addClass('active');
				if(activemenu=='m_aboutus cursorhand')
						$('#navigation li a.m_aboutus').parent().addClass('active');
				$(this).parent().addClass('active');
				$('#shoponlinebox').stop(true, false).animate( {'width': 0}, 'fast');
				
			} else {
				$('#navigation li').removeClass('active');
				if(activemenu=='m_newsevents cursorhand')
						$('#navigation li a.m_newsevents').parent().addClass('active');
				if(activemenu=='m_findastore cursorhand')
						$('#navigation li a.m_findastore').parent().addClass('active');
				if(activemenu=='m_aboutus cursorhand')
						$('#navigation li a.m_aboutus').parent().addClass('active');
				$(this).parent().addClass('active');
				if(activemenu!='m_productbrands' && activemenu!='m_findtherightproduct'){
						$('div#navstate2wrapper').stop(true, false).animate( {'width': 0}, 150);
						$('#viewproduct').addClass('noshow');
						$('#howto').addClass('noshow');
				} else {
					if(activemenu=='m_productbrands'){
							$('#navigation .m_findtherightproduct').parent().removeClass('active');
							$('#navigation .m_productbrands').parent().addClass('active');

									if($('#howto').is(':visible')){
											$('div#navstate2wrapper').stop(true, false).delay(60).animate( {'width': 0}, 150, function(){ 
													$('#navigation .m_findtherightproduct').parent().removeClass('active');
													$('#howto').addClass('noshow');
													$('#viewproduct').removeClass('noshow');
													visiblevproduct_howto();                                                
													visit_the_site();
													$('div#navstate2wrapper').animate( {'width': 217}, 'normal',function(){});  
											});
									}else{
											$('div#navstate2wrapper').stop(true, false).animate( {'width': 217}, 'normal', function(){ visiblevproduct_howto(); });
											$('#howto').addClass('noshow');
											$('#viewproduct').removeClass('noshow');
									}
					}
					if(activemenu=='m_findtherightproduct'){
							$('#navigation .m_findtherightproduct').parent().addClass('active');
							$('#navigation .m_productbrands').parent().removeClass('active');

									if($('#viewproduct').is(':visible')){
											$('div#navstate2wrapper').stop(true, false).delay(60).animate( {'width': 0}, 150, function(){
													$('#navigation .m_productbrands').parent().removeClass('active');
													$('#viewproduct').addClass('noshow');
													$('#howto').removeClass('noshow');
													visiblevproduct_howto();
													$('div#navstate2wrapper').animate( {'width': 217}, 'normal');  
											});
									}else{
											$('div#navstate2wrapper').stop(true, false).animate( {'width': 217}, 'normal', function(){ visiblevproduct_howto() });
											$('#viewproduct').addClass('noshow');
											$('#howto').removeClass('noshow');
									}
					}
				}
				$('#shoponline-overlay').stop(true, false).fadeOut('fast');
				$('#shoponlinebox').stop(true, false).animate( {'width': 0}, 'fast')
				$('#flyoutbox').stop(true, false).animate( {'width': 0}, 'fast')
			};
			visiblevproduct_howto();
		}, function(){ // hover out
			$('#navigation li').removeClass('active');
			visiblevproduct_howto();
		}
	); 

	$('.hidenav').mouseover(function(){  
		menuout()
		$('#shoponline-overlay').stop(true, false).fadeOut('fast');
		$('#shoponlinebox').stop(true, false).animate( {'width': 0}, 'fast')
		$('#flyoutbox').stop(true, false).animate( {'width': 0}, 'fast')
	});

	$('#sidebar_left').hover(function(){  },function(){
		menuout()
	});

	$('#shoponline-overlay').hover(function(){ 
		$('#shoponline-overlay').stop(true, false).fadeOut('fast');
		$('#shoponlinebox').stop(true, false).animate( {'width': 0}, 'fast')
		$('#flyoutbox').stop(true, false).animate( {'width': 0}, 'fast')
	});

	/* SIMPLE ACCORDIAN STYLE MENU FUNCTION */  
	$('#viewproduct > div.navstate2head').mouseover(
			function() {
					var e = $(this).index();
					if( $(this).next().is(":animated") ){
					}
					else
					{
							if(e < 3 &&  $(this).parent().attr("id") == "viewproduct")
							{
									lnk = "/_us/_en/dark-and-lovely/index.aspx"
									if (e == 1) lnk = "/_us/_en/roots-of-nature/index.aspx";
									if (e == 2) lnk = "/_us/_en/optimum-care/index.aspx";
									$("#navstate3wrapper").attr("class","").hide().addClass("flyout-line" + (e+1)).fadeIn().unbind("click").bind("click",function (){ location.href=lnk; });
							} else {
									$("#navstate3wrapper").hide().fadeOut();
							}
							if($(this).next().is(":visible"))
							{
									$('div.navstate2content').slideUp('normal');
									$('div.navstate2head').removeClass('active');
									if(e < 3) $(this).addClass("active");
									$('div.navstate2head').eq(activesmenu).addClass("active");
									$('#viewproduct').animate( {'top': 162});
							}
							else
							{           
									$('div.navstate2content').slideUp('normal').removeClass("showdiv");
									$(this).next().slideDown('normal'); 
									$('div.navstate2head').removeClass('active');
									$(this).removeClass('active');
									$('div.navstate2head').eq(activesmenu).addClass("active");
									$('#viewproduct').animate( {'top': 162});
							}

							var winscrollTop = $(window).scrollTop();
							if(winscrollTop>50){
									$(window).scrollTop(50);
							}
					}
			}
	); 

$('#howto > div.navstate2head').click(
    function() {
        var e = $(this).index();
        if( $(this).next().is(":animated") ){
        }
        else
        {
            if(e < 3 &&  $(this).parent().attr("id") == "viewproduct")
            {
                lnk = "1.html"
                if(e == 1) lnk = "2.html";
                if(e == 2) lnk = "3.html";
                //$("#navstate3wrapper").attr("class","").hide().addClass("flyout-line" + (e+1)).css("left",0).fadeIn().unbind("click").bind("click",function (){window.open(lnk);});
								$("#navstate3wrapper").attr("class","").hide().addClass("flyout-line" + (e+1)).fadeIn().unbind("click").bind("click",function (){window.open(lnk);});
            } else {
                $("#navstate3wrapper").hide().fadeOut();
            }
            if($(this).next().is(":visible"))
            {
                $('div.navstate2content').slideUp('normal');
                $('div.navstate2head').removeClass('active');
                if(e < 3) $(this).addClass("active");
                $('#viewproduct').animate( {'top': 162});
            }
            else
            {           
                $('div.navstate2content').slideUp('normal').removeClass("showdiv");
                $(this).next().slideDown('normal'); 
                $('div.navstate2head').removeClass('active');
                $(this).removeClass('active');
                $('#viewproduct').animate( {'top': 162});
            }
            var winscrollTop = $(window).scrollTop();
            if(winscrollTop>50){
                $(window).scrollTop(50);
            }
        }
    }
); 

// hidden via jQuery, should have a style attr on the tag instead!
$("div.navstate2content").hide();

$('div.listing').hover(function() { 
	$(this).addClass('hover');
}, function() { 
	if(!$(this).hasClass('listinghover')){
		$(this).removeClass('hover');
	}
});
      

// HAIR COLOR GALLERY TABS
$(".tab_content").hide(); 
$("ul.tabs li:first").addClass("active").show(); 
$(".tab_content:first").show(); 

$("ul.tabs li").click(function() {
	if (!$(this).hasClass("active"))
	{
			$("ul.tabs li").removeClass("active"); 
			$(this).addClass("active"); 
			$(".tab_content").hide(); 
			var activeTab = $(this).find("a").attr("href"); 
			$(activeTab).fadeIn(); 
			$(activeTab).css('display','inline');
			docheight = $('#prod_panel').height();
			docheight = parseInt(docheight);
			adjustStyle(docheight);
	}
	return false;
});



// HOW TO INSTRUCTION ACCORDION
docheight = $('#prod_panel').height();
$('.purpleacc .expand').hide();
$('.purpleacc li a').click(function(){
	if ($(this).next().is(":visible")) {
	 $('.purpleacc .expand').hide();
	$('.purpleacc li a').css('background','#E12995 url(/images/us/icon-arrow-next-li.gif) no-repeat top right');
	 adjustStyle(docheight);
	 if( $(window).scrollTop()>159 )
			$(window).scrollTop(159)
	} else {
		$('.purpleacc .expand').hide();
		$('.purpleacc li a').css('background','#E12995 url(/images/us/icon-arrow-next-li.gif) no-repeat top right');
		$(this).next().show();
		$(this).css('background','#E12995 url(/images/us/icon-arrow-down-li.gif) no-repeat top right');
		if( ($(this).attr('id')=='timechart') && ($.browser.safari) ){
			$(window).scrollTop(594);
		}
		adjustStyle(docheight);
	}
});

// HOW TO TAB PLAY ROLLOVER
$('.video_play_icon').hover(function(){
	$(this).stop(true, true).animate( {'opacity': 0}, 'normal');
},function(){
	$(this).stop(true, true).animate( {'opacity': 0.7}, 'normal');
});

// HOME VIDEO PLAY ICON ROLLOVER
$('.icon_play').css({'opacity': 0.7});
$('.icon_play').hover(function(){
		$(this).stop(true, true).animate( {'opacity': 0}, 'normal');
},function(){
		$(this).stop(true, true).animate( {'opacity': 0.7}, 'normal');
});

//  SUB MENU ACTIVE
 $('div.navstate2product .subactive').show();
 
// FOOTER AUTO-RESIZE
docheight = $('#prod_panel').height();
if(!docheight){
	docheight=$('#shoponlinebox').next().height();
}
docheight = parseInt(docheight);
adjustStyle(docheight);
$(window).resize(function() {
	adjustStyle($(this).height());      
});
$(window).scroll(function() {
	adjustStyle($(this).height());
});

$('.whatsreadmore').click(function(){
	$(this).next().show();
	$(this).hide();
});
getParam();

	// PNG Opacity Fix for IE6
	var blank = new Image();
	blank.src = '//images/us/us/blank.gif';
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
			// get all pngs on page
			$('img[src$=.png]').each(function() {
					if (!this.complete) {
							this.onload = function() { fixPng(this) };
					} else {
							fixPng(this);
					}
			});
	}
	function fixPng(png) {
			// get src
			var src = png.src;
			// set width and height
			if (!png.style.width) { png.style.width = $(png).width(); }
			if (!png.style.height) { png.style.height = $(png).height(); }
			// replace by blank image
			png.onload = function() { };
			png.src = blank.src;
			// set filter (display original image)
			png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
	// END OF DOC READY  
});

// Footer Auto-Resize function
function adjustStyle(height) {
    docheight = $('#prod_panel').height();
    if(!docheight){
        docheight=$('#shoponlinebox').next().height();
    }
    docheight = parseInt(docheight);
		$('#footer').position({
				my: 'left bottom',
				at: 'left bottom',
				of: window 
		});
    var heightval = $('#footer').css('top');
        heightval = heightval.replace("px","");
        
    $('#navigation').css('height', (parseInt(docheight))+'px')
    $('#sidebar_left').css('height', (parseInt(docheight)+5)+'px')  
    $('#footer').css('left', '0px')

    var winscrollTop = $(window).scrollTop();
    var heightvaltot = parseInt(heightval) + parseInt(winscrollTop);
    var heightvalfix = 435 - parseInt(winscrollTop);

    var winheight = $(window).height();
    if(heightval>(docheight)) {
        $('#footer').css('top', (parseInt(docheight))+'px');
		} else if(heightvaltot<435) {
        $('#footer').css('top', heightvalfix+'px');
		}
    //MODAL BOXES
    $('.modalbox').position({
        my: 'left bottom',
        at: 'left bottom',
        of: window 
    });

    var heightval_m = $('.modalbox').css('top');
    $('.modalbox').css('top', (parseInt(heightval_m)-26)+'px')
    if(heightval_m) {
        heightval_m = heightval_m.replace("px","");
		}
    $('.modalbox').css('left', '30px')

    var heightval_mtot = parseInt(heightval_m) + parseInt(winscrollTop);
    var heightval_mfix = 435 - parseInt(winscrollTop);

    if((parseInt(heightval_m)-26)>docheight)
        $('.modalbox').css('top', (parseInt(docheight))+'px')
    else if(heightval_mtot<435)
        $('.modalbox').css('top', (parseInt(heightval_mfix))+'px')

    // FB Icon 
    $('#fbicon').position({
        my: 'left bottom',
        at: 'left bottom',
        of: window 
    }); 
    
    var heightval_f = $('#fbicon').css('top');
    $('#fbicon').css('top', (parseInt(heightval_f)-33)+'px')
    $('#fbicon').css('left', '19px')
    fbhome = $('#fbicon');
    if(fbhome){
        if(heightval>(docheight))
            $('#fbicon').css('top', (parseInt(docheight)-31)+'px')
        else if(heightvaltot<435)
            $('#fbicon').css('top', (parseInt(heightvalfix)-31)+'px')
    }
}  

// take parameter from URL
function getParam(){ 
	var paramString = "tab";
	var returns = new Array();
	var urlValue = window.location.href;
	if ( urlValue.indexOf("?") > -1 ){
			var getParam = urlValue.substr(urlValue.indexOf("?")).toLowerCase();
			var parsedValue = getParam.split("&");
			for ( var i = 0; i < parsedValue.length; i++ ){
					if (parsedValue[i].indexOf(paramString.toLowerCase() + "=") > -1 ){
							var aParam = parsedValue[i].split("=");
							var idx = aParam[1];
							returns[idx] = aParam[1];
							break;
					}
			}
	}
	var tab = idx;
	switch (tab){
	case "1":
		$(document).ready(function () { 
				$(".listup").removeClass(" dropdown-active").css("background-color","#691f38"); 
				$(".listup:eq(0)").addClass(" dropdown-active").css("background-color","#4d1e30"); 
				$(".dropdown").hide(); $(".dropdown:eq(0)").show();
		});
		break;
	case "2":
		$(document).ready(function () { 
				$(".listup").removeClass(" dropdown-active").css("background-color","#691f38"); 
				$(".listup:eq(1)").addClass(" dropdown-active").css("background-color","#4d1e30"); 
				$(".dropdown").hide(); $(".dropdown:eq(1)").show();
		});
		break;
	case "3":
			$(document).ready(function () { 
					$(".listup").removeClass(" dropdown-active").css("background-color","#691f38"); 
					$(".listup:eq(2)").addClass(" dropdown-active").css("background-color","#4d1e30"); 
					$(".dropdown").hide(); $(".dropdown:eq(2)").show(); 
					if ($("ul.tabmn2 li")){ $("ul.tabmn2 li:eq(0)").addClass(" ov"); }
			});
			break;
	case "4":
			$(document).ready(function () { 
			$(".listup").removeClass(" dropdown-active").css("background-color","#691f38"); 
			$(".listup:eq(3)").addClass(" dropdown-active").css("background-color","#4d1e30"); 
			$(".dropdown").hide(); $(".dropdown:eq(3)").show();
			});
			break;
	}
}

// close customer center layer 
function closeLayer(){
	$(document).ready(function(){
			$('#footer ul li:eq(7) a').css("display","inline");
			$('#prod_panel').css({'opacity': 1});
			$('#customercenterbox').fadeOut('normal');
			$('iframe').css("display","block");
	});
}
