/*
 * Site Common Javascript
 *
 * May 10, 2010
 *
 */

// init the local namespace. All functions should be part of this namespace
var $gld = window.$gld || {};  



$(document).ready(function() {

    $clxcommon.initExternal();
    $clxcommon.initWarning();
    $clxcommon.attachClickAnalytics('clorox-promo');
    $clxcommon.attachClickAnalytics('clorox-video');
    $clxcommon.attachClickAnalytics('clorox-download');
    	
	/**
	 * Cufon font replacement
	 */
	 
	/* pre hack for inner html that needs to not be replaced */
	var exWarning;
	var warningParent = [];
	//find all of the warning elements
	$("span.warning-text-eng", document.body).each(function () {
		//get the warning text (not static in case this changes in the library)
		exWarning = $(this).html();
		//get each parent as unique object
		warningParent[warningParent.length] = $(this).parent();
		//ditch the warning so it doesn't get replaced
    	$(this).remove();
    });
    
    // ALL CUFON REPLACEMENT MUST HAPPEN HERE
	Cufon.replace('.replace',{hover:true});
	Cufon.replace('h1:not(.cufonExclude)'); 
	Cufon.replace('h2'); 
	Cufon.replace('h3'); 
	Cufon.replace('h4'); 
	Cufon.replace('h5');
	Cufon.replace('#mainNav span');
	Cufon.replace('#mainNav a.primary');
	Cufon.replace('#mainNav a.greentab');
	Cufon.replace('#mainNav ul.secondary > li > a');
	Cufon.replace('ul#mainNav ul.secondary li.active ul.tertiaryNav li a',{hover:true});
	Cufon.replace('#storageTipsSearchLbl');
	Cufon.replace('#tipOfTheWeek .subject');
	//in glad to give
	Cufon.replace('.title');
	Cufon.replace('.section-title');
	Cufon.replace('.button');
    Cufon.replace('a#do_action');
    Cufon.replace('.sub-head');
    //still tasty
    Cufon.replace('#st-cat-title');
    Cufon.replace('#st-question');
    Cufon.replace('#st-promos .st-promo-desc');
    Cufon.replace('.still-tasty-cat .cat-title');
   

    
    
    
    /* post hack for inner html that needs to not be replaced */
    //make sure cufon has triggered otherwise it does it later 
    //for some reason and then our text gets replaced
	Cufon.now();
    //loop through the parent objects and add the warning text/element back in
    for(var i in warningParent){
    	$(warningParent[i]).append('<span class="warning-text-eng">'+exWarning+'</span>');
    }
    
	//END Cufon font replacement
     

    //Main Nav slide-down
    $('ul#mainNav li span.primary:not(.dont-drop)').click(function(){
		$(this).toggleClass('ul.secondary').next().slideToggle("fast");
	});
	// main navigation z-indexing
	var zIndexNumber = 1000;
	$('ul#mainNav li').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	

/* Product Pages */

	// be sure to show the buy/available sizes box if there are available sizes
	if($(".available").length > 0){
        $("#buyBox").show();
    }
    

/* Home Page */

	//left and right panel hovers + dropdowns
	$('#homeStorage').hover(function () {
		$(this).css('background', 'url(/img/home/home_storage_over.jpg)');
		$('li.dropHeading ul:eq(0)',this).slideToggle("fast");
		$('li.dropHeading',this).css('background', 'url(/img/home/select_over.png)');
	}, function () {
		$(this).css('background', 'url(/img/home/home_storage.jpg)');
		$('li.dropHeading ul:eq(0)',this).slideToggle("fast");
		$('li.dropHeading',this).css('background', 'url(/img/home/select.png)');
	});
	$('#homeTrash').hover(function () {
		$(this).css('background', 'url(/img/home/home_trash_over.jpg)');
		$('li.dropHeading ul:eq(0)',this).slideToggle("fast");
		$('li.dropHeading',this).css('background', 'url(/img/home/select_over.png)');
	}, function () {
		$(this).css('background', 'url(/img/home/home_trash.jpg)');
		$('li.dropHeading ul:eq(0)',this).slideToggle("fast");
		$('li.dropHeading',this).css('background', 'url(/img/home/select.png)');
	});
	
	//home page promo slider
	if($('#homePromoSlider').length>0){
		//set up the nivo slider options
		$('#homePromoSlider').nivoSlider({
			effect:'sliceUpDownLeft', // Specify sets like: 'fold,fade,sliceDown'
	        slices:20, // For slice animations
	        animSpeed:1000, // Slide transition speed
	        pauseTime:5000, // How long each slide will show
	        startSlide:0, // Set starting Slide (0 index)
	        directionNav:false, // Next & Prev navigation
	        controlNav:true, // 1,2,3... navigation
	        controlNavThumbs:false, // Use thumbnails for Control Nav
	        pauseOnHover:false, // Stop animation while hovering
	        manualAdvance:false, // Force manual transitions
	        beforeChange: function(){}, // Triggers before a slide transition
	        afterChange: function(){}, // Triggers after a slide transition
	        slideshowEnd: function(){}, // Triggers after all slides have been shown
	        lastSlide: function(){}, // Triggers when last slide is shown
	        afterLoad: function(){} // Triggers when slider has loaded
	    });
	
	}
	
	// Set up Waste Less Innovation slider
	if($('#innovationSlider').length>0){
		$('#innovationSlider').jcarousel({
		// Configuration goes here
			visible: 4,
			scroll: 1,
			wrap: 'circular'
		});
	}
	
$clxcommon.createLink('#btnTailgatePDF', '/pdf/glad-tailgate-toolkit.pdf');
$clxcommon.createLink('#btnEverydayPDF', '/pdf/glad-everyday-event-toolkit.pdf');

});








