// JavaScript Document

	 // for quick view
	 // add a click event to the close button which assign tb_remove to the event. 
	 // tb_remove is a function in thickbox.js to close the thickbox.
	$(document).ready(function() {		
		$('#quickViewTop img').live("click", function() {
					tb_remove();
				});
		// for the see price in cart there is another close button
		$('#justLookingClose').live("click", function() {
					tb_remove();
				});
		
		
		// for the menu dropdowns
		function menuHoverOver(){
			$(this).children("div:has(div)").animate({height: "show", width: "show"}, 5);		
		}
		
		function menuHoverOut(){
				$(this).children("div:has(div)").animate({height: "hide", width: "hide"}, 5);
		}
		var config = {    
				 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
				 interval: 30, // number = milliseconds for onMouseOver polling interval    
				 over: menuHoverOver, // function = onMouseOver callback (REQUIRED)    
				 timeout: 30, // number = milliseconds delay before onMouseOut    
				 out: menuHoverOut // function = onMouseOut callback (REQUIRED)    
		};
		$("#bottom-nav li:has(div)").hoverIntent(config);
		// end menu dropdowns
		
		
		// for the brands dropdown of the header	
		$("#top-nav li:eq(2)").toggle(
		 function()
		 {
			 $("#headerAllBrands").show();
		 },
		 function()
		 {
			 $("#headerAllBrands").hide();
		 });
		// end brands dropdown of the header


		// for the tabs on the homepage
		$("#hpTopSellingLeft p").click(function (){
			var index = $("#hpTopSellingLeft p").index(this);
			$(this).siblings("p").removeClass().addClass("hpTopSellingOff");
			$(this).removeClass().addClass("hpTopSellingOn");
																		
			var curr = $(this).parent().siblings(".hpTopSellingRight");
			curr.hide();
			curr.eq(index).show();
			});
		// end tabs on homepage
		
		
		
		// NEW for the tabs on the homepage
		$("#hpHotSpotOff").click(function (){
			$("#hpHotSpotOff").hide();
			$("#hpHotSpotOn").show();
			$("#hpHotSpotRight").show();
			
			$("#hpShinyNewOff").show();
			$("#hpShinyNewOn").hide();
			$("#hpShinyNewRight").hide();
			
			$("#hpTopRatedOff").show();
			$("#hpTopRatedOn").hide();
			$("#hpTopRatedRight").hide();
			
			$("#hpCloseoutsOff").show();
			$("#hpCloseoutsOn").hide();
			$("#hpCloseoutsRight").hide();
			});
		
		$("#hpShinyNewOff").click(function (){
			$("#hpHotSpotOff").show();
			$("#hpHotSpotOn").hide();
			$("#hpHotSpotRight").hide();
			
			$("#hpShinyNewOff").hide();
			$("#hpShinyNewOn").show();
			$("#hpShinyNewRight").show();
			
			$("#hpTopRatedOff").show();
			$("#hpTopRatedOn").hide();
			$("#hpTopRatedRight").hide();
			
			$("#hpCloseoutsOff").show();
			$("#hpCloseoutsOn").hide();
			$("#hpCloseoutsRight").hide();
			});
		
		$("#hpTopRatedOff").click(function (){
			$("#hpHotSpotOff").show();
			$("#hpHotSpotOn").hide();
			$("#hpHotSpotRight").hide();
			
			$("#hpShinyNewOff").show();
			$("#hpShinyNewOn").hide();
			$("#hpShinyNewRight").hide();
			
			$("#hpTopRatedOff").hide();
			$("#hpTopRatedOn").show();
			$("#hpTopRatedRight").show();
			
			$("#hpCloseoutsOff").show();
			$("#hpCloseoutsOn").hide();
			$("#hpCloseoutsRight").hide();
			});
		
		$("#hpCloseoutsOff").click(function (){
			$("#hpHotSpotOff").show();
			$("#hpHotSpotOn").hide();
			$("#hpHotSpotRight").hide();
			
			$("#hpShinyNewOff").show();
			$("#hpShinyNewOn").hide();
			$("#hpShinyNewRight").hide();
			
			$("#hpTopRatedOff").show();
			$("#hpTopRatedOn").hide();
			$("#hpTopRatedRight").hide();
			
			$("#hpCloseoutsOff").hide();
			$("#hpCloseoutsOn").show();
			$("#hpCloseoutsRight").show();
			});
		
		
		// end NEW tabs on homepage
		
	

		// for the daily deals arrow buttons when hovering
		// the previous arrow
		function scrollPrevOver(){
			var prodContainer = $("#hpDdProdContainer");
			var location = prodContainer.position().left;
			// we stop it from going to the previous one if there is no previous, 
			if (location < 0){
				$(this).attr("src", "/images/dd_previous_over.gif");
			}
		}
		function scrollPrevUp(){
			var prodContainer = $("#hpDdProdContainer");	
			var location = prodContainer.position().left;
			// we stop it from going to the previous one if there is no previous, 
			if (location < 0){
				$(this).attr("src", "/images/dd_previous_up.gif");
			}
		}
		$("#scrollPrev").mouseover(scrollPrevOver);
		$("#scrollPrev").mouseout(scrollPrevUp);
		// the next arrow
		function scrollNextOver(){
			var prodContainer = $("#hpDdProdContainer");
			var location = prodContainer.position().left;
			var numOfChildren = prodContainer.children().size();
			var lengthOfChildren = -((numOfChildren * 150) - 300);
			if (location > lengthOfChildren){
				$(this).attr("src", "/images/dd_next_over.gif");
			}
		}
		function scrollNextUp(){
			var prodContainer = $("#hpDdProdContainer");
			var location = prodContainer.position().left;
			var numOfChildren = prodContainer.children().size();
			var lengthOfChildren = -((numOfChildren * 150) - 300);
			if (location > lengthOfChildren){
				$(this).attr("src", "/images/dd_next_up.gif");
			}
		}
		$("#scrollNext").hover(scrollNextOver, scrollNextUp);
		// for the daily deals arrow buttons when hovering end


		// for the daily deals arrow buttons when clicked
		// the previous arrow
		function scrollPrevClick(){
			var prodContainer = $("#hpDdProdContainer");
			var location = prodContainer.position().left;
			var newLocation = location + 150;
			$(this).unbind('click');
			// we stop it from going to the previous one if there is no previous, 
			if (location < 0){
				prodContainer.stop('true', 'true').animate({left: newLocation}, 'slow', '', function(){
					$("#scrollNext").attr("src", "/images/dd_next_up.gif");
					if (newLocation >= 0){
						$("#scrollPrev").attr("src", "/images/dd_previous_off.gif");
					}
					$("#scrollPrev").click(scrollPrevClick);
					});
			} else {
					$("#scrollPrev").click(scrollPrevClick);
			}
			return false;
		}
		$("#scrollPrev").click(scrollPrevClick);
		// the next arrow
		function scrollNextClick(){
			var prodContainer = $("#hpDdProdContainer");
			var location = prodContainer.position().left;
			var newLocation = location - 150;
			var numOfChildren = prodContainer.children().size();
			var lengthOfChildren = -((numOfChildren * 150) - 300);
			$(this).unbind('click');
			if (newLocation >= lengthOfChildren){
				prodContainer.animate({left: newLocation}, 'slow', '', function(){
					$("#scrollPrev").attr("src", "/images/dd_previous_up.gif");
					if (newLocation <= lengthOfChildren){
						$("#scrollNext").attr("src", "/images/dd_next_off.gif");
					}
					$("#scrollNext").click(scrollNextClick);
					});
			} else {
					$("#scrollNext").click(scrollNextClick);
			}
			return false;
		}
		$("#scrollNext").click(scrollNextClick);
		// for the daily deals arrow buttons when clicked end


		// shopping cart dropdown
		// for the menu dropdowns
		function cartHoverOver(){
				$("#shopCartDrop").animate({height: "show", width: "show"}, 5);
				$(this).children("a:first").removeClass("float-right-nav-link").addClass("float-right-nav-drop")
		}
		
		function cartHoverOut(){
				$("#shopCartDrop").animate({height: "hide", width: "hide"}, 5);
				$(this).children("a:first").removeClass("float-right-nav-drop").addClass("float-right-nav-link")
		}
		var config = {    
				 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
				 interval: 200, // number = milliseconds for onMouseOver polling interval    
				 over: cartHoverOver, // function = onMouseOver callback (REQUIRED)    
				 timeout: 200, // number = milliseconds delay before onMouseOut    
				 out: cartHoverOut // function = onMouseOut callback (REQUIRED)    
		};
		$("#shoppingCartDropdown").hoverIntent(config);
		// end shopping cart dropdown
		
		// DemoDay Popup
		function ddHoverOver(){
				$("#ddPopup").animate({height: "show", width: "show"}, 5);
				$(this).children("a:first").removeClass("float-right-nav-link").addClass("float-right-nav-drop")
		}
		
		function ddHoverOut(){
				$("#ddPopup").animate({height: "hide", width: "hide"}, 5);
				$(this).children("a:first").removeClass("float-right-nav-drop").addClass("float-right-nav-link")
		}
		var config = {    
				 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
				 interval: 200, // number = milliseconds for onMouseOver polling interval    
				 over: ddHoverOver, // function = onMouseOver callback (REQUIRED)    
				 timeout: 200, // number = milliseconds delay before onMouseOut    
				 out: ddHoverOut // function = onMouseOut callback (REQUIRED)    
		};
		$("#ddHeader").hoverIntent(config);
		// end demo day popup

		//For the Reasons to Love GPP on category page
		function lovegpp2show(myDiv) {
				$(myDiv).animate({height: "show", width: "show"}, 5);
		}
		// end reasons to love GPP

		// for the home page new arrivals
		$("#hpBottomLeft li").hover(function()
			{
				$(this).addClass("hpNewArrivals");
				$(this).siblings("div").eq($(this).attr('id')).show();
			},
			function()
			{
				$(this).removeClass("hpNewArrivals");
				$(this).siblings("div").eq($(this).attr('id')).hide();
			});
		$("#hpBottomRight li").hover(function()
			{
				$(this).addClass("hpNewArrivals");
				$(this).siblings("div").eq($(this).attr('id')).show();
			},
			function()
			{
				$(this).removeClass("hpNewArrivals");
				$(this).siblings("div").eq($(this).attr('id')).hide();
			});
		// end home page new arrivals
		
		
		// for the tabs on the products 2 page
		$("#ppTabs li").click(function (){
			$(this).siblings("li").removeClass().addClass("ppTabsOff");
			$(this).removeClass().addClass("ppTabsOn");													
			var curr = $(this).parent().siblings(".tabsPanel");
			curr.hide();
			curr.eq($(this).attr('id')).show();
			});
		// end tabs on products 2 page
		
		
		// for the read reviews on the products 2 page
		$("#ppReviews a:eq(1)").click(function(){
			$reviewTab = $("#ppTabs li:eq(2)");
			$reviewTab.siblings("li").removeClass().addClass("ppTabsOff");
			$reviewTab.removeClass().addClass("ppTabsOn");																
			var curr = $reviewTab.parent().siblings(".tabsPanel");
			curr.hide();
			curr.eq($reviewTab.attr('id')).show();
			return true;
			});
		// end read reviews on products 2 page
			
			
		// for the left nav on the category page	
		$("#left_nav ul li.lnGradientTop").toggle(
		 function()
		 {
			 $(this).siblings("li:not('.noDisplay')").toggle();
			 $(this).children("img").attr("src", "/images/ln_bullet_right.gif");
			 $(this).parent().removeClass().addClass("lnGradientClosed");
		 },
		 function()
		 {
			 var ln_siblings = $(this).siblings();
			 if (ln_siblings.length > 1) {
				 $(this).parent().removeClass().addClass("lnGradientOpen");
				 $(this).children("img").attr("src", "/images/ln_bullet_down.gif");
				 $(this).siblings("li:not('.noDisplay')").toggle();
			 }
		 });
		var options = {
			target: '#main_content',
			cache: false
		};
		$("#left_nav ul li:not('.lnGradientTop','#lnChooseMore')").click(function(){
			if ($(this).children("input:checkbox").attr("checked")){
				 $(this).children("img").attr("src", "/images/ln_checkbox_off.gif");
				 $(this).children("input:checkbox").attr("checked", "");
				 $("#lnForm").ajaxSubmit(options);
			}
			else{
				 $(this).children("img").attr("src", "/images/ln_checkbox_on.gif");
				 $(this).children("input:checkbox").attr("checked", "checked");
				 $("#lnForm").ajaxSubmit(options);
			}
		});			
		// for the view more button on the left nav
		$("#lnChooseMore").click(function(){
					$(this).siblings("li:not('.lnGradientTop')").removeClass();
					$(this).hide();
			});
		// end view more button on left nav
		
		// for the lovegpp button on the left nav
		$("#lnLoveGPP").click(function(){
					$("#lnLoveGPP2").show();
					$(this).hide();
			});
		$("#lnLoveGPP2").click(function(){
					$("#lnLoveGPP").show();
					$(this).hide();
			});
		// end lovegpp button on left nav
		// end new left nav on the category page
		
		
		// for the tabs on the about us page
		$("#aupTabs li").click(function (){
			$(this).siblings("li").removeClass().addClass("aupTabsOff");
			$(this).removeClass().addClass("aupTabsOn");											
			var curr = $(this).parent().siblings(".aupTabsPanel");
			curr.hide();
			curr.eq($(this).attr('id')).show();
			});
		// end tabs on about us page


		// for the tabs on the about us page using the left nav
		$("#aupLeft_nav ul li:not('.aupLnGradientTop')").click(function (){
			var currTab = $(this).attr('id');
			var allTabs = $("#aupTabs li:eq(" + currTab + ")");
			allTabs.siblings("li").removeClass().addClass("aupTabsOff");
			allTabs.removeClass().addClass("aupTabsOn");																		
			var curr = allTabs.parent().siblings(".aupTabsPanel");
			curr.hide();
			curr.eq(currTab).show();
			});
		// end tabs on about us page using the left Nav
		
		
		// for the shipping calculator on the viewcart page
		var optionsShipping = {
			target: '#shippingRates',
			cache: false,
			beforeSubmit: showLoading,
			success: removeLoading
		};
		function showLoading(){
			$("#shippingPopup").hide();
			$("#shippingLoading").show();
		}
		function removeLoading(){
			$("#shippingLoading").hide();
		}
		
		$("#shippingForm").ajaxForm(optionsShipping);
		
		$("#shippingPlaceHolder").click(function(){
				$("#shippingPopup").show();
		 });
		
		$("#shippingButton").click(function(){
			$("#shippingForm").ajaxSubmit(optionsShipping);
		});
		
		$("#shippingZipClose").click(function(){
			$("#shippingPopup").hide();
		});
		// end for the shipping calculator on the viewcart page
		
		
		$("#memberCheckoutSubmit input").click(function(){
			$(this).parent().hide();
			$("#memberCheckoutSubmitted").show();
		});

	});
	
			// used for magic zoom so the alt image will be displayed in the magic zoom
			function changeZoomImage() {
			// Step 1
			// Stop Magic Zoom
			MagicZoom_stopZooms();
			// Step 2
			// Re-initialize Magic Zoom
			MagicZoom_findZooms();
			}
