/*

  Make the mainbody fill the rest of the page

  Requires:
    addevent.js

  v1.0 18/08/2009, Hayo Baan
       Initial version

  v2.0 18/07/2010, Hayo Baan
       Added calculation of mainbodyWidth

  v2.1 27/07/2010, Hayo Baan
       jQuery adaptations

*/

// Flag to indicate whether or not IE8 work-around has been triggered yet
var alreadyDone=0;

// Height of the mainbody
var mainbodyHeight=500;
var mainbodyWidth=800;

function verticalPos(elem) {
    return elem.offsetParent ? (elem.offsetTop + verticalPos(elem.offsetParent)) : elem.offsetTop;
}

function resizeBody() {
    var footerPos=verticalPos(document.getElementById("footer"));
    var mainbodyPos=verticalPos(document.getElementById("mainbody"));
    mainbodyWidth=document.getElementById("mainbody").offsetWidth;
    mainbodyHeight=Math.max(50,footerPos-mainbodyPos);
    document.getElementById("mainbody").style.height=mainbodyHeight+"px";
    document.getElementById("mainbody").focus();
    // Work-around for stupid IE8 bug where table content would not resize properly
    if ((navigator.userAgent.search(/\bMSIE [8]/) > -1) &&
        !alreadyDone &&
        (document.getElementById("home") || document.getElementById("contact"))) {
        document.getElementById("mainbody").innerHTML+=""; alreadyDone=1;
    }
}

$(document).ready(resizeBody);
$(window).resize(resizeBody);

