// if the min screen size not defined in child page, set default here
if(!minScreenSize) { var minScreenSize = {width: 840,height:640}; }
if(!layoutMode) { var layoutMode = ""; }

// initialize the layout
$.layout({mode: layoutMode, screen: minScreenSize});

var BgImgRatioHeightOverWidth;
var BgImgRatioWidthOverHeight;

function resizeBackgroundImage()
{
    var h = BgImgRatioHeightOverWidth * $(window).width();

    if((h < $(window).height())||(h<$(document).height()))
    {
        var w = BgImgRatioWidthOverHeight * $(window).height();
        if(w >= $(window).width())
        {
            $('div.background-container img').css({
                width:  w + 'px',
                height: $(window).height() + 'px'
            });
        }
        else
        {
            $('div.background-container img').css({
                width:  '100%',
                height: '100%'
            });
        }
    }
    else
    {
        $('div.background-container img').css({                    
            width:  $(window).width() + 'px',
            height: h + 'px'
        });
    }
}

function headerCenter() {
    //vertical center
    $(".header").verticalCenter({
        minH: globalSettings.centerBoxDefault.minH,
        maxH: globalSettings.centerBoxDefault.maxH,
        offsetTop:40,
        offsetBot:0     
    }).css("visibility","visible");     
}

//*** Event Handlers ***

// wait for background image to load
$(document).bind('backgroundLoaded', function(){
    BgImgRatioHeightOverWidth = $('div.background-container img').height()/$('div.background-container img').width();
    BgImgRatioWidthOverHeight = $('div.background-container img').width()/$('div.background-container img').height();
    resizeBackgroundImage();
});

$(document).bind('newBackgroundLoaded', function(event, i) {
    BgImgRatioHeightOverWidth = $('div.background-container img.image' + i).height() / $('div.background-container img.image' + i).width();
    BgImgRatioWidthOverHeight = $('div.background-container img.image' + i).width() / $('div.background-container img.image' + i).height();
    resizeBackgroundImage();
});

$(document).ready(function(){
    $(window).bind("resize", function(){
        resizeBackgroundImage();
    });
    //if(!$.browser.msie) {Cufon('h1')('h2'); } //Fonts
}); 

$(window).resize(headerCenter);

headerCenter();
