function menuClass(){
    this.data = null;
    this.container = null;
    this.openBranch = "-1";
    this.hideTimer = null;
    this.rootOffsetLeft = 1;
    this.rootOffsetTop = -2;
    this.childOffsetLeft = 1;
    this.childOffsetTop = -2;
    this.drawGorMenu = function(){
        var table = this.container.appendChild(document.createElement("TABLE"));
        this.appendClass(table, "mrTable");
        table.cellPadding = 0;
        table.cellSpacing = 1;
        var td, data, i, a;
        var tr = table.appendChild(document.createElement("TBODY")).appendChild(document.createElement("TR"));
        data = this.findChilds(-1);
        for (i in data){
            td = tr.appendChild(document.createElement("TD"));
            td.noWrap = true;
            this.appendClass(td, "mrMenu");
            a = td.appendChild(document.createElement("A"));
            a.appendChild(document.createTextNode(data[i].text));
            a.href = data[i].url;
            td.url = data[i].url;
            td.onclick = function (){window.location = this.url;}
            //td.tabIndex = 1;
            td.noWrap = true;
            var childs = this.findChilds(i);
            data[i].haveCHilds = false;
            if (childs.length > 0){
                this.appendClass(td, "mrChild");
                this.data[i].haveChilds = true;
                td.childObj = this.drawChilds(childs, td, "left", "bottom", this.rootOffsetLeft, this.rootOffsetTop);
                this.data[i].table = td.childObj;
            }
            this.data[i].owner = td;
            a.nodeID = i;
            a.menuObj = this;
            a.onmouseover = this.showChild;
            a.onfocus = this.showChild;
            a.onkeydown = this.keyDownGor;
            a.onmouseout = this.outBranch;
            a.onblur = this.outBranch;
        }
    }
    this.drawChilds = function (data, container, gorPos, vertPos, offsetLeft, offsetTop){
        var table = this.container.appendChild(document.createElement("TABLE"));
        this.appendClass(table, "mcTable");
        table.style.position = "absolute";
        if (gorPos == "right") table.style.left = this.countOffsetLeft(container) + container.offsetWidth + offsetLeft;
        else table.style.left = this.countOffsetLeft(container) + offsetLeft;
        if (vertPos == "bottom") table.style.top = this.countOffsetTop(container) + container.offsetHeight + offsetTop;
        else table.style.top = this.countOffsetTop(container) + offsetTop;
        table.cellPadding = 0;
        table.cellSpacing = 0;
        var td, tr, childs, i, a;
        var tbody = table.appendChild(document.createElement("TBODY"));
        for (i in data){
            tr = tbody.appendChild(document.createElement("TR"));
            td = tr.appendChild(document.createElement("TD"));
            td.noWrap = true;
            this.appendClass(td, "mcMenu");
            a = td.appendChild(document.createElement("A"));
            a.appendChild(document.createTextNode(data[i].text));
            a.href = data[i].url;
            td.url = data[i].url;
            //td.tabIndex = 1;
            td.noWrap = true;
            td.onclick = function (){window.location = this.url;}
            childs = this.findChilds(i);
            data[i].haveCHilds = false;
            if (childs.length > 0){
                this.appendClass(td, "mcChild");
                this.data[i].haveChilds = true;
                td.childObj = this.drawChilds(childs, td, "right", "top", this.childOffsetLeft, this.childOffsetTop);
                this.data[i].table = td.childObj;
            }
            this.data[i].owner = td;
            a.nodeID = i;
            a.menuObj = this;
            a.onmouseover = this.showChild;
            a.onfocus = this.showChild;
            a.onkeydown = this.keyDown;
            a.onmouseout = this.outBranch;
            a.onblur = this.outBranch;
        }
        table.style.visibility = "hidden";
        return table;
    }
    this.findChilds = function (nodeID){
        var childs = new Array();
        var i;
        for (i in this.data){
            if (this.data[i].parent == nodeID)
                childs[i] = this.data[i];
        }
        return childs;
    }
    this.showChild = function (){
        window.clearTimeout(this.menuObj.hideTimer);
        if (this.menuObj.openBranch.indexOf(this.menuObj.data[this.nodeID].parent) != -1){
            var node;
            var openBranch = this.menuObj.openBranch.split(",");
            while ((node = openBranch.pop())){
                if (node != this.menuObj.data[this.nodeID].parent){
                    this.menuObj.removeClass(this.menuObj.data[node].owner, (this.menuObj.data[node].parent==-1?"mrOver":"mcOver"));
                    if (this.menuObj.data[node].haveChilds){
                        this.menuObj.data[node].table.style.visibility = "hidden";
                    }
                }else{
                    openBranch.push(node);
                    break;
                }
            }
            this.menuObj.openBranch = "" + this.menuObj.implode(openBranch);
        }
        this.menuObj.openBranch += "," + this.nodeID;
        this.menuObj.appendClass(this.parentNode, (this.menuObj.data[this.nodeID].parent==-1?"mrOver":"mcOver"));
        if (this.menuObj.data[this.nodeID].haveChilds){
            if (window.Core) this.parentNode.childObj.style.zIndex= Core.maxZIdex++;
            this.parentNode.childObj.style.visibility = "visible";
        }
    }
    this.keyDown = function (e){
        var evt = e?e:event;
        if (evt.keyCode == 40 && this.parentNode.parentNode.nextSibling){
            this.parentNode.parentNode.nextSibling.firstChild.firstChild.focus();
        }
        if (evt.keyCode == 38 && this.parentNode.parentNode.previousSibling){
            this.parentNode.parentNode.previousSibling.firstChild.firstChild.focus();
        }
        if (evt.keyCode == 39 && this.menuObj.data[this.nodeID].haveChilds){
            this.menuObj.data[this.nodeID].table.firstChild.firstChild.firstChild.firstChild.focus();
        }
        if (evt.keyCode == 37 && this.menuObj.data[this.nodeID].parent != -1){
            this.menuObj.data[this.menuObj.data[this.nodeID].parent].owner.firstChild.focus();
        }else if (evt.keyCode == 37 && this.menuObj.data[this.nodeID].parent == -1){
            this.blur();
        }

        if (evt.keyCode == 13){
            this.click();
        }
        return false;
    }
    this.keyDownGor = function (){
        if (event.keyCode == 39 && this.parentNode.nextSibling){
            this.parentNode.nextSibling.firstChild.focus();
        }
        if (event.keyCode == 37 && this.parentNode.previousSibling){
            this.parentNode.previousSibling.firstChild.focus();
        }
        if (event.keyCode == 40 && this.menuObj.data[this.nodeID].haveChilds){
            this.menuObj.data[this.nodeID].table.firstChild.firstChild.firstChild.firstChild.focus();
        }
        if (event.keyCode == 38 && this.menuObj.data[this.nodeID].parent != -1){
            this.menuObj.data[this.menuObj.data[this.nodeID].parent].owner.firstChild.focus();
        }else if (event.keyCode == 38 && this.menuObj.data[this.nodeID].parent == -1){
            this.blur();
        }

        if (event.keyCode == 13){
            this.click();
        }
        return false;
    }
    this.outBranch = function (){
        window.status = "";
        window.clearTimeout(this.menuObj.hideTimer);
        this.menuObj.hideTimer = window.setTimeout("window."+this.menuObj.name+".hideBranch()", 1000);
    }
    this.hideBranch = function (){
        var node;
        var openBranch = this.openBranch.split(",");
        while ((node = openBranch.pop())){
            if (node != -1){
                this.removeClass(this.data[node].owner, (this.data[node].parent==-1?"mrOver":"mcOver"));
                if (this.data[node].haveChilds){
                    this.data[node].table.style.visibility = "hidden";
                }
            }else{
                openBranch.push(node);
                break;
            }
        }
        this.openBranch = "" + this.implode(openBranch);
    }
    this.countOffsetLeft = function (obj){
        var offset = 0;
        while (obj.tagName != "BODY"){
            if (obj.tagName != "TR")
            offset += obj.offsetLeft;
            if (obj.style.position == "absolute") break;
            obj = obj.parentNode;
        }
        return offset;
    }
    this.countOffsetTop = function (obj){
        var offset = 0;
        while (obj.tagName != "BODY" /*&& obj.style.position != "absolute"*/){
            if (obj.tagName != "TR")
            offset += obj.offsetTop;
            if (obj.style.position == "absolute") break;
            obj = obj.parentNode;
        }
        return offset;
    }
    this.implode = function (array){
        var result = "", i;
        if (array.length > 1){
            for (i in array)
                result += array[i] + ",";
            result = result.substr(0, (result.length - 1));
        }else{
            result = array;
        }
        return result;
    }
    this.appendClass = function(obj, CSSclass){
        if (obj.className.indexOf(CSSclass) == -1)
            obj.className += ' ' + CSSclass;
    }
    this.removeClass = function(obj, CSSclass){
        obj.className = obj.className.replace(CSSclass, '');
    }
}
function init(){

        	var ruMData = {
        		 0: {parent: -1, url: "index.htm",                  text: "Автор"},
        		 1: {parent: -1, url: "work.htm",                   text: "Разработки"},
        		 2: {parent:  1, url: "tree.htm",                   text: "Дерево"},
        		 3: {parent:  1, url: "roll.htm",                   text: "Навигатор"},
        		 4: {parent:  1, url: "calendar.htm",               text: "Календарь"},
        		 5: {parent:  1, url: "editor.htm",                 text: "Редактор"},
        		 6: {parent:  1, url: "sGrid.htm",                  text: "Сортировка таблиц"},
        		 7: {parent:  1, url: "configInterface.htm",        text: "Интрефейс"},
        		 8: {parent:  1, url: "menu.htm",                   text: "Меню"},
        		 9: {parent: -1, url: "install.htm",                text: "Инсталяция"},
        		10: {parent:  4, url: "install.htm",                text: "Инсталяция"},
            11: {parent: -1, url: "ajax.htm",                   text: "Ajax"},
            12: {parent: 11, url: "uploadfile.htm",             text: "Загрузка файла"},
            13: {parent: -1, url: "Texts/ModulesInJS/",         text: "jsx"}
        	}

        	var enMData = {
        		 0: {parent: -1, url: "index.htm",           text: "Auhor"},
        		 1: {parent: -1, url: "work.htm",            text: "Development"},
        		 2: {parent:  1, url: "tree.htm",            text: "Tree"},
        		 3: {parent:  1, url: "roll.htm",            text: "Roll"},
        		 4: {parent:  1, url: "calendar.htm",        text: "Calendar"},
        		 5: {parent:  1, url: "editor.htm",          text: "Editor"},
        		 6: {parent:  1, url: "sGrid.htm",           text: "Table Sort"},
        		 7: {parent:  1, url: "configInterface.htm", text: "Interface"},
        		 8: {parent:  1, url: "menu.htm",            text: "Menu"},
        		 9: {parent: -1, url: "install.htm",         text: "Install"},
        		10: {parent:  4, url: "install.htm",         text: "Install"},
            11: {parent: -1, url: "ajax.htm",            text: "Ajax"},
            12: {parent: 11, url: "uploadfile.htm",      text: "Upload file"}
        	}

            window.gorMenu = new menuClass();
            gorMenu.container = document.getElementById("gMenu");
            gorMenu.name = "gorMenu";
            gorMenu.rootOffsetLeft = -1;
            gorMenu.rootOffsetTop = 3;
            gorMenu.childOffsetLeft = -3;
            gorMenu.childOffsetTop = -1;
            gorMenu.data = ruMData;
            gorMenu.drawGorMenu();
}