function initMenus() {
    $('ul.menu ul').hide();
    $.each($('ul.menu'), function() {
        var cookie = $.cookie(this.id);
        if (cookie == null) {
            $('#' + this.id + ' .m1').addClass('active');
        }
        if (cookie === null || String(cookie).length < 1) {
            $('#' + this.id + '.expandfirst ul:first').show();
        }
        else {
            $('#' + this.id + ' .' + cookie).addClass('active');
            $('#' + this.id + ' .' + cookie).next().show();
        }
    });

    $('ul.menu li a').click(
		function() {


		    var checkElement = $(this).next();
		    var parent = this.parentNode.parentNode.id;

		    if ($('#' + parent).hasClass('noaccordion')) {
		        if ((String(parent).length > 0) && (String(this.className).length > 0)) {
		            if ($(this).next().is(':visible')) {
		                $.cookie(parent, null);
		            }
		            else {
		                $.cookie(parent, this.className);
		            }
		            $(this).next().slideToggle('normal');
		        }
		    }
		    if (!($(this).attr('href') == null)) {
		        window.location = $(this).attr('href')
		        //alert('redirect to: ' + $(this).attr('href'));
		    }
		    if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		        if ($('#' + parent).hasClass('collapsible')) {
		            $('#' + parent + ' ul:visible').slideUp('normal');
		        }
		        return false;
		    }
		    if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		        $('#' + parent + ' ul:visible').slideUp('normal');
		        if ((String(parent).length > 0) && (String(this.className).length > 0)) {
		            $.cookie(parent, this.className);
		        }
		        $("#menu1 li a").removeClass('active');
		        $("." + this.className).addClass('active');
		        checkElement.slideDown('normal');
		        return false;
		    }
		}
	);
}
$(document).ready(function() { initMenus(); });
