function getContainerLeft(obj) {
    var curleft = 0;

    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }

    return curleft;
}

function getContainerTop(obj) {
    var curtop = 0;

    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    } else if (obj.y) {
        curtop += obj.y;
    }

    return curtop;
}

function getMenuTable(container) {
    var tbl = null;

    if (container.hasChildNodes()) {
        // go through each node and add a mouseover
        for (var i = 0; i < container.childNodes.length; i++) {
            if (container.childNodes.item(i).nodeName == 'TABLE') {
                tbl = container.childNodes.item(i);
            }
        }
    }

    return tbl;
}

function getMenuItems(container) {
    var menuItems = new Array();

    if (container.hasChildNodes()) {
        // go through each node and add a mouseover
        for (var i = 0; i < container.childNodes.length; i++) {
            if (container.childNodes.item(i).nodeName == 'TD') {
                menuItems[i] = container.childNodes.item(i);
            }
        }
    }

    return menuItems;
}

function chgItemClass(item, newClass) {
    var status = false;

    if (item.nodeType == 1) {
        if (!document.all && document.getElementById) {
            item.setAttribute('class', newClass);
            status = true;
        } else if (document.all && document.getElementById) {
            item.setAttribute('className', newClass);
            status = true;
        } else if (item.style.className) {
            item.style.className = newClass;
            status = true;
        }
    }

    return status;
}

function showMenu(menuId) {
    var menuElm = null;
    if (!document.all && document.getElementById) {
        menuElm = document.getElementById(menuId);
    } else if (document.all && document.getElementById) {
        menuElm = document.all[menuId];
    }

    if (menuElm.nodeType == 1) {
        menuElm.style.display = 'block';
        menuElm.style.visibility = 'visible';
    }
}

function hideMenu(menuId) {
    var menuElm = null;
    if (!document.all && document.getElementById) {
        menuElm = document.getElementById(menuId);
    } else if (document.all && document.getElementById) {
        menuElm = document.all[menuId];
    }

    if (menuElm.nodeType == 1) {
        menuElm.style.display = 'none';
        menuElm.style.visibility = 'hidden';
    }
}

