function tabChanged(tabBtn) {
    $("#ProductDetails .product-detail-item").hide();

    switch(tabBtn) {
        case 'btn_pInfo':
            $("#ProductInfo").show();
            break;
        case 'btn_faq':
            $("#FAQ").show();
            break;
        case 'btn_sFacts':
            $("#SupplementFacts").show();
            break;
    }
}


if (typeof strive == 'undefined') strive = new Object();

strive = {

	sifr : function() {
		if (typeof sIFR == "function") {
            sIFR.replaceElement(named({sSelector:"h3.block-title", sFlashSrc:this.assets_path + "fla/avenir-95b.swf", sColor:"#8F8A3F", sLinkColor:"#8F8A3F", sBgColor:"#8F8A3F", sHoverColor:"#8F8A3F", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0}));
            sIFR.replaceElement(named({sSelector:"h3.header-box", sFlashSrc:this.assets_path + "fla/avenir-95b.swf", sColor:"#8F8A3F", sLinkColor:"#8F8A3F", sBgColor:"#8F8A3F", sHoverColor:"#8F8A3F", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center"}));
		};
	},

    init_navigation : function() {
        if ($("#MainNav").size() > 0) {
            var so = new SWFObject(this.assets_path + "flash/MainNav.swf", "MainNavFlash", "970", "80", "9", "#ffffff");
            so.addParam("allowScriptAccess", "sameDomain");
            so.addParam("scale", "noscale");
            so.addParam("salign", "T");
            so.addParam("wmode", "transparent");
            so.addVariable("xmlPath", strive.mainNavXMLPath);
            so.addVariable("itemSelected", strive.mainNavItemSelected);
            so.write("MainNav");
        }
    },

    init_Animation : function(path) {
        if ($("#Animation").size() > 0) {
			// Parse the query string
			qs = location.search.substring(1, location.search.length);
			
			//if( qs.indexOf('test') >= 0 ) temp = "banner";
			//else temp = "header"
			temp = "banner";
			
			var so = new SWFObject(this.assets_path + "flash/" + temp + ".swf", "StriveHeader", "958", "236", "9", "#ffffff");
            //var so = new SWFObject(this.assets_path + "flash/header.swf", "StriveHeader", "958", "236", "9", "#ffffff");
			
            so.addParam("allowScriptAccess", "sameDomain");
            so.addParam("scale", "noscale");
            so.addParam("salign", "T");
            so.addParam("wmode", "transparent");
            so.addVariable("xmlPath", this.assets_path + "xml/data.xml");
            //so.addVariable("var1", this.assets_path + "xml/data.xml");
            so.write("Animation");
        }
    },

	init_productTabs : function() {
        if ($("#ProductSubNav").size() > 0) {
            var so = new SWFObject(this.assets_path + "flash/product_tabs.swf", "ProductTabs", "330", "30", "9", "#ffffff");
            so.addParam("allowScriptAccess", "sameDomain");
            so.addParam("scale", "noscale");
            so.addParam("salign", "T");
            so.addParam("wmode", "transparent");
			so.addVariable("bgColor", ((strive.tabBgColor) ? ('0x'+strive.tabBgColor) : '0x6F81A7'));
			so.addVariable("bgColorSelected", ((strive.tabBgColorSelected) ? ('0x'+strive.tabBgColorSelected) : '0x23355B'));
            so.write("ProductSubNav");
        }
	},

    init_productDetails : function() {
        if ($("#ProductDesc").size() > 0) {
            $("h2").css('color', '#'+strive.tabBgColor);
            $("#FAQ .faq-question").css('color', '#'+strive.tabBgColorSelected);
            $("#FAQ ol.faq > li").css('color', '#'+strive.tabBgColorSelected);
            $("#ProductDetails .product-detail-item").hide();
            $("#ProductInfo").show();
            $("#FAQ .faq-question + .faq-answer").hide();
            $("#FAQ .faq-question").css('cursor', 'pointer').click(function(){
                $(this).next('.faq-answer').toggle();
            })
        }
    },

    init_theSource : function() {
        if ($(".post-list-page #FeaturedCategories").size() > 0) {
            $(".post-list-page #FeaturedCategories ul li").prepend('<div class="category-tree-control">&nbsp;</div>');
            $(".post-list-page #FeaturedCategories ul.child-category-block").each(function() {
                $(this).prevAll('div').click(function(){
                    $(this).nextAll('ul').toggle();
                    $(this).toggleClass('tree-control-hidden').toggleClass('tree-control-shown');
                }).addClass('tree-control-hidden');
            }).hide();
        }
    },

    init_StoreLocator : function() {
        if ($("#FormStoreSearch").size() > 0) {
            strive.stores = new Object();
            $("#id_city > option").each(function(i){ //mount one array of cities for each province
                var division = $(this).text().indexOf(' - ');
                var province = $(this).text().substring(0,division);
    
                if (typeof strive.stores[province] == 'undefined')
                    strive.stores[province] = [];
                strive.stores[province].push({'value':$(this).attr('value'), 'name':$(this).attr('value')});
            });
            
            var citySelect = document.getElementById('id_city'); //get the object with the id 'id_city'
            var province = $("#id_province option:selected").text(); //get the text of the province selected
            
            //If province is 'Select a province' or there's no city for the selected province
            if ($("#id_province option:selected")[0].value == '') {
                citySelect.options.length = 0; //clean up the city select
                $("#id_city").attr('disabled', 'true'); //disable the city select
                $("#id_SearchStore").attr('disabled', 'true');//disable the search button
            } else {
                if (typeof strive.stores[province] != 'undefined') {
                    //var selectedText = citySelect.options[citySelect.selectedIndex].text;
                    var city_selected = $("#id_city option:selected").text().substr(($("#id_city option:selected").text().indexOf(" - ")) + 3);
                    citySelect.options.length = 0; //clean up the city select
                    citySelect.options[0] = new Option('select a city', ''); //set up the first item for the city select
                    for(i=1; i<= strive.stores[province].length; i++){ //set up all the other items for the city select
                        citySelect.options[i] = new Option(strive.stores[province][(i-1)].name,strive.stores[province][(i-1)].value);
                    }
                    $("#id_city option:contains('" + city_selected + "')").attr('selected', 'selected');
                } else {
                    citySelect.options.length = 0; //clean up the city select
                    citySelect.options[0] = new Option('select a city', ''); //set up the first item for the city select
                }
            }
            
            $("#id_province").change(function(){ //When a province is selected
                if ($("#id_province option:selected")[0].value != '') { //It isn't the first option 'Select a province'
                    
                    var pSelected = $("#id_province option:selected").text(); //get the province selected after the province is selected
                    
                    $("#id_SearchStore").attr('disabled', false); // enable the search button
                    $("#id_city").attr('disabled', false); // enable the city select
                    citySelect.options.length = 0; //clean up the city select
                    citySelect.options[0] = new Option('select a city', ''); //set up the first item for the city select
                            
                    if (typeof strive.stores[pSelected] != 'undefined') {
                        for(i=1; i<= strive.stores[pSelected].length; i++){ //set up all the other items for the city select
                            citySelect.options[i] = new Option(strive.stores[pSelected][(i-1)].name,strive.stores[pSelected][(i-1)].value);
                        }
                    }
                } else {
                    citySelect.options.length = 0; //clean up the city select
                    $("#id_city").attr('disabled', 'true'); //disable the city select
                    $("#id_SearchStore").attr('disabled', 'true');//disable the search button
                }
            });
        }
    },

    init : function() {
        this.init_navigation();
        this.init_Animation();
		this.init_productTabs();
        this.init_productDetails();
        this.init_theSource();
        this.init_StoreLocator();
    }    
};

$(document).ready(function(){
    strive.init();
});