/*
 * Clorox2 Common Javascript
 *
 * October 11, 2009
 *
 */

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

/**
 * initAnythingSlider(): setup the 'anything' slider, which is used on the homepage
 *
 */
$clorox2.initAnythingSlider = function () {
    function formatText(index, panel) {
        return index + "";
    }
	
    $(function () {
	
        $('.anythingSlider').anythingSlider({
            easing: "swing",        		// Anything other than "linear" or "swing" requires the easing plugin
            autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
            delay: 15000,                   // How long between slide transitions in AutoPlay mode
            startStopped: false,            // If autoPlay is on, this can force it to start stopped
            animationTime: 600,             // How long the slide transition takes
            hashTags: true,                 // Should links change the hashtag in the URL?
            buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
            pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
            startText: "Go",             	// Start text
            stopText: "Stop",               // Stop text
            navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
        });
	    
        $("#slide-jump").click(function(){
            $('.anythingSlider').anythingSlider(6);
        });
	    
    });
}

/**
 * initTabContainers(): setup the tabs
 *
 */
$clorox2.initTabContainers = function() {

    $(function () {
        var tabContainers = $('div.tabs > div');
        tabContainers.hide().filter(':first').show();

        $('div.tabs ul.containerNav a').click(function () {
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $('div.tabs ul.containerNav a').removeClass('selected');
            $(this).addClass('selected');
            return false;
        }).filter(':first').click();

    });

}

$(window).load(function () {
    // fix PNG transparency. We have to do this on load(), not ready(), because
    // all of the pngs have to have loaded before we can apply the fix to them
 
    // NOTE: we have to apply the fix to the individual elements that we need to fix
    // not everything.
    $('#possibilityBoxGraphic, #carsonBoxGraphic').pngfix();
});
	
$(document).ready(function() {
    $clxcommon.initExternal();
    $clxcommon.initWarning();
    $clxcommon.attachClickAnalytics('promo');
	
    $('#c2moneyback').mousedown(function() {
        $clxcommon.trackAnalyticsPageView('download','c2-money-back-guaranteePDF');
    });
		
    $('#cheatsheetPDF').mousedown(function() {
        $clxcommon.trackAnalyticsPageView('download','cheatsheetPDF');
    });

    // accordion effect for faq list
    if ($('.faqBox').length > 0) {

        var activeId = (document.location.hash != '') ? '.class-' + document.location.hash.replace(/./, '') : false;
				
        $('.faqBox').accordion({
            header: "h3",
            collapsible: true,
            active: activeId,
            alwaysOpen: false,
            autoHeight: false
        });
    }

    // only init the sliders if they are found in the page
    if ($('.anythingSlider').length > 0)
        $clorox2.initAnythingSlider();
	
    $clxcommon.createLink('#promoPacks', '/our-products/');
    $clxcommon.createLink('#promoPossibility', '/possibility-shop/');
    $clxcommon.createLink('#promoCarson', '/carson-kressley/');
    $clxcommon.createLink('#promoSoccer', 'http://www.usyouthsoccer.org/index.html');
    $clxcommon.createLink('#promoWhy', '/our-products/');
    $clxcommon.createLink('#promoTour', 'http://clorox2-events.com/index.cfm?e=0&action=main.welcome&id1=&id2=');
    $clxcommon.createLink('#promoStain', '/stain-app/');
    $clxcommon.createLink('#promoMoney', '/money-back-guarantee/');
    $clxcommon.createLink('#soccerBox', 'http://www.USYouthSoccer.org');
    $clxcommon.createLink('#possibilityBox', '/possibility-shop/');
    $clxcommon.createLink('#carsonBox', '/carson-kressley/');
    $clxcommon.createLink('#tourPromoBox', '/tour/');
    $clxcommon.createLink('#promoMeet', '/our-products/');
    $clxcommon.createLink('#promoBuy', 'http://www.cloroxproductlocator.com/');
    $clxcommon.createLink('#tourCta', 'http://www.clorox2-events.com/');
    $clxcommon.createLink('.slideGrassStain', '/mystain/find-a-stain/grass/');
    $clxcommon.createLink('.slideInkStain', '/mystain/find-a-stain/ballpoint-ink/');
    $clxcommon.createLink('.slideSoccer', '/mystain/find-a-stain/dirt/');
    $clxcommon.createLink('.slideDate', '/mystain/find-a-stain/red-wine/');
});
