window.addEvent('domready', function() {

    var nv = $('nav');
    var curr = nv.getElement('li.current');
    if (curr) {
        show_subitems(curr);
    }
    nv.getChildren('li').addEvent('mouseover',function (e) {
        show_subitems(this,true);
        if (!this.hasClass('current'))
            this.addClass('over');
        //this.getElement('ul').setStyle('display','block');
    });

    nv.getChildren('li').addEvent('mouseleave',function (e) {
        if (!this.hasClass('current')) {
            hide_subitems(this,true);
            this.removeClass('over');
        }
    });

    function show_subitems(top_item,hide_curr)
    {
        if (hide_curr) {
            if (curr) {
                hide_subitems(curr,false);
            }
        }

        var subm = top_item.getElement('ul');
        if (subm)
            subm.setStyle('display','block');
    }

    function hide_subitems(top_item,show_curr)
    {
        if (show_curr) {
            if (curr) {
                show_subitems(curr,false);
            }
        }

        var subm = top_item.getElement('ul');
        if (subm)
            subm.setStyle('display','none');
    }

    var ll = $('login-link');
    if (ll) {
        ll.addEvent('click',function (e) {
            e.stop();
            $('login-box').setStyle('display','block');
        });
    }
});
