
var firstTime = 1;

function resizeBackground()
{
    var width = (window.innerWidth)? window.innerWidth:document.body.offsetWidth;
    var height = (window.innerHeight)? window.innerHeight:document.body.offsetHeight;

    var imageHeight = document.getElementById("backgroundImage").height;
    var imageWidth = document.getElementById("backgroundImage").width;

    var docHeight = (document.body.scrollHeight) ? document.body.scrollHeight : 0;
    var docWidth = (document.body.scrollWidth) ? document.body.scrollWidth : 0;

    var styleHeight = "105%";
    var styleWidth = "105%";

    if (height < parseInt(docHeight))
    {
        height = docHeight;
        styleHeight = (docHeight * 1.05) + "px"
    }

    if (width < parseInt(docWidth))
    {
        width = docWidth;
        styleWidth = (docWidth * 1.05) + "px"
    }

    if (imageHeight < height)
    {
//     alert("ay");
        document.getElementById("backgroundImage").style.height = styleHeight;
        document.getElementById("backgroundImage").style.width = "auto";
    }
    else if (imageWidth < width)
    {
//     alert("yo");
        document.getElementById("backgroundImage").style.width = styleWidth;
        document.getElementById("backgroundImage").style.height = "auto";
    }

    // XXX HACK
    document.getElementById("mainContentImage").style.height = "100%";
    if (firstTime == 1)
    {
        firstTime = 0;
        resizeBackground();
    }
}

window.onload = resizeBackground;
window.onresize = resizeBackground;

