$(document).ready(function() {
	
	
	
	
	// Activate anchorAnimate plugin 
	$("a.anchorLink").anchorAnimate();	
	// Slider for Product Section
	$('#coda-slider-1').codaSlider({
		dynamicArrows: false,
		dynamicTabs: false
	});
	
	
	// Dropdowns for Products and Contact
	$(function () {
        $('.sublinks').each(function () {
			$(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function () {
				var current = $('.sublinks:eq(0)', this);
				current.fadeIn(100);
			},
			out: function () {
				var current = $('.sublinks:eq(0)', this);
				current.fadeOut(100);
			}
			});
		});
    });
	
	// Masthead Color Changes when Subnav clicked
	function activeMarker () {
		$('#landing #Products .masthead').delay(400).animate({
			backgroundColor: "#00A4E4"
		}, 400);
		$('#landing #Home').delay(400).animate({
			backgroundColor: "#00A4E4"
		}, 400);
		goToByScroll("Products");
	}
	function activeSafety () {
		$('#landing #Products .masthead').delay(400).animate({
			backgroundColor: "#00A160"
		}, 400);
		$('#landing #Home').delay(400).animate({
			backgroundColor: "#00A160"
		}, 400);
		goToByScroll("Products");
	}
	function activeLabels () {
		$('#landing #Products .masthead').delay(400).animate({
			backgroundColor: "#8DC63F"
		}, 400);
		$('#landing #Home').delay(400).animate({
			backgroundColor: "#8DC63F"
		}, 400);
		goToByScroll("Products");
	}
	$('.tab1 a').click(function(){
		activeMarker();
	});
	$('.tab2 a').click(function(){
		activeSafety();
	});
	$('.tab3 a').click(function(){
		activeLabels();
	});
	$("#redlink").click(function(){
		activeSafety();
	});
	
	$('.homenav').click(function(){
		$('#landing #Products .masthead').delay(400).animate({
			backgroundColor: "#00A4E4"
		}, 400);
		$('#landing #Home').delay(400).animate({
			backgroundColor: "#00A4E4"
		}, 400);
	});
	
	// use hashtag to remember
	var hash = false; 
	checkHash();
	function checkHash(){ 
		if(window.location.hash != hash) { 
			hash = window.location.hash; 
			processHash(hash); 
		} t=setTimeout("checkHash()",400); 
	}
	function processHash(hash){
		if (hash == "#1"){	
			activeMarker();
		}
		if (hash == "#1?section=Products"){	
			activeMarker();
		}
		if (hash == "#2"){	
			activeSafety();
		}
		if (hash == "#2?section=Products"){	
			activeSafety();
		}
		if (hash == "#3"){	
			activeLabels();
		}
		if (hash == "#3?section=Products"){	
			activeLabels();
		}
	}
	
	

	 // Image Swapping on hover for Sub Pages
	 var galleryImageDefault = $("#sub .gallery").attr("src");
	 $(function(){ 
		 $("#sub .productThumb").hoverIntent(function(){
			var galleryImage = $(this).attr("alt");
			$("#sub .gallery").attr("src", galleryImage);
		 }, function(){
			$("#sub .gallery").attr("src", galleryImageDefault);
		 })
	 });
	 // Image Swapping on hover for SAFETY
	 var gallerySafetyImageDefault = $(".safety .gallery").attr("src");
	 $(function(){ 
		 $(".safety .productThumb").hoverIntent(function(){
			var gallerySafetyImage = $(this).attr("alt");
			$(".safety .gallery").attr("src", gallerySafetyImage);
		 }, function(){
			$(".safety .gallery").attr("src", gallerySafetyImageDefault);
		 })
	 });
	
	// Modals for Label Previews, using FancyBox plugin 
	$(".preview").fancybox({
		'opacity'		: true,
		'overlayColor'	: '#fff',
		'overlayOpacity': 0.4,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'none'
	});
	
	function goToByScroll(id){
     	$('html,body').animate({scrollTop: $("#"+id).offset().top},'fast');
	}
	function fromSubPage() {
		var goingToProducts = $.url.param("section");
		if (goingToProducts == "Products"){	
			goToByScroll("Products");
		};
	}
	fromSubPage();
	
	
	// Tabs for Feature on Homepage
	$(".tab_content").hide();
	$("ul.tabs li:nth-child(1)").addClass("active").show();
	$(".tab_content:nth-child(1)").show();
	
	$("ul.tabs li").click(function () {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn('slow');
		return false;
	});
	


});

