var CURRENT_THEME = '';
var STYLE_SHEETS = Array()
var WIN_WIDTH = getWinWidth();
var WIN_HEIGHT = getWinHeight();
var WIN_HEADER = 110;
var WIN_MARGIN = 10;
var THEMES = Array('00', '02', '03', '06', '08', '09', '10', '11');
init_addStyleSheets();
function init_addStyleSheets() {
    var insertPoint = document.getElementsByTagName('head')[0];
    styleSheet = document.createElement('link');
    styleSheet.rel = 'stylesheet';
    styleSheet.type = 'text/css';
    styleSheet.href = 'Styles/common/style.css';
    insertPoint.appendChild(styleSheet);


    for (i in THEMES) {
        styleSheetFolder = 'style_' + THEMES[i];
        styleSheet = document.createElement('link');
        styleSheet.rel = 'stylesheet';
        styleSheet.type = 'text/css';
        styleSheet.href = 'Styles/' + styleSheetFolder + '/style.css';
        styleSheet.title = styleSheetFolder;
        styleSheet.disabled = true;
        insertPoint.appendChild(styleSheet);
        STYLE_SHEETS.push(styleSheet);
    }
}
function changeTheme(newTheme) {
    if (newTheme == CURRENT_THEME) { return; }
    for (var i = 0; i < STYLE_SHEETS.length; i++) {
        styleSheet = STYLE_SHEETS[i];
        if (styleSheet.title == newTheme) {
            styleSheet.disabled = false;
            CURRENT_THEME = newTheme;
        } else {
            styleSheet.disabled = true;
        }
    }
    setBackgroundImage();
}
function setBackgroundImage() {
    var wrapperTable = document.getElementById("wrapperTable");
    var wrapperFrame = document.getElementById("wrapperFrame");
    var wrapperLeft = document.getElementById("wrapperLeft");
    var wrapperRight = document.getElementById("wrapperRight");
    var wrapperHeader = document.getElementById("wrapperHeader");
    
    if (null == wrapperTable) { return; }
    var SCREEN_WIDTHS = new Array(800, 1024, 1152, 1280, 1440, 1680, 1920);
    WIN_WIDTH = getWinWidth();
    ('' == CURRENT_THEME) ? current_theme = 'style_00' : current_theme = CURRENT_THEME; //DUMB IE
    var bgImg = false;
    for (var i = 0; i < SCREEN_WIDTHS.length; i++) {
        if (WIN_WIDTH == SCREEN_WIDTHS[i]) {
            bgImg = 'Styles/' + current_theme + '/background_' + SCREEN_WIDTHS[i] + '.jpg';
            wrapperTable.style.backgroundImage = "url('" + bgImg + "')";
            wrapperFrame.style.height = (WIN_HEIGHT - WIN_HEADER) + "px";
            wrapperFrame.style.left = WIN_MARGIN + "px";
            wrapperFrame.style.width = (WIN_WIDTH - 2 * WIN_MARGIN) + "px";
            return;
        }
    }
    if (false == bgImg) {
        for (var i = 0; i < SCREEN_WIDTHS.length; i++) {
            if (SCREEN_WIDTHS[i] > WIN_WIDTH) {
                bgImg = 'Styles/' + current_theme + '/background_' + SCREEN_WIDTHS[i] + '.jpg';
                wrapperTable.style.backgroundImage = "url('" + bgImg + "')";
                wrapperFrame.style.height = (WIN_HEIGHT - WIN_HEADER) + "px";
                wrapperFrame.style.left = WIN_MARGIN + "px";
                wrapperFrame.style.width = (WIN_WIDTH - 2 * WIN_MARGIN) + "px";
                return;
            }
        }
    }
    bgImg = 'Styles/' + current_theme + '/background_1024.jpg';
    wrapperTable.style.backgroundImage = "url('" + bgImg + "')";
    wrapperFrame.style.height = (WIN_HEIGHT - WIN_HEADER) + "px";
    wrapperFrame.style.left = WIN_MARGIN + "px";
    wrapperFrame.style.width = (WIN_WIDTH - 2 * WIN_MARGIN) + "px";

}
function setWidth(newWidth) {
    if (null == newWidth) {
        WIN_WIDTH = getWinWidth();
        return;
    }
    WIN_WIDTH = newWidth;
}
function getWinWidth() {
    var winW = window.innerWidth;
    if (undefined == winW) { winW = document.documentElement.clientWidth; }
    if (undefined == winW) { winW = document.body.offsetWidth; }
    if (undefined == winW) { winW = document.getElementsByTagName('body')[0].clientWidth; }
    if (undefined == winW) { winW = screen.width; }
    return winW;
}
function getWinHeight() {
    var winW = window.innerHeight;
    if (undefined == winW) { winW = document.documentElement.clientHeight; }
    if (undefined == winW) { winW = document.body.offsetHeight; }
    if (undefined == winW) { winW = document.getElementsByTagName('body')[0].clientHeight; }
    if (undefined == winW) { winW = screen.height; }
    return winW;
}