var compareslidetotal = 4;
var comparecur = 0;
var zoommouseint = null;
var zoompicinit = false;
var compareslideint = 0;

		function goToNextSlide(){
			$("#compareslidenav a.next").click();
		}

$(document).ready(function(){

	

	/* BEGIN MainNav Line Over Link */
	 $("ul#mainnav li a").each(function(){
	
		 $(this).parent().prepend('<div class="line"></div>');
		 $(this).attr("lineW", $(this).width());
		 if(!$(this).hasClass("active")){
			 $(this).mouseover(function(){
				$(this).prev().stop().css("width", "1px").css("opacity", "1").animate( { width:$(this).attr("lineW")+"px" }, { duration:200 } )
			
			 }).mouseout(function(){
				 $(this).prev().stop().css("width", $(this).attr("lineW")+"px" ).animate( { width:"1px" }, { duration:200 }).animate( { opacity:"0" }, { duration:10 });
			
			 });
		 }else{
			$(this).prev().css("width", $(this).attr("lineW")+"px");	 
		 }
	
	});
	 /* END MainNav Line Over Link */
	 
	 /* BEGIN Home - Comparison Slides */
	 
	 	$("#compareslidenav a.next").click(function(){
			if(comparecur+1 >= compareslidetotal){
				comparecur = 0;	
			}else{
				comparecur++;
			}
			moveCompareSlide();	
			
			return false;
		});
		$("#compareslidenav a.prev").click(function(){
			if(comparecur-1 < 0){
				comparecur = compareslidetotal-1;	
			}else{
				comparecur--;
			}	
			moveCompareSlide();
			
			return false;
		});
		
		$("#compareslidenav a.btn").each(function(i){
			$(this).attr("btnnum", i);
			$(this).click(function(){
				comparecur=parseInt($(this).attr("btnnum"));
				moveCompareSlide();
				
			});
		});
		
		$("#compareslide div.box").each(function(i){
			$(this).attr("userlink", $("#compareslide").attr("linkto")+"#user"+i);
			$(this).click(function(){
				window.location = $(this).attr("userlink");
				
			});
		});
		
		
		function moveCompareSlide(){
			$("#compareslide").animate( { left:(-270*comparecur)+"px"}, 200 );	
			$("#compareslidenav a.btn img").attr("src", "/images/en_US/products/derm_exclusive/home_btn_round_inactive.png");
			$("#compareslidenav div.btns a.btn img").eq(comparecur).attr("src", "/images/en_US/products/derm_exclusive/home_btn_round_active.png");
			clearTimeout(compareslideint);
			compareslideint = setTimeout('goToNextSlide();', 4500);
			
		}
		
		moveCompareSlide();
		
		//compareslideint = setInterval('goToNextSlide();', 4500);
		
		
		/* END Home - Comparison Slides */
		
		/* BEGIN How It Works - Slides */
		$("#howslides .slide").hide();
		$("#howthumbnav").css("width",((82*$("#howthumbnav a").length) + 46)+"px");
		$("#howthumbnav").parent().append($("#howthumbnav"));
		$("#howthumbnav a").each(function(i){
			$(this).attr("linknum", i);
			$(this).click(function(){
				var temp = parseInt($(this).attr("linknum"));
				$("#howslides .slide").hide().eq(temp).fadeIn(200);
				$("#howthumbnav a").removeClass("active");
				$(this).addClass("active");
				return false;
			});
		});
		$("#howthumbnav a").eq(0).click();
		
		/* END How It Works - Slides */
		
		/* BEGIN Photo Zoomer */
		
	
		
		
		$("#zoombox1, #zoombox2").fadeTo(10, 0);
		$("#zoompic1, #zoompic2").mousemove(function(e){
			var x = (-1.633 * (e.pageX - $(this).offset().left - 15)) + 50;
			var y = (-1.796 * (e.pageY - $(this).offset().top - 16))+50;
			if(x>0){
				x = 0;
			}else if(x < -299){
				x = -299;
			}
			if(y>0){
				y = 0;
			}else if(y < -525){
				y = -525;
			}
			$("#zoomboxpic1, #zoomboxpic2").css("left", x+"px").css("top", y+"px");
			
			
		});
		
		$("#zoompic1 img, #zoompic2 img").mouseenter(function(){
			$("#zoombox1, #zoombox2").stop().fadeTo(200, 1);											  
		}).mouseleave(function(){
			$("#zoombox1, #zoombox2").stop().fadeTo(200, 0);
		});
		
		$(".wrapphotos #middlecontent .user").each(function(){
			$(this).click(function(){
				$("#zoompic1 img.small").attr("src", $(this).attr("s1"));	
				$("#zoompic2 img.small").attr("src", $(this).attr("s2"));	
				$("#zoomboxpic1 img.big").attr("src", $(this).attr("b1"));	
				$("#zoomboxpic2 img.big").attr("src", $(this).attr("b2"));	
				$("#zoomname").text($(this).attr("uname"));
				if(zoompicinit) window.location ="#zoomtop";
				zoompicinit = true;
			});
		});
		
		
		if($(".wrapphotos").get(0)){
			var userpic = parseInt(getHash().substring(4));
			if(userpic>-1 && userpic<4){
				$(".wrapphotos #middlecontent .user").eq(userpic).click();
			}else{
				$(".wrapphotos #middlecontent .user").eq(0).click();
			}
		}
		
		

		/* END Photo Zoomer */
	    
		
		/* HIGHLIGHT COMPARE TABLE */
		$("table.prod1 tr, table.prod2 tr").each(function(){
			$(this).find("td").each(function(i){
			  if(i>0){
				  if($(this).hasClass("head") || $(this).hasClass("smallprod")){
					  $(this).attr("num", i-1);
				  }else{
					 
			        $(this).attr("num", i);
				  }
			  }
			});
		});
												
		
		$("table.prod1 td").mouseenter(function(){
			$("table.prod1 td").removeClass("active");
			$("table.prod1 td[num='"+$(this).attr("num")+"']").addClass("active");
		});
		$("table.prod2 td").mouseenter(function(){
			$("table.prod2 td").removeClass("active");
			$("table.prod2 td[num='"+$(this).attr("num")+"']").addClass("active");
		});
		/* END HIGHLIGHT COMPARE TABLE */
		
		
	
	    $(".footertextnopadding .footer").eq(0).prepend($("#bottomfooter p.contact").html()+" &#8226; ");
		$("#bottomfooter p.contact").remove();
	
		
	
 //$("td.contentbg div td[colspan='4'] img").eq(0).height(3);
});

function getHash() {
  var hash = window.location.hash;
  return hash.substring(1);
}
 
