if(document.getElementById) {

function setOwnProps(obj, parent) {
        this.style = obj.style;
        this.sWidth = obj.offsetWidth;
        this.sHeight = obj.offsetHeight;
        this.sTop = obj.offsetTop;
        this.sLeft = obj.offsetLeft;
        this.pHeight = parent.offsetHeight;
}

function twoLevelMenu(navEl, subEl, layout) {
        this.navEl = navEl;
        this.subEl = subEl;
        this.type = (layout == "horizontal")?true:false;
        this.init(layout);
}

twoLevelMenu.prototype.init = function(layout) {
        var t = this;
        setOwnProps.call(this, this.subEl, this.navEl);
        this.isOpen = false;
        this.navEl.className = layout;
        this.navEl.onmouseover = function() { t.showSub(); }
        this.navEl.onmouseout = function() { t.hideSub(); }
        this.setPos(this.getPos(this.type));
}

twoLevelMenu.prototype.getPos = function(b) {
        var x = this.getCoord(this.navEl, "offsetLeft"),
        y = this.getCoord(this.navEl, "offsetTop") + ((b)?this.navEl.offsetHeight:"");
        return { x : x, y : y }
}

twoLevelMenu.prototype.setPos = function(pos) {
        var x = (this.type)?"":this.sWidth, y = (this.type)?this.sHeight:"";
        this.moveTo(pos.x - x, pos.y - y);
}

twoLevelMenu.prototype.getCoord = function(el, prop) {
        var parent = el.offsetParent, coord = el[prop];
        while(parent) { coord += parent[prop]; parent = parent.offsetParent; }
        return coord;
}

twoLevelMenu.prototype.clipTo = function(t, r, b, l) {
        this.style.clip = "rect(" + t + "px," + r + "px," + b + "px," + l + "px)";
}

twoLevelMenu.prototype.moveTo = function(x, y) {
        this.x = Math.floor(x);
        this.y = Math.floor(y);
        this.style.left = this.x + "px";
        this.style.top = this.y + "px";
}

twoLevelMenu.prototype.slideTo = function(step, top) {
        var t = this, stop = this.pHeight + top;
        if(this.type) {
                if(this.isOpen == true) {
                        if(this.y + step <= stop) {
                                this.clipTo(stop  - this.y - step, this.sWidth, this.sHeight, 0);
                                this.moveTo(this.x, this.y + step);
                                setTimeout(function() { t.slideTo(step, top); }, 10);
                        }
                        else {
                                this.moveTo(this.x, stop);
                                this.clipTo(stop - this.y, this.sWidth, this.sHeight, 0);
                        }
                }
                else if(this.y >= -this.sHeight) {
                        this.clipTo(stop - this.y + step, this.sWidth, this.sHeight, 0);
                        this.moveTo(this.x, this.y - step);
                        setTimeout(function() { t.slideTo(step, top); }, 10);
                }
                else return null;
        }
        else {
                if(this.isOpen == true) {
                        if(this.x + step <= this.sWidth) {
                                this.clipTo(0, this.sWidth, this.sHeight, this.sWidth - this.x - step);
                                this.moveTo(this.x + step, this.y);
                                setTimeout(function() { t.slideTo(step, top); }, 10);
                        }
                        else this.clipTo(0, this.sWidth, this.sHeight, 0);
                }
                else if(this.x >= -this.sWidth + 20) {
                        this.clipTo(0, this.sWidth, this.sHeight, this.sWidth - this.x + step);
                        this.moveTo(this.x - step, this.y);
                        setTimeout(function() { t.slideTo(step, top); }, 10);
                }
                else return null;
        }
}

twoLevelMenu.prototype.showSub = function() {
        if(this.hideTimer) clearTimeout(this.hideTimer);
        var offTop = this.getCoord(this.navEl, "offsetTop");
        if(this.isOpen == false && this.subEl.childNodes.length) { this.isOpen = true; this.slideTo(10, offTop); }
        else return false;
}

twoLevelMenu.prototype.hideSub = function() {
        var t = this, offTop = this.getCoord(this.navEl, "offsetTop");
        this.hideTimer = setTimeout(function() {
                if(t.isOpen == true) { t.isOpen = false; t.slideTo(10, offTop); }}, 200);
}

onload = function() {
        var o = new Array, k = -1,
        layout = ["horizontal", "vertical"], // попробовал сделать два варианта для отображения меню
        menu = document.getElementById("menuDDM"),
        navObj = menu.getElementsByTagName("li"),
        menuLen = navObj.length;
        for(var i = 0; i < menuLen; i++) {
                if(navObj[i].parentNode.parentNode == menu) {
                        var subObj = navObj[i].getElementsByTagName("ul")[0];
                        o[k++] = new twoLevelMenu(navObj[i], subObj, layout[0]); // выбран layout[0] - горизонтальное меню
                }
        }
        this.onresize = function() {
                for(var i = 0, obj = null; obj = o[i]; i++) {
                        obj.setPos(obj.getPos(obj["type"]));
                }
        }
}
}