// Define page events.
window.onload = resize;
window.onresize = resize;

// Size the page contents (the divs) to fill the browser window.
function resize() {
    
    // Measure the width and height of the browser window's
    // client area to derive the pixel wd/ht of the map.
    var winWd = 0, winHt = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        winWd = window.innerWidth;
        winHt = window.innerHeight;
    } else if (document.documentElement &&
            (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        winWd = document.documentElement.clientWidth;
        winHt = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        winWd = document.body.clientWidth;
        winHt = document.body.clientHeight;
    }

    // Enforce a minimum width for the page.
    if (winWd < 480) {
        winWd = 480;
    }
    else {
        // Narrow the page a bit to account for vertical scroll bar in Firefox and Safari.
        // (winWd does account for vertical scroll bar in FireFox and Safari)
        winWd = winWd - 8;
    }

    // Unstretch the div heights so that their natural height can be referenced.
    document.getElementById("divComment").style.height = "auto";
    document.getElementById("divContent").style.height = "auto";

    // Stretch content to fit the window's width.  (Width factors are typically 
    // 800px minus the element's left position in style.css.)
    document.getElementById("divPage").style.width = (winWd - 20) + "px";
    document.getElementById("divHeader").style.width = (winWd - 20) + "px";
    document.getElementById("divHeaderExpander").style.width = (winWd - 468) + "px";
    document.getElementById("divHeaderLogo").style.marginLeft = (winWd - 102) + "px";
    document.getElementById("divContent").style.width = (winWd - 158) + "px";
    document.getElementById("divFooter").style.width = (winWd - 20) + "px";
    document.getElementById("divFooterExpander").style.width = (winWd - 290) + "px";
    document.getElementById("divFooterSf").style.marginLeft = (winWd - 146) + "px";

    // Stretch the comments (the sidebar text) and content in height to reach the footer evenly.
    var divFooterTop = document.getElementById("divFooter").offsetTop;
    var divCommentTop = document.getElementById("divComment").offsetTop;
    var divContentTop = document.getElementById("divContent").offsetTop;
    document.getElementById("divComment").style.height = (divFooterTop - divCommentTop - 115) + "px";
    document.getElementById("divContent").style.height = (divFooterTop - divContentTop - 95) + "px";

    // Done.
    return true;
}

