var j = jQuery.noConflict();

j(document).ready(function() {

    // Collapse all initally expanded submenus except the current section, which is determined by the class name
    j("#primaryNavigation > li > a:not(.stayOpen) + a + ul").css("display", "none");


    // Make the mouse a pointer when hovering over the expand/collapse button and
    // change plus/minus icon according to the collapsed state except the current section, which is determined by the class name "stayOpen"
    j("#primaryNavigation > li:has(ul)").find("a.static:not(.stayOpen)").removeClass("static").addClass("collapsed").addClass("pointer");

    // when onclick event fires, Toggle the selected menu's class and expand or collapse the corresponding menu
    j("#primaryNavigation > li > a.collapsed").click(function() {
    j(this).toggleClass("expanded").toggleClass("collapsed").parent().find("ul").slideToggle(350);
        
        j("#primaryNavigation >li a.pointer").removeClass("expanded").addClass("collapsed");
        j(this).removeClass("collapsed").addClass("expanded");
        j("#primaryNavigation >li > a:not(.stayOpen) + a + ul").css("display", "none");
    });

    // when onclick event fires, Toggle the selected menu's class and expand or collapse the menu
    j("#primaryNavigation > li > a.expanded").click(function() {
        j(this).toggleClass("collapsed").toggleClass("expanded").find("+ a + ul").slideToggle(350);
        j(this).removeClass("expanded").addClass("collapsed");
    });

});

