var MenuNav = function() {
    var root;
    function dd(menuId) {
        this.root = menuId;
    }
    dd.prototype.init = function() {
        initMenu(this.root);
    }
    function initMenu(p) {
        assembleMenu(document.getElementById(p));
    }

    function assembleMenu(uLParentNode) {
        var theUL = uLParentNode.getElementsByTagName("ul")[0];
        var theULChilds = theUL.childNodes;

        for (var i = 0; i < theULChilds.length; i++) {
            if (theULChilds[i].tagName == "LI") {
                var theLINode = theULChilds[i];
                if (hasNextLevelMenu(theLINode)) {
                    setMouseActions(theLINode);
                    theLINode.firstChild.className = uLParentNode.tagName == "DIV" ? "downMenu" : "rightMenu";

                    assembleMenu(theLINode);
                }
            }
        }

        function hasNextLevelMenu(node) {
            return node.getElementsByTagName("ul").length > 0;
        }

        function setMouseActions(node) {
            node.onmouseover = function() {
                this.getElementsByTagName("ul")[0].style.display = "block";
                this.firstChild.style.color = "#FFF";
            };

            node.onmouseout = function() {
                this.getElementsByTagName("ul")[0].style.display = "none";
                if (this.className == "active")
                    this.firstChild.style.color = "#FFF";
                else {
                    this.firstChild.style.color = "#cccc99";
                }
            };
        }
    }
    return { dd: dd }
} ();


