/*
-------------------------------------------------------------------------------
Runni JavaScript
Author: Persoona Oy
Version: 04.05.2009

Copyright (c) 2009 Persoona Oy. All rights reserved.
---------------------------------------------------------------------------- */

function open_popup(url) {
    window.open(url, "Window1", "scrollbars=yes, width=620, height=550");
}

function setBodyClass() {
    // Initialize variable (set the default value)
    var body_class = new Array();

    body_class = document.body.className.split(" ");

    if (body_class.length > 1) {
        body_class.pop();
        body_class = body_class.join();
    } else {
        body_class = document.body.className;
    }

    return body_class;
}

function setBackground() {
    // Initialize variables (set the default values)
    var body_class = new Array();
    var size = "xs-small";

    // Get width of the browser window (browsing area)
    if (typeof(document.compatMode) == "undefined" || document.compatMode == "CSS1Compat") {
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    } else {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }

    // Set the size variable to size of the browser window.
    //
    // Supported screen resolutions are: 
    //  - 1024x768 (xs-small),
    //  - 1280x800 (x-small),
    //  - 1280x1024 (small),
    //  - 1440x900 (medium),
    //  - 1680x1050 (large),
    //  - 1920x1200 (x-large),
    //  - 2560x1600 (xl-large)
    //
    if (width <= 1024 && height <= 768) {
        size = "xs-small";
    } else if (width <= 1280 && height <= 800) { 
        size = "x-small";
    } else if (width <= 1280 && height <= 1024) { 
        size = "small";
    } else if (width <= 1440 && height <= 900) {
        size = "medium";
    } else if (width <= 1680 && height <= 1050) {
        size = "large";
    } else if (width <= 1920 && height <= 1200) {
        size = "x-large";
    } else {
        size = "xl-large";
    }

    // Call setBodyClass()-function in order to set the body_class variable
    body_class = setBodyClass();

    // Detect if user is using Microsoft Internet Explorer and try
    // to workaround setting the class attribute bug.
    // TODO: Remove duplication (DRY)?
    if (/MSIE (5\.5|6|7)/.test(navigator.userAgent)) {
        if (document.body.className !== "") {
            document.body.setAttribute("className", body_class + " " + size);
        } else {
            document.body.setAttribute("className", size);
        }
    } else {
        if (document.body.className !== "") {
            document.body.setAttribute("class", body_class + " " + size);
        } else {
            document.body.setAttribute("class", size);
        }
    }
}

window.onresize = setBackground;
