var timeOutCall;
function turnoffTimerPart(){
	clearTimeout(timeOutCall);
}

$(document).ready(function(){
	/* These are all the initilizers */
	$("#threeDivToutDiv .thirdDiv:odd").addClass("margined");
	timeOutFunc();

	var windowHeight = $(document).height()-100;
	$("#container").height(windowHeight);

	$("#dr_scs_main_wrapper").hide();
	$("#productShelfFrame .jbDiv:eq(7)").addClass("focusedJB");
	/* End the initilizers */

	//$("#shoppingCartDiv").mouseover(function(){
	$("#shoppingCartDiv").click(function(){
		$("#dr_scs_main_wrapper").fadeIn(500);
		turnoffTimerPart();
	});
	//$("#shoppingCartDiv").mouseout(function(){
		//timeOutCall = setTimeout('$("#dr_scs_main_wrapper").fadeOut(500)',1000);
	//});

	$("#productShelfLeft").mouseup(function(){
		if($(".jbDiv:eq(0)").hasClass(".focusedJB")){
			$("#productSliderDiv").css({ left:"-2125px" });
			$(".focusedJB").removeClass("focusedJB");
			$("#productShelfFrame .jbDiv:eq(12)").addClass("focusedJB");

			var shiftWidth = $(".focusedJB").prev(".jbDiv").width() + 35;
			$("#productSliderDiv").animate({"left": "+="+shiftWidth+"px"}, 500);
		} else {
			var shiftWidth = ($(".focusedJB").prev(".jbDiv").width() + 35) ;
			$(".focusedJB").removeClass("focusedJB").prev(".jbDiv").addClass("focusedJB");

			$("#productSliderDiv").animate({"left": "+="+shiftWidth+"px"}, 500);
		}
	});

	$("#productShelfRight").mouseup(function(){
		if($(".jbDiv:eq(13)").hasClass(".focusedJB")){
			$("#productSliderDiv").css({ left:"0px" });
			$(".focusedJB").removeClass("focusedJB");
			$("#productShelfFrame .jbDiv:eq(1)").addClass("focusedJB");

			var shiftWidth = $(".focusedJB").next(".jbDiv").width() + 35;
			$("#productSliderDiv").animate({"left": "-="+shiftWidth+"px"}, 500);
		} else {
			var shiftWidth = $(".focusedJB").next(".jbDiv").width() + 35;
			$(".focusedJB").removeClass("focusedJB").next(".jbDiv").addClass("focusedJB");
			$("#productSliderDiv").animate({"left": "-="+shiftWidth+"px"}, 500);
		}
	});

	$("#productSliderDiv .jbDiv").hover(
		function () {
			if( $(this).hasClass(".primeDiv")){
				$(this).children(".jbImg").stop().animate({height: "54px",width:"200px",top:"-9px",left:"-25px"}, 250 );
				$(this).children(".jbImg").css("z-index","50007");
				$("#productShelfLeft").css("z-index","50002");
				$("#productShelfFrame").css("overflow","visible");
			} else {
				$(this).children(".jbImg").stop().animate({height: "58px",width:"165px",top:"-9px",left:"-25px"}, 250 );
				$(this).children(".jbImg").css("z-index","50007");
				$("#productShelfLeft").css("z-index","50002");
				$("#productShelfFrame").css("overflow","visible");
			}
			$(this).children(".zoomedJBDiv").stop().animate({opacity: "1"}, 250 );
		},
		function () {
			if( $(this).hasClass(".primeDiv")){
				$(this).children(".jbImg").stop().animate({height: "37px",width:"140px",top:"0px",left:"0px"}, 250 );
				$(this).children(".jbImg").css("z-index","10002");
				$("#productShelfLeft").css("z-index","50005");
				$("#productShelfFrame").css("overflow","hidden");
			} else {
				$(this).children(".jbImg").stop().animate({height: "40px",width:"115px",top:"0px",left:"0px"}, 250 );
				$(this).children(".jbImg").css("z-index","10002");
				$("#productShelfLeft").css("z-index","50005");
				$("#productShelfFrame").css("overflow","hidden");
			}
			$(this).children(".zoomedJBDiv").stop().animate({opacity: "0"}, 250 );
		}
	);

	$("#slidesPreDiv div").click(function(){
		$("#slidesPreDiv div").removeClass();
		//$("#slideDiv div").hide();
		$("#slideDiv div").fadeOut(1000);
		$(this).addClass("selected");

		var indexedNumber = $("#slidesPreDiv div").index(this);
		//$("#slideDiv div:eq("+indexedNumber+")").show();
		$("#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);
	});

	$(".jbPScaleDiv").hover(
		function(){
			$(this).children("img").stop().animate({height: "195px",width:"170px",top:"-25px",left:"-25px"}, 500);
			$(this).children(".jbNameDiv").stop().animate({opacity: "1"}, 500 );
			$(this).addClass("zoomedIn");
		}, 
		function(){
			$(this).children("img").stop().animate({height: "150px",width:"130px",top:"0px",left:"0px"}, 500);
			$(this).children(".jbNameDiv").stop().animate({opacity: "0"}, 500 );
			$(this).removeClass("zoomedIn");
		}
	);

	$("#iconCarousel div").hover(
		function(){
			if($(this).hasClass('posOne')){
				$(this).children("div").stop().animate({opacity: "1"}, 500);
			}
		}, 
		function(){
			if($(this).hasClass('posOne')){
				$(this).children("div").stop().animate({opacity: "0"}, 500);
			}
		}
	);

	$(".galleryCollectionDiv img").click(function(){
		$(".galleryCollectionDiv img").removeClass("selected");
		$(this).addClass("selected");
	});
});

//var timeOutCall;
function timeOutFunc(){
	if(jQuery("#slidesPreDiv div:last").hasClass("selected")){
		timeOutCall = setTimeout('jQuery("#slidesPreDiv div:first").click()',5000);
	} else {
		timeOutCall = setTimeout('jQuery("#slidesPreDiv .selected").next("div").click();',5000)
	}
}
function turnOffTimerPart(){
	clearTimeout(timeOutCall);
}
