﻿function NavMenuIsTopLevel(p) {
    return (p.parent().attr('id') == 'menu');
}

function NavMenuSetNormal(x) {
    x.css("color", "#666666");
    x.css("font-weight", "normal");
    x.show();
    if (!NavMenuIsTopLevel(x))
        x.css("list-style-image", "url('/images/navi_bullet.gif')");
}

function NavMenuFixSiblings(l) {
    NavMenuSetNormal(l.prevAll());
    NavMenuSetNormal(l.nextAll());
    l.show();
    if (!NavMenuIsTopLevel(l)) {
        l.css("list-style-image", "url('/images/navi_bullet_open.gif')");
        l.css("vertical-align", "top");
        l.find('li:first').css('margin-top', '10px');
        if (l.find(">ul>li").length > 0) {
            l.css('padding-bottom', '0px');
            l.css("font-weight", "bold");
        }
    }
}

function NavMenu(menuItemId) {
    $("#menu").show();
    $("#menu li li").hide(); // hide all sub items

    // find current item, expand sub nodes and all li items up to top menu
    var rid = menuItemId; 
    if (rid != '') {
        var p = $("#" + rid);
        var topElement = p;
        NavMenuSetNormal(p.find(">ul>li"));
        NavMenuFixSiblings(p);
        p.parentsUntil('#menu').each(function (index) {
            if ($(this).is("li")) {
                NavMenuFixSiblings($(this));
                topElement = $(this);
            }
        });
        p.css("color", "#933939");
        p.css("font-weight", "bold");
        p.css("vertical-align", "top");
        if (!NavMenuIsTopLevel(p)) {
            if (p.find(">ul>li").length > 0)
                p.css("list-style-image", "url('/images/navi_bullet_active_open.gif')");
            else
                p.css("list-style-image", "url('/images/navi_bullet_active.gif')");
        }

        topElement.addClass('menuOpen');
        topElement.find('li:first').css('margin-top', '10px');
        topElement.css("font-weight", "bold");

        //animation
        if (p.find(">ul>li").length > 0) {
            p.find(">ul").hide();
            p.find(">ul").show('fade');
        }
    }

    // wire navigation
    $("#menu").find("li").click(function (e) {
        e.stopPropagation();
        var id = $(this).attr('id');
        if (id)
            document.location = "/TypeDef.aspx?mid=" + id;
    });

    $("#menu .navText").hover(
    function (e) {
        e.stopPropagation();
        $(this).css('text-decoration', 'underline');
    },
        function () {
            $(this).css('text-decoration', 'none');
        }
    );
   
}
