// Fix the footer to always stick to the bottom
jQuery(document).ready(function() {
    var heights  = { "fluff" : 50 };
    getHeights();

    // resizeFooter is activated on ready and resize
    resizeFooter();
    jQuery(window).resize(resizeFooter);

    function getHeights() {
        var elements = ['#footer', '#header', '#wrap'];
        for (var i in elements) {
            // Check for hasOwnProperty because of Prototype.js's extending of objects
            if (!elements.hasOwnProperty(i)) continue;

            var el = elements[i];
            heights[el] = jQuery(el).height();
        }

        heights.noWrap  = heights["#header"] + heights["#footer"] + heights.fluff;
        heights.content = heights.noWrap + heights["#wrap"];
    }

    function resizeFooter(coolResize) {
        coolResize = (coolResize == false) ? false : true;
        // Resize the #wrap div to be as high for the rest of the page
        // Of course, if the innerHeight of the page is higher than the #wrap
        // forget it all
        if (jQuery(window).height() > heights.content) {
            var newHeight = jQuery(window).height() - heights.noWrap;
            jQuery("#wrap").height(newHeight);
        }
    }
});
