
// disables CSS workings of the menu and make it JS-based for a more smooth experience
$opened = undefined;
function initMenu() {
    if ($('nav')) {
        $openCloseDelay = 300;
        // make it JS-based
        $$('li.level_2').each(function($item) {
            if ($item.down('ul.level_3')) {
                if ($item.down('ul.level_3').getStyle('visibility') == 'hidden') {
                    // hide 'em
                    $item.down('ul.level_3').hide();
                } else {
                    // it's the opened one - somebody is hovering of this item
                    $opened = $item;
                }
                // make visible
                $item.down('ul.level_3').setStyle({
                    visibility: 'visible'
                });
                // add functions to show and hide sub
                $item.showSub = function($quick) {
                    if ($quick == true) {
                        this.down('ul.level_3').show();
                    } else {
                        Effect.BlindDown(this.down('ul.level_3'), { duration: 0.1 });
                    }
                    $opened = this;
                };
                $item.hideSub = function($quick) {
                    if ($quick == true) {
                        this.down('ul.level_3').hide();
                    } else {
                        Effect.BlindUp(this.down('ul.level_3'), { duration: 0.1 });
                    }
                    $opened = undefined;
                };
                // add roll over
                $item.on('mouseover', function($event, $element) {
                    if ($opened != this) {
                        this.delayShow = setTimeout(function() {
                            $item.showSub();
                        }, $openCloseDelay);
                    }
                    if (this.delayHide) {
                        clearTimeout(this.delayHide);
                        this.delayHide = undefined;
                    }
                });
                // add roll out
                $item.on('mouseout', function($event, $element) {
                    this.delayHide = setTimeout(function() {
                        $item.hideSub();
                    }, $openCloseDelay);
                    if (this.delayShow) {
                        clearTimeout(this.delayShow);
                        this.delayShow = undefined;
                    }
                });
            }
        });
        // disable CSS workings
        $('nav').removeClassName('css');
    }
}