function init() {
    var ourAttsMenu;
    var ourAttsMenuDiv;
    var aboutMenu;
    var aboutMenuDiv;
    var vertSettMenu;
    var vertSettMenuDiv;
    var legalFaqMenu;
    var legalFaqMenuDiv;
    var hkqKidsMenu;
    var hkqKidsMenuDiv;
    var contactMenu;
    var contactMenuDiv;
    var perInjLiaMenu;
    var perInjLiaMenuDiv;
    var commCorpMenu;
    var commCorpMenuDiv;
    var perLegServMenu;
    var perLegServMenuDiv;

    if (document.getElementById) {
        ourAttsMenu = document.getElementById('ourAttsContainer');
        ourAttsMenuDiv = document.getElementById('ourAttsMenu');
        ourAttsMenu.appendChild(ourAttsMenuDiv);
        ourAttsMenuDiv.style.top = (26 + getContainerTop(ourAttsMenu)) + 'px';
        ourAttsMenuDiv.style.left = (0 + getContainerLeft(ourAttsMenu)) + 'px';
        ourAttsMenuDiv.style.width = 'auto';

        aboutMenu = document.getElementById('aboutContainer');
        aboutMenuDiv = document.getElementById('aboutMenu');
        aboutMenu.appendChild(aboutMenuDiv);
        aboutMenuDiv.style.top = (26 + getContainerTop(aboutMenu)) + 'px';
        aboutMenuDiv.style.left = (5 + getContainerLeft(aboutMenu)) + 'px';
        aboutMenuDiv.style.width = 'auto';

        vertSettMenu = document.getElementById('vertSettContainer');
        vertSettMenuDiv = document.getElementById('vertSettMenu');
        vertSettMenu.appendChild(vertSettMenuDiv);
        vertSettMenuDiv.style.top = (26 + getContainerTop(vertSettMenu)) + 'px';
        vertSettMenuDiv.style.left = (5 + getContainerLeft(vertSettMenu)) + 'px';
        vertSettMenuDiv.style.width = 'auto';

        legalFaqMenu = document.getElementById('legalFaqContainer');
        legalFaqMenuDiv = document.getElementById('legalFaqMenu');
        legalFaqMenu.appendChild(legalFaqMenuDiv);
        legalFaqMenuDiv.style.top = (26 + getContainerTop(legalFaqMenu)) + 'px';
        legalFaqMenuDiv.style.left = (5 + getContainerLeft(legalFaqMenu)) + 'px';
        legalFaqMenuDiv.style.width = 'auto';

        hkqKidsMenu = document.getElementById('hkqKidsContainer');
        hkqKidsMenuDiv = document.getElementById('hkqKidsMenu');
        hkqKidsMenu.appendChild(hkqKidsMenuDiv);
        hkqKidsMenuDiv.style.top = (26 + getContainerTop(hkqKidsMenu)) + 'px';
        hkqKidsMenuDiv.style.left = (5 + getContainerLeft(hkqKidsMenu)) + 'px';
        hkqKidsMenuDiv.style.width = 'auto';

        contactMenu = document.getElementById('contactContainer');
        contactMenuDiv = document.getElementById('contactMenu');
        contactMenu.appendChild(contactMenuDiv);
        contactMenuDiv.style.top = (26 + getContainerTop(contactMenu)) + 'px';
        contactMenuDiv.style.left = (getContainerLeft(contactMenu) - 75) + 'px';
        contactMenuDiv.style.width = 'auto';

        perInjLiaMenu = document.getElementById('perInjLiaContainer');
        perInjLiaMenuDiv = document.getElementById('perInjLiaMenu');
        perInjLiaMenu.appendChild(perInjLiaMenuDiv);
        perInjLiaMenuDiv.style.top = (3 + getContainerTop(perInjLiaMenu)) + 'px';
        perInjLiaMenuDiv.style.left = (206 + getContainerLeft(perInjLiaMenu)) + 'px';
        perInjLiaMenuDiv.style.width = 'auto';

        commCorpMenu = document.getElementById('commCorpContainer');
        commCorpMenuDiv = document.getElementById('commCorpMenu');
        commCorpMenu.appendChild(commCorpMenuDiv);
        commCorpMenuDiv.style.top = (3 + getContainerTop(commCorpMenu)) + 'px';
        commCorpMenuDiv.style.left = (206 + getContainerLeft(commCorpMenu)) + 'px';
        commCorpMenuDiv.style.width = 'auto';

        perLegServMenu = document.getElementById('perLegServContainer');
        perLegServMenuDiv = document.getElementById('perLegServMenu');
        perLegServMenu.appendChild(perLegServMenuDiv);
        perLegServMenuDiv.style.top = (3 + getContainerTop(perLegServMenu)) + 'px';
        perLegServMenuDiv.style.left = (206 + getContainerLeft(perLegServMenu)) + 'px';
        perLegServMenuDiv.style.width = 'auto';


        // get the main table for this ourAttsMenu
        var ourAttsmenuTbl = getMenuTable(ourAttsMenuDiv);
        var ourAttsmenuItems = getMenuItems(ourAttsmenuTbl);

        // get the main table for this aboutMenu
        var aboutmenuTbl = getMenuTable(aboutMenuDiv);
        var aboutmenuItems = getMenuItems(aboutmenuTbl);

        // get the main table for this vertSettMenu
        var vertSettmenuTbl = getMenuTable(vertSettMenuDiv);
        var vertSettmenuItems = getMenuItems(vertSettmenuTbl);

        // get the main table for this legalFaqMenu
        var legalFaqmenuTbl = getMenuTable(legalFaqMenuDiv);
        var legalFaqmenuItems = getMenuItems(legalFaqmenuTbl);

        // get the main table for this hkqKidsMenu
        var hkqKidsmenuTbl = getMenuTable(hkqKidsMenuDiv);
        var hkqKidsmenuItems = getMenuItems(hkqKidsmenuTbl);

        // get the main table for this contactMenu
        var contactmenuTbl = getMenuTable(contactMenuDiv);
        var contactmenuItems = getMenuItems(contactmenuTbl);

        // get the main table for this perInjLiaMenu
        var perInjLiaMenuTbl = getMenuTable(perInjLiaMenuDiv);
        var perInjLiaMenuItems = getMenuItems(perInjLiaMenuTbl);

        // get the main table for this commCorpMenu
        var commCorpMenuTbl = getMenuTable(commCorpMenuDiv);
        var commCorpMenuItems = getMenuItems(commCorpMenuTbl);

        // get the main table for this perLegServMenu
        var perLegServMenuTbl = getMenuTable(perLegServMenuDiv);
        var perLegServMenuItems = getMenuItems(perLegServMenuTbl);
    }
}

if (window.addEventListener) {
    window.addEventListener('load', init, false);
} else if (window.attachEvent) {
    window.attachEvent('onload', init);
} else {
    window.onload = init;
}