var dmg3_cats = $ES('.navlist .m-cat-depth-1');
var $_dmg3showHeight = dmg3_cats.length * 34;
window.addEvent('domready', function () {
	var link = $ES('link');
	$('dmg3-style').inject($E('link'), 'before');
    dmg3_cats.each(function (cat, i) {
        var popup = cat.getElement('.dmg3-popup');
        if (popup) {
            cat.addEvents({
                'mouseenter': function () {
                    var mtop = -i * 34, r;
                    if (popup.retrieve('top')) {
                            mtop = popup.retrieve('top');
                            r = true;
                        }
                    popup.setStyles({
                            'display': 'block',
                            'margin-top': mtop
                        });
                    if (!r && i && popup.getSize().y < (i + 1) * 34) {
                            var turetop = mtop + ((i + 1) * 34 - popup.getSize().y);
                            popup.store('top', turetop);
                            popup.setStyle('margin-top', turetop)
                        }
                    this.addClass('current')
                },
                'mouseleave': function () {
                    popup.setStyle('display', 'none');
                    this.removeClass('current');
                }
            })
        }
    })
})
