/*
 *  Fix IE background image flicker (via http://www.mister-pixel.com/)
 */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

/*
 *	sIFR
 */
var SIFR = {
	init: function()
	{
		if (typeof sIFR == "function")
		{
			sIFR.replaceElement("#copy h1", named({sFlashSrc: "flash/minion-pro.swf", sColor: "#006940"}));
			sIFR.replaceElement(".difference h2", named({sFlashSrc: "flash/minion-pro.swf", sColor: "#757575"}));
			sIFR.replaceElement("fieldset h2", named({sFlashSrc: "flash/minion-pro.swf", sColor: "#006940"}));
		}
	}
};

/*
 *  Product hover
 */
var ProductHover = {
    init: function() {
        $("ul#product-list li").hover(function(){
            $(this).addClass("hover");
        }, function(){
            $(this).removeClass("hover");
        });
    }
};

/*
 *  Button hover, focus, blur effects. Print button click. Expand/Collapse buttons
 */
var Buttons = {
    init: function() {
        var thisClass = this;
        
        // hover, focus, blur, disabled
        $("#overview ul li a, .paging ul li a, #sign-up a, #send a")
        .hover(thisClass.showOverImage(), thisClass.showOffImage())
        .focus(thisClass.showOverImage())
        .blur(thisClass.showOffImage());
        $("#overview ul li a[class=disabled], .paging ul li a[class=disabled]")
        .each(thisClass.showDisabledImage())
        .hover(thisClass.showDisabledImage(), thisClass.showDisabledImage())
        .focus(thisClass.showDisabledImage())
        .blur(thisClass.showDisabledImage())
        .click(function(){return false;});
        
        // print
        $("#print a").click(function(){
            window.print();
            
            return false;
        });
        
        // expand/collapse
        $("div.site-map li ul").hide();
        $("div.site-map li:has(ul)").prepend("<strong class=\"col\">Collapsed</strong> ").addClass("parent");
        $("div.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");
            }
        });
    },
    
    showOffImage: function()
    {
        return (function(){$(this).parent().css("background-position", "0 0")});
    },
    
    showOverImage: function()
    {
        return (function(){$(this).parent().css("background-position", "0 50%")});
    },
    
    showDisabledImage: function()
    {
        return (function(){$(this).parent().css("background-position", "0 100%")});
    }
};

/*
 *  Sign Up form validation
 */
/*
var SignUpForm = {
    nameClientID: "",
    emailClientID: "",
    
    init: function()
    {
        var thisClass = this;
        var errors = [];
        
        $("#sign-up a").click(function(){
            $(":input.required").each(function(){
                if ($(this).val() == "")
                {
                    var id = $(this).attr("id");
                    var html = $("label[for=" + id + "]").html();
                    errors.push(html.split("<strong>")[0] + " is required");
                    $("label[for=" + id + "] strong").addClass("required");
                }
            });
            
            // no errors, allow submit
            if (errors.length == 0)
            {
                return true;
            }
            
            // generate error message and insert into page
            $("fieldset").prepend("<div id=\"errors\"><p>Please correct the following errors:</p><ul></ul></div>");
            $.each(errors, function(i, n){
                $("#errors ul").append("<li>" + errors[i] + "</li>");
            });
            
            return false;
        });
    },
    
    setNameClientID: function(val)
    {
        this.nameClientID = val;
    },
    
    setEmailClientID: function(val)
    {
        this.emailClientID = val;
    }
};
*/

/*
 *  methods to run on DOM ready
 */
$(document).ready(function() {
    SIFR.init();
    ProductHover.init();
    Buttons.init();
});

/*
 *	detach all handlers
 */
$(window).unload(function(){
    $("*").unbind();
});