
$(document).ready(function(){
	
	$(window).resize(function(){
		var count = $(".container").offset().left + 2;
		$("#rightBar").css({width: count + "px", right: "-" + count + "px"});
	});
	$(document).ready(function(){
		var count = $(".container").offset().left + 2;
		$("#rightBar").css({ width: count + "px", right: "-" + count + "px" });
	});
	
	
	
	//sun rotate
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
		//do not animate sun
	} else {
		var angle = 0;
		setInterval(function(){
			angle+=.2;
				$("#sun").rotate(angle);
		},80);
	};
	
	function animateBG(){
		$("#siteTop").stop().animate({backgroundPositionX: "-2500px"}, 250000, 'linear', function(){
			$(this).css({backgroundPositionX: "0px"});
			animateBG();
		});
	};
	animateBG();
	
	
		

	
	$("#productViewBG .productQty #addToCartBtn").hover(function(){
		$(this).stop().animate({backgroundColor: "#0f1434"});
	}, function(){
		$(this).stop().animate({backgroundColor: "#768390"});
	});
	
	$("#header #searchCartW #searchW #searchBoxW #searchBtn").hover(function(){
		$(this).stop().animate({backgroundColor: "#0084fb"});
	}, function(){
		$(this).stop().animate({backgroundColor: "#0060b6"});
	});
	
	$(".shopNowBtn").hover(function(){
		$(this).stop().animate({backgroundColor: "#74ba00"});
	}, function(){
		$(this).stop().animate({backgroundColor: "#5d9401"});
	});
	
	$(".whiteBtn").hover(function(){
		$(this).stop().animate({color: "#007ceb"});
	}, function(){
		$(this).stop().animate({color: "#0060b6"});
	});
	
	$('.prodLinks').hide(); //Hide/close all containers
	$('.prodCat.active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
	
	//On Click
	$('.prodCat').click(function(){
	    if ($(this).next().is(':hidden')) { //If immediate next container is closed...

		    $('.prodCat').removeClass('active').next().slideUp(300, function () {
		        var height = $("#prodCatList").height();
		        $("#prodList").stop().animate({minHeight: height + "px"});
		    }); //Remove all .acc_trigger classes and slide up the immediate next container

		    $(this).toggleClass('active').next().slideDown(300, function () {
		        var height = $("#prodCatList").height();
		        $("#prodList").stop().animate({ minHeight: height + "px" });
		    }); //Add .acc_trigger class to clicked trigger and slide down the immediate next container

		    $(this).stop().animate({ color: "#00265e" });

		} else {
		    $('.prodLinks').slideUp(300, function () {
		        var height = $("#prodCatList").height();
		        $("#prodList").stop().animate({ minHeight: height + "px" });
		    });
			$('.prodCat').removeClass('active');
		}
		//return false; //Prevent the browser jump to the link anchor
	});

	var height = $("#prodCatList").height();
	$("#prodList").stop().animate({ minHeight: height + "px" });
	
	$("#prodList .productItem").hover(function(){
		$(this).find(".productText").stop().animate({backgroundColor: "#1a3046"});
	}, function(){
		$(this).find(".productText").stop().animate({backgroundColor: "transparent"});
	});
	
	$("#prodCatList .prodCat").hover(function(){
		if( !$(this).hasClass("active") ){
			$(this).stop().animate({color: "#0067fe"});
		};
	}, function(){
		if( !$(this).hasClass("active") ){
			$(this).stop().animate({color: "#00265e"});
		};
	});
	$("#prodList .productItem:last").css({marginBottom: "0px"});
	
	$("#prodCatList .prodLinks a").hover(function(){
		$(this).stop().animate({color: "#0087ff"});
	}, function(){
		$(this).stop().animate({color: "#0f1434"});
	});
	
	$(".whiteBtn").hover(function(){
		$(this).stop().animate({backgroundColor: "#0f1434", color: "#ffffff"});
	}, function(){
		$(this).stop().animate({backgroundColor: "#ffffff", color: "#0060b6"});
	});
	
	//social link hover (rolls up on mouseover and mouseout. grabs the items height and uses that to determine movement.
	$(".scHdr").hover(function(){
		var h = $(this).height();
		$(this).stop().animate({backgroundPositionY: "-" + h + "px"}, 300);
	}, function(){
		var h = $(this).height();
		$(this).stop().animate({backgroundPositionY: "-" + (h*2) + "px"}, 300, function(){
			$(this).css({backgroundPositionY: "0px"});
		});
	});


////////////////////////////////////////////////fade btns
	$('.fadeThis').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0); 
	});
	
	$("body").delegate(".fadeThis", "hover", function(event) {
		if( event.type === 'mouseenter' ){
			$(this).find("span.hover").stop().fadeTo(300,1);
		} else {
			$(this).find("span.hover").stop().fadeTo(300,0);
		};
	});
	
 ////////////////////////////////////////////////////////menu//////////////////////////
	$("ul#navUL li").hover(function(){
		$(this).find(".mBtn").stop().animate({color: "#0f1434", backgroundColor: "#a5df00"});
		$(this).find(".subMenu").stop(true, true).slideDown(200);
	}, function(){
		$(this).find(".mBtn").stop().animate({color: "#ffffff", backgroundColor: "transparent"});
		$(this).find(".subMenu").stop(true, true).slideUp(200);
	});
	
	$("#header #navWrap #navUL li").each(function(){
		$(this).find(".subMenu .menuProducts .mnProdItem:first").addClass("first");
		$(this).find(".subMenu .menuProducts .mnProdItem:nth-child(5n)").addClass("last").next(".mnProdItem").addClass("first");
		$(this).find(".subMenu .menuProducts .mnProdItem:last").css({marginBottom: "0px"});
	});
	
	
	
	
	$("#header #navWrap .subMenu .menuProducts .mnProdItem").hover(function(){
		$(this).stop().animate({borderTopColor: "#0060b6", borderRightColor: "#0060b6", borderBottomColor: "#0060b6", borderLeftColor: "#0060b6"});
		$(this).find("a").stop().animate({color: "#0060b6"});
	}, function(){
		$(this).stop().animate({borderTopColor: "#ececec", borderRightColor: "#ececec", borderBottomColor: "#ececec", borderLeftColor: "#ececec"});
		$(this).find("a").stop().animate({color: "#0f1434"});
	});
 
	/////////////////anchor slide
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();
		
		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;
		
		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];
		
		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
		
		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});
	
	
	
});
