Menu = new function() {
    var HTMLDocument = null;
    var menuOpened = null;
    var timeout = null;
    var interval = null;

    this.open = function(cellId) {
        if (this.menuOpened != null) {
            if (this.menuOpened == cellId) {
                this.keepOpened(cellId);
                return;
            }
            this.close(this.menuOpened);
        }

        var cell = this.HTMLDocument.getElementById(cellId);
        var subMenu = this.HTMLDocument.getElementById("subMenu" + cellId);
        if (subMenu != null) {
            var marginW = this.HTMLDocument.body.getAttribute("topmargin");
            var marginH = this.HTMLDocument.body.getAttribute("leftmargin");

            var cellX = 0;
            var cellY = 0;
            if (cell.offsetParent) {
                cellX = cell.offsetLeft;
                cellY = cell.offsetTop;

                var o = cell.offsetParent;
                while (o = o.offsetParent) {
                    cellX += o.offsetLeft;
                    cellY += o.offsetTop;
                }
            }
            var properties = new Array (
                cellX,
                cellY,
                cell.clientWidth,
                cell.clientHeight
            );
            subMenu.style.top  = properties[1] + properties[3] + parseInt(marginH) + 7;
            subMenu.style.left = properties[0];

            if (subMenu.style.display == "" || subMenu.style.display == "none") {
                this.menuOpened = cell.id;
                subMenu.style.zIndex = 9;
                subMenu.style.opacity = 0.00;
                subMenu.style.display = "block";
                this.interval = window.setInterval("Menu.visualEffect(Menu.menuOpened);",10);
            }
        }
    };
    this.close = function(cellId) {
        if (cellId == null) cellId = this.menuOpened;

        var subMenu = this.HTMLDocument.getElementById("subMenu" + cellId);
        if (subMenu != null) {
            subMenu.style.display = "none";
            window.clearInterval(this.interval);
            window.clearTimeout(this.timeout);
            this.menuOpened = null;
        }
    };
    this.timeredClosing = function(cellId) {
        this.timeout = window.setTimeout("Menu.close('" + cellId + "');",1000);
    };
    this.keepOpened = function(cellId) {
        window.clearTimeout(this.timeout);
    };
    this.visualEffect = function(cellId) {
        var subMenu = this.HTMLDocument.getElementById("subMenu" + cellId);
        subMenu.style.opacity = parseFloat(subMenu.style.opacity) + 0.05;
        if (subMenu.style.opacity == 1.00)
            window.clearInterval(this.interval);
    };
}

Menu.HTMLDocument = document;
