﻿/*********************************************************************************

Bionex Multimedia universal JavaScript file
v. 1.0
Copyright Bionex Multimedia Inc.

*********************************************************************************/

//pushes footer to bottom by enlarging content area
function footerize(contentID, footerID) {
    var content = document.getElementById(contentID);
    var footer = document.getElementById(footerID);

    //gets total height to bottom of footer
    // getPageCoords(footer).x: dist. to top of pg from top of footer ; footer.offsetHeight: height of footer
    var h2f = getPageCoords(footer).y + footer.offsetHeight;
    var diff = window.innerHeight - h2f;
    //sets the height if extra space found
    // NOTE: heights must be .minHeight (vs .height) as otherwise causes problems w/ iframes
    if (diff > 0) {
        //makes content too long
        content.style.minHeight = "1000px";
        //auto-corrects the now too long by checking length of page vs. window
        // (this accounts for wrapper divs that may surround content div and cause content div to be too short vs the old way:
        //  content.style.height = (content.offsetHeight + diff) + "px";)
        var scroll = document.body.offsetHeight - window.innerHeight;
        if (scroll > 0) content.style.minHeight = (parseInt(content.style.minHeight.replace("px","")) - scroll) + "px";
    }
}

//gets distance from element to top / left of page
function getPageCoords (element) {
    var coords = { x: 0, y: 0 };
    while (element) {
        coords.x += element.offsetLeft;
        coords.y += element.offsetTop;
        element = element.offsetParent;
    }
    return coords;
}
