/**
 **********************************************************************************
 *  Global calls
 **********************************************************************************
 */
(function()
{
    /**
     *  Fix IE background image flicker
     *  http://www.mister-pixel.com/
     */
    try
    {
	    document.execCommand('BackgroundImageCache', false, true);
    }
    catch(e) {}
})();

/**
 **********************************************************************************
 *  GoldNSoft namespace
 **********************************************************************************
 */
GoldNSoft = {};

/**
 **********************************************************************************
 *  sIFR
 **********************************************************************************
 */
GoldNSoft.SIFR = {
	init: function()
	{
	    if (typeof sIFR != "function" || $('#home').size() > 0) return;
		
        sIFR.replaceElement(".one-column h2, .two-column h2, .excluded h2", named({sFlashSrc: "flash/avenir-65-medium.swf", sColor: "#E41B23", sWmode: "transparent"}));
	}
};

/**
 **********************************************************************************
 *  Button hover, focus, blur effects. Print button click. Expand/Collapse buttons
 **********************************************************************************
 */
GoldNSoft.Buttons = {
    init: function() {
        var thisClass = this;
        
         $("#overview ul li a[class=disabled], .paging ul li a[class=disabled]").click(function(){ return false; });
        
        // print
        $("#print a").click(function(){
            //if (pageTracker) pageTracker._trackEvent('Recipe', 'Print', window.location.href); // Google Anaylitics event tracking
            
            window.print();
            
            return false;
        });
        
        // expand/collapse
        $("#site-map li ul").hide();
        $("#site-map li:has(ul)").prepend("<strong class=\"col\">Collapsed</strong> ").addClass("parent");
        $("#site-map li strong").click(function(){
            // toggle content visibility
            $(this).siblings("ul").toggle();
            
            // update UI
            $(this).empty();
            if ($(this).attr("class") == "col")
            {
                $(this).removeClass("col");
                $(this).html("Expanded");
                $(this).addClass("exp");
            }
            else
            {
                $(this).removeClass("exp");
                $(this).html("Collapsed");
                $(this).addClass("col");
            }
        });
    }
};

/*
*  Product tabs
*/
GoldNSoft.ProductTabs = {
	init: function()
	{
		$.address.change(function(event)
		{
			$.address.value($(this).attr('href'));

			$('#product-tabs li a').removeClass('active');
			$('.product-panel').hide();

			if (event.value == '/' || $('#' + event.value).length == 0)
			{
				$('#product-tabs li a:first').addClass('active');
				$('.product-panel:first').show();
			}
			else
			{
				$('a[href=#' + event.value + ']').addClass('active');
				$('#' + event.value).show();
			}
		});
	}
};

/**
**********************************************************************************
*  methods to run on DOM ready
**********************************************************************************
*/
$(document).ready(function() {
    GoldNSoft.SIFR.init();
    GoldNSoft.Buttons.init();
	if ($('#product-tabs').length > 0) {
        GoldNSoft.ProductTabs.init();
	}
   });
