﻿//Write the style to make the main table's position absolute
document.write("<style type=\"text/css\">" +
                   "#Table_02 {" +
                       "position: absolute;" +
                       "top: 0px;" +
                       "left: " + Math.round((screen.availWidth - 770) / 2) + "px;" +
                   "}" +
                   "#Table_01 {" +
                       "position: absolute;" +
                       "top: 149px;" +
                       "left: " + Math.round((screen.availWidth - 770) / 2) + "px;" +
                       "/*height: 450px;*/" +
                   "}" +
               "</style>");

var interval = new Array(2), curMenu = null;

//Shows a menu
function showMenu(menuId, x, maxWidth, maxHeight) {
    curMenu = menuId;

    if (document.getElementById(menuId).style.visibility != "visible") {
        document.getElementById(menuId).style.height = "0px";
        document.getElementById(menuId).style.width = "0px";
        document.getElementById(menuId).style.left = x;
        document.getElementById(menuId).style.visibility = "visible";

        interval[getIntervalIndex(menuId)] = setInterval("animateMenu(\"" + menuId + "\", " + maxWidth + ", " + maxHeight + ")", 40);
    }
}

function animateMenu(menuId, maxWidth, maxHeight) {
    var i = document.getElementById(menuId).style.width.indexOf("px");
    var w = Number(document.getElementById(menuId).style.width.substring(0, i));
    var wr = maxWidth / 7;
    i = document.getElementById(menuId).style.height.indexOf("px");
    var h = Number(document.getElementById(menuId).style.height.substring(0, i));
    var hr = maxHeight / 7;

    if (w+wr < maxWidth && h+hr < maxHeight) {
        document.getElementById(menuId).style.width = (w+wr) + "px";
        document.getElementById(menuId).style.height = (h+hr) + "px";
        //alert(document.getElementById(menuId).style.height + "\n" + document.getElementById(menuId).style.width);
    }
    else {
        clearInterval(interval[getIntervalIndex(menuId)]);
        if (menuId == curMenu) {
            document.getElementById(menuId).style.width = maxWidth + "px";
            document.getElementById(menuId).style.height = maxHeight + "px";
            document.getElementById(menuId+"Inner").style.display = "block";
        }
    }
}

//Hides a menu
function hideMenu(menuId) {
    if (menuId != curMenu) {
        clearInterval(interval[getIntervalIndex(menuId)]);
        document.getElementById(menuId+"Inner").style.display = "none";
        document.getElementById(menuId).style.visibility = "hidden";
    }
}

function getIntervalIndex(menuId) {
    switch (menuId) {
        case "company":
            return 0;
            break;
        case "solutions":
            return 1;
            break;
    }
}