function initMenus() {
    $('ul.menu ul').hide();
    $.each($('ul.menu'), function () {
        var cookie = $.cookie(this.id);

        if (cookie === null || String(cookie).length < 1) {
            $('#' + this.id + '.expandfirst ul:first').show();
        }
        else {
            $('#' + this.id + ' .' + cookie).next().show();
        }
    });


    //Adding the event receiver on click
    $('ul.menu li a').bind("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);
                    $.cookie(parent, this.className, { path: "/" });
                }
                $(this).next().delay(500).slideToggle("slow");
            }
        }

        if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            if ($('#' + parent).hasClass('collapsible')) {
                $('#' + parent + ' ul:visible').delay(300).slideUp("slow");
            }
            //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);
                $.cookie(parent, this.className, { path: "/" });
            }
            checkElement.delay(500).slideDown("slow");
            //return false;
        }
    }
    );

//    $("a.headerLink").click(function () {       
//        //Hide the sub category links if they are visible.
//        $('ul.subCategoryLinks:visible').slideUp('normal');

//        //Clear the cache if other item is clicked
//        $.each($('ul.menu'), function () {
//            var cookie = $.cookie(this.id, null);
//        });
//    });
}

$(document).ready(function () {
    initMenus();

});
