
var P5_viewHeightMin   = 620;
var P5_containerHeight = 512;
var P5_bgImageHeight   = 1536;

function setCenter() {
    var viewHeight = getClientHeight();
    var topMargin = 40;
    var bgTop = Math.floor((viewHeight - P5_bgImageHeight) / 2);
    if (viewHeight > P5_viewHeightMin) {
        topMargin = Math.floor((viewHeight - P5_containerHeight) / 2);
    } else {
        bgTop = Math.floor((P5_containerHeight - P5_bgImageHeight) / 2) + topMargin;
    }
    document.body.style.backgroundPosition = '50% ' + bgTop + 'px';
    var elm = document.getElementById('container');
    elm.style.marginTop    = topMargin + 'px';
    elm.style.marginBottom = topMargin + 'px';
}

function getClientHeight()
{
    if (document.documentElement.clientHeight) {
        return document.documentElement.clientHeight;
    }
    if (document.body.clientHeight) {
        return document.body.clientHeight;
    }
    if (window.innerHeight) {
        return window.innerHeight;
    }
    return 0;
}

if(window.addEventListener) {  
    window.addEventListener("load", setCenter, false );   
    window.addEventListener("resize", setCenter, false );   
} else if(window.attachEvent) {
    window.attachEvent("onload", setCenter);
    window.attachEvent("onresize", setCenter);
}


/**
 * Legacy IE style
 */
if (navigator.userAgent.indexOf('MSIE 6') != -1) {
    document.write('<link rel="stylesheet" href="/assets/style/ie6.css" />');
}

