function attachNewWindowEvent(evt,handler) {
    if (window.attachEvent) {
        window.attachEvent("on" + evt, handler);
    } else if (window.addEventListener) {
        window.addEventListener(evt,handler,false);
    }
}

function getObject(obj_name) {
    var obj;
    if (typeof obj_name == "string") {
        if (document.all) {
            obj = eval("document.all." + obj_name);
        } else {
            obj = document.getElementById(obj_name);
        }
    } else {
        obj = obj_name;
    }
    return (obj);
}

var myWidth = 0, myHeight = 0;
function determineInnerSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
}

function adjustLayout() {
    determineInnerSize();

    // maybe adjust site width (reduce margins)
    restMargin = myWidth - 1103;
    if (restMargin < 0) {
        getObject("theBody").style.backgroundPosition = "-63px";
        getObject("siteMenu").style.left = "0px";
        getObject("container").style.marginRight = ((myWidth - 200) / 2) + "px";
    } else if (restMargin < 63) {
        getObject("theBody").style.backgroundPosition = "-" + (63 - restMargin) + "px";
        getObject("siteMenu").style.left = restMargin + "px";
        getObject("container").style.margin = "0px auto";
    } else {
        getObject("theBody").style.backgroundPosition = "0px";
        getObject("siteMenu").style.left = "63px";
        getObject("container").style.margin = "0px auto";
    }

    // maybe adjust site menu position (move up if too little space)
    var menu = getObject("siteMenu");
    var factor = myHeight - menu.offsetHeight;

    if (factor < 0) {
        menu.style.top = "0";
    } else if (factor < 0.2 * myHeight) { // standard is siteMenu positioned at top: 20%
        menu.style.top = factor + "px";
    }
}


attachNewWindowEvent("load", adjustLayout);
attachNewWindowEvent("resize", adjustLayout);