﻿var arrLittleBayBackgroundWidths = new Array(1224, 1280, 1600);
var arrLittleBayBackgroundHeights = new Array(768, 1024, 1200);
var arrLittleBayBackgroundFiles = new Array("bg_body_cloud.jpg", "LittleBayBG_1280x1024.jpg", "LittleBayBG_1600x1200.jpg");

var arrPortalFlashWidths43 = new Array(1003, 1259, 1579);
var arrPortalFlashHeights43 = new Array(624, 880, 1056);

var arrPortalFlashWidths1610 = new Array(1259, 1419, 1659);
var arrPortalFlashHeights1610 = new Array(656, 756, 906);

var arrPortalFlashWidths169 = new Array(1259, 1339, 1899);
var arrPortalFlashHeights169 = new Array(576, 624, 936);

var resizeBak;

function AutoSizing_DoLittleBayBackground()
{
    if (getWindowHeight() < 756)
        document.getElementById("inner-container").style.paddingTop = "10px";
        
    resizeBak = window.onresize;
    window.onresize = null;
    var clientWidth = Math.max(getWindowWidth(), getScrollWidth());
    var clientHeight = Math.max(getWindowHeight(), getScrollHeight());
    //Find the smallest background that is bigger than the browser bounds
    var index = 0;
    while (clientWidth > arrLittleBayBackgroundWidths[index] || clientHeight > arrLittleBayBackgroundHeights[index])
    {
        if (index == arrLittleBayBackgroundWidths.length-1)
            break;                                              //browser rezolution is larger than any background file
        index++;
    }
    var divElement = document.getElementById("container");
    divElement.style.backgroundImage = "url(ContentFiles/AutoSizing/" + arrLittleBayBackgroundFiles[index] + ")";
    divElement.style.width = clientWidth + "px";
    divElement.style.height = clientHeight + "px";
    
    window.setTimeout("window.onresize = resizeBak;", 100);
}

function AutoSizing_DoPortalSplash()
{
    var arrPortalFlashWidths, arrPortalFlashHeights;
    var rezType = GetScreenRezType();
    if (rezType == 1)
    {
        arrPortalFlashWidths = arrPortalFlashWidths43;
        arrPortalFlashHeights = arrPortalFlashHeights43;
    }
    else if (rezType == 2)
    {
        arrPortalFlashWidths = arrPortalFlashWidths1610;
        arrPortalFlashHeights = arrPortalFlashHeights1610;
    }
    else
    {
        arrPortalFlashWidths = arrPortalFlashWidths169;
        arrPortalFlashHeights = arrPortalFlashHeights169;
    }
    document.body.style.margin = "0px";
    var clientWidth = getWindowWidth();
    var clientHeight = getWindowHeight();
    //Find the smallest background that is bigger than the browser bounds
    var index = 0;
    while (clientWidth > arrPortalFlashWidths[index] || clientHeight > arrPortalFlashHeights[index])
    {
        if (index == arrPortalFlashWidths.length-1)
            break;                                              //browser rezolution is larger than any background file
        index++;
    }
    var divElement = document.getElementById("container");
    CreateFlash("divPortalFlash", clientWidth, clientHeight, "ContentFiles/AutoSizing/MoranHome_"+arrPortalFlashWidths[index]+"x"+arrPortalFlashHeights[index]+".swf");
}

//1 = 4:3 (1.3 recurring), 2 = 16:10 (1.6), 3 = 16:9 (1.7 recurring)
function GetScreenRezType()
{
    var ratio = (screen.width * 1.0) / screen.height;
    if (ratio < 1.467)
        return 1;
    else if (ratio < 1.689)
        return 2;
    else
        return 3;
}

function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.documentElement.scrollWidth;
           
   return w ? w : 0;
} 

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.documentElement.scrollHeight;
           
   return h ? h : 0;
}