var MenuHandler = new Class({
    initialize: function(elem) {
        this.root = $(elem)
        this._mark(this.root, 1)
        this._affect()
    },
    
    _mark: function(elem, level) {
        var t = this
        elem.getChildren().each(function(dd) {
            dd.getChildren().each(function(item) {
                if (item.getTag() == 'dl') {
                    item.addClass('sublevel-' + level)
                    t._mark(item, level + 1)
                }
            })
        })
    },
    
    _affect: function() {
        this.root.getElements('dd').each(function(dd) {
            // try to get dl
            var dl = dd.getChildren()[1]
            if ($defined(dl)) {
                dd.addEvent('mouseenter', function() {
                    dl.setStyle('display', 'block')
                })
                dd.addEvent('mouseleave', function() {
                    dl.setStyle('display', 'none')
                })
            }
        })
    }
})

window.addEvent('load', function() {
    new Asset.css('/templates/1/css/menu.css')
    
    $$('dl#menuNiv1').each(function(dl) {
        new MenuHandler(dl)
    })

})
