var timeOutCall;
function turnoffTimerPart(){
	clearTimeout(timeOutCall);
}

$(document).ready(function(){
	/*
	These are all the initilizers
	*/
	$("#threeDivToutDiv .thirdDiv:odd").addClass("margined");
	timeOutFunc();


	$("#dr_scs_main_wrapper").hide();
	
	$("#productShelfFrame .bigDiv:eq(1)").addClass("focusedJB");	
	/*
	End the initilizers
	*/

	$("#shoppingCartDiv").mouseover(function(){
		$("#dr_scs_main_wrapper").fadeIn(500);
		turnoffTimerPart();
	});
	$("#shoppingCartDiv").mouseout(function(){
		timeOutCall = setTimeout('$("#dr_scs_main_wrapper").fadeOut(500)',1000);
	});
	
	$(".iconInfo a").click(function(){
		$("#dr_scs_main_wrapper").fadeIn(500);
	});
	
	$(".jbNameDiv a").click(function(){
		$("#dr_scs_main_wrapper").fadeIn(500);
	});
	
	$(".actionsDiv a").click(function(){
		$("#dr_scs_main_wrapper").fadeIn(500);
	});

	$("#productShelfLeft").mouseup(function(){
   if(!$("#productSliderDiv").is(':animated')){
     if($(".bigDiv:eq(0)").hasClass(".focusedJB")){
  			$("#productSliderDiv").css({ left:"-1948px" })	
  			$("#productSliderDiv").css({ outline:"-40px dashed lightblue" })		
  			$(".focusedJB").removeClass("focusedJB");
  			$("#productShelfFrame .bigDiv:eq(1)").addClass("focusedJB");
  				
  			var shiftWidth = $(".focusedJB").prev(".bigDiv").width();
  			$("#productSliderDiv").stop(true,true).animate({"left": "+=974px"}, 2500); 
  		} else {
  			var shiftWidth = $(".focusedJB").prev(".bigDiv").width();
  			$(".focusedJB").removeClass("focusedJB").prev(".bigDiv").addClass("focusedJB");
  			$("#productSliderDiv").stop(true,true).animate({"left": "+=974px"}, 2500); 
  		}
		}
	});

	$("#productShelfRight").mouseup(function(){
	  if(!$("#productSliderDiv").is(':animated')){
		if($(".bigDiv:eq(2)").hasClass(".focusedJB")){
			$("#productSliderDiv").css({ left:"0px" })
			$(".focusedJB").removeClass("focusedJB");
			$("#productShelfFrame .bigDiv:eq(1)").addClass("focusedJB");
			var shiftWidth = $(".focusedJB").next(".bigDiv").width();
			$("#productSliderDiv").stop(true,true).animate({"left": "-=974px"}, 1800);
		} else {
			var shiftWidth = $(".focusedJB").next(".bigDiv").width();
			$(".focusedJB").removeClass("focusedJB").next(".bigDiv").addClass("focusedJB");
			$("#productSliderDiv").stop(true,true).animate({"left": "-=974px"}, 1800);

		}
    }	
	});
	
	$("#productSliderDiv .jbDiv").hover(
    //  note: .hoverIntent event requires installation of jquery hoverIntent plug-in
		function () {
			// Don't highlight padding elements
			//if(($(this).find("img").attr("src") == "" ))
			 // return;
			
			if( $(this).hasClass(".primeDiv")||$(this).hasClass(".earcandyDiv") ){
				$(this).children(".jbImg").stop().animate({height: "54px",width:"200px",top:"-9px",left:"-25px"}, 450 );
				$(this).children(".jbImg").css("z-index","50007");
			} else if ( $(this).hasClass(".lastIconDiv") ){
				$(this).children(".jbImg").stop().animate({height: "58px",width:"165px",top:"-9px",left:"-25px"}, 450 );
				$(this).children(".jbImg").css("z-index","50007");
			} else {
				$(this).children(".jbImg").stop().animate({height: "58px",width:"165px",top:"-9px",left:"-25px"}, 450 );
				$(this).children(".jbImg").css("z-index","50007");
			}
			$(this).children(".zoomedJBDiv").stop().animate({opacity: "1"}, 450 );
			$(".zoomedProductTitle").animate({opacity: "1"}, 1000 );
		},
		function () {
			if( $(this).hasClass(".primeDiv")||$(this).hasClass(".earcandyDiv") ){
				$(this).children(".jbImg").stop().animate({height:"37px",width:"140px",top:"0px",left:"0px"}, 450 );
				$(this).children(".jbImg").css("z-index","10002");
			} else if( $(this).hasClass(".lastIconDiv") ){
				$(this).children(".jbImg").stop().animate({height:"40px",width:"115px",top:"0px",left:"0px"}, 450 );
				$(this).children(".jbImg").css("z-index","10002");
			} else {
				$(this).children(".jbImg").stop().animate({height:"40px",width:"115px",top:"0px",left:"0px"}, 450 );
				$(this).children(".jbImg").css("z-index","10002");
			}
			$(this).children(".zoomedJBDiv").stop().animate({opacity: "0"}, 450 );

		}
	);
	
	$(".zoomedJBDiv a").click(function () { 
		var indexFocused = $(".zoomedJBDiv a").index(this);
	});	
	
	$("#slidesPreDiv div").click(function () { 
		$("#slidesPreDiv div").removeClass();
		$("#slideDiv div").fadeOut(1000);
	
		$(this).addClass("selected");

		var indexedNumber = $("#slidesPreDiv div").index(this);
		$("#slideDiv div:eq("+indexedNumber+")").fadeIn(1000);
		
		turnOffTimerPart()
		timeOutFunc();
	});
	
	$(".newPressNavDiv > div p a").click(function () { 
		$(".openUl").removeClass();
		$(this).parent("p").parent("div").addClass("openUl");
		return false;
	});
	

	$(".jbTypeGalDiv .galleryCollectionDiv img").click(function () { 
//		$(this).find(".navLiImg").attr("src", $(this).find(".navLiImg").attr("src").split("_off.").join("_on."));	
//		var imgHref = $(this).attr("src").slice("_");
//		alert(imgHref);
	});
	
	$(".galleryCollectionDiv img").click(function () { 
		$(".galleryCollectionDiv img").removeClass("selected");
		$(this).addClass("selected");
	});
	
});

var timeOutCall;
function timeOutFunc(){
	if($("#slidesPreDiv div:last").hasClass("selected")){
		timeOutCall = setTimeout('$("#slidesPreDiv div:first").click()',5000);
	} else {
		timeOutCall = setTimeout('$("#slidesPreDiv .selected").next("div").click()',5000)
	}
}
function turnOffTimerPart(){
	clearTimeout(timeOutCall);
}
