﻿function initMenu() {
    $('.aaMenu ul').hide();

    if ($(".aaMenu .active").length > 0) {
        var obj = $(".aaMenu .active").parent();
        while (obj.attr("tagName") != "DIV") {
            if (obj.attr("tagName") == "LI") { obj.attr("class", "active"); }
            if (obj.attr("tagName") == "UL") obj.show();
            obj = obj.parent();
        } 
    }

    
    $('.aaMenu li a').click(
    	function () {
    	    if (this.className != "") {
    	        var isinselected, isinclassname;
    	        selectedclass = this.className
    	        //$("ul.aaMenu li ul").slideUp("fast");
    	        jQuery.each($("ul.aaMenu li ul"), function (i, val) {

    	            if (this.tagName == "UL") {
    	                isinselected = false;
    	                isinclassname = this.className;

    	                jQuery.each($("ul." + selectedclass).parents(), function (i, val) {
    	                    if (this.tagName == "UL" && this.className == isinclassname) isinselected = true;
    	                });

    	                if (!isinselected) $("ul." + this.className).slideUp("fast");

    	            }
    	        });
    	        jQuery.each($("ul." + this.className).parents(), function (i, val) {
    	            if (this.tagName == "UL") $("ul." + this.className).slideDown("normal");
    	        });

    	        if ($("ul." + this.className).css("display") == "none") $("ul." + this.className).slideDown("normal");
    	        else $("ul." + this.className).slideUp("fast");
    	    } 
    	}
	)
};
$(document).ready(function () { initMenu(); });





