﻿
$("html").addClass("js-footer");
$(window).load(function() {
    // Execute on document ready
    setAutoHeight();
});

function setAutoHeight() {
    try {
        var windowHeight = $(window).height();
        var containerHeight = $("#container").height();
        var heightDiff = windowHeight - containerHeight;
        var element = $("#fullHeightElement");
        if (element.length) {
            var footerHeight = $("#footer").innerHeight();
            var elementHeight;
            if (heightDiff > 0) {
                // The following compensates for the element's 10px of bottom margin
                elementHeight = windowHeight - element.offset().top - footerHeight - 10;  
            }
            if (heightDiff < 0) {
                // The following compensates for the element's 10px of bottom margin
                elementHeight = containerHeight - element.offset().top - footerHeight - 10;
            }
            element.height(elementHeight);
        }
        else {
            if (heightDiff > 0) {
                $("#footer").css("margin-top", heightDiff);
                $("#footer").css("margin-top", heightDiff);
            }
        }
    }
    catch (err) {
        // Do nothing
    }
    $("html").removeClass("js-footer");
}
