var WindowSize = (function () {
    return {
        width : function () { return window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth); },
        height : function () { return window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight); }
    };
})();
var FullBleed = function () {
    var bgImage = null,
        resizeTimer = null,
        initialize = function () {
            bgImage = $('mainImage');
            if (bgImage) {
                scale();
                bgImage.removeAttribute('height');
                bgImage.removeAttribute('width');
                bgImage.style.display = 'block';
            }
            document.body.style.visibility = 'visible';
            Event.observe(window, 'resize', scale.bind(this));
        },
        ieScale = function () {
            clearTimeout(resizeTimer);
            resizeTimer = setTimeout(scale, 100);
        },
        scale = function () {
            var imgwidth = bgImage.getWidth(),
                imgheight = bgImage.getHeight(),
                winwidth = WindowSize.width(),
                winheight = WindowSize.height(),
                widthratio = winwidth / imgwidth,
                heightratio = winheight / imgheight,
                widthdiff = heightratio * imgwidth,
                heightdiff = widthratio * imgheight,
                newWidth,
                newHeight;

            if (heightdiff > winheight) {
                newWidth = winwidth;
                newHeight = heightdiff;
            } else {
                newWidth = widthdiff;
                newHeight = winheight;
            }

            bgImage.setStyle({ height: newHeight + 'px' });
        };
        initialize.apply(this);

    if (Liberty.Browser.ie === false) {
        return { 'scale' : scale };
    } else {
        return { 'scale' : ieScale };
    }
};
