var timeoutIdArr = [];

function init_popup_menu() {
    var allDivs = document.getElementById("MenuTopTr").getElementsByTagName("DIV");
    for (var i = 0; i < allDivs.length; i++) {
        if (allDivs[i].className == "menuWrapper") {
            var allLinks = allDivs[i].getElementsByTagName("A");
            var max = 10;
            for (var j = 0; j < allLinks.length; j++) {
                if (allLinks[j].parentNode.parentNode.parentNode == allDivs[i]) {
                    if (allLinks[j].offsetWidth > max) max = allLinks[j].offsetWidth;
                }
            }
            allDivs[i].style.width = max + 13 + "px";
            allDivs[i].getElementsByTagName("UL")[0].style.width = "100%";
            if (allDivs[i].parentNode.tagName == "LI") allDivs[i].style.display = "none";
        }
    }
    
    var allCells = document.getElementById("MenuTopTr").cells;
    for (var i = 0; i < allCells.length; i++) {
        if (allCells[i].className.indexOf("MenuTd") != -1 && allCells[i].getElementsByTagName("UL").length) {
            allCells[i].onmouseover = function () {
                if (this.className.indexOf("over") == -1) this.className += " over";
                if (timeoutIdArr[this.id]) {
                    clearTimeout(timeoutIdArr[this.id]);
                    timeoutIdArr[this.id] = null;
                }
                if (this.className.indexOf("activeMenu") != -1) {
                    this.getElementsByTagName("DIV")[1].style.left = "-2px";
                } else {
                    this.getElementsByTagName("DIV")[1].style.left = "0px";
                }
                this.getElementsByTagName("DIV")[1].style.display = "block";
            }
            allCells[i].onmouseout = function () {
                timeoutIdArr[this.id] = setTimeout("document.getElementById('" + this.id + "').getElementsByTagName('DIV')[1].style.display = 'none'; document.getElementById('" + this.id + "').className = document.getElementById('" + this.id + "').className.replace(' over','');",100);
            }
        }
        if (allCells[i].className.indexOf("MenuTd") != -1 && !allCells[i].getElementsByTagName("UL").length) {
            allCells[i].onmouseover = function () {
                if (this.className.indexOf("over") == -1) this.className += " over";
            }
            allCells[i].onmouseout = function () {
                timeoutIdArr[this.id] = setTimeout("document.getElementById('" + this.id + "').className = document.getElementById('" + this.id + "').className.replace(' over','');",100);
            }
        }
    }
    
    var allEls = document.getElementById("MenuTopTr").getElementsByTagName("LI");
    for (var i = 0; i < allEls.length; i++) {
        if (allEls[i].getElementsByTagName("DIV").length) {
            allEls[i].onmouseover = function () {
                if (timeoutIdArr[this.id]) {
                    clearTimeout(timeoutIdArr[this.id]);
                    timeoutIdArr[this.id] = null;
                }
                var tempDIV = this.getElementsByTagName("DIV")[0];
                tempDIV.style.left = this.offsetWidth - 1 + 'px';
                tempDIV.style.top = this.offsetTop + 'px';
                tempDIV.style.display = "block";
            }
            allEls[i].onmouseout = function () {
                timeoutIdArr[this.id] = setTimeout("document.getElementById('" + this.id + "').getElementsByTagName('DIV')[0].style.display = 'none';",100);
            }
        }
    }
}