(function($){
    $.fn.extend({
        menu: function(){
            $(this).find("li>ul").each(function(){
                if ($(this).find(".active").length == 0)
                {
                    $(this).hide();
                }
            });
            
            //$(this).find("li>a").not(".active").hover(function(){$(this).css('background-color','#85a6c8');}, function(){$(this).css('background-color','#ebecf5');});
            $(this).find("li>a").not(".active").hover(function(){
                    $(this).css('background-color','#85a6c8');
                }, function(){
                    if ($(this).attr('class') != 'hl')
                    {
                        $(this).css('background-color','#ebecf5');
                    }
                });
            $(this).find("li>ul>li>a").not(".active").hover(function(){$(this).css('background-color','#aac1d9');}, function(){$(this).css('background-color','#ebecf5');});

            $(this).find("li>a").click(function(){
                if ($(this).next().is("ul"))
                {
                    $(this).parent().parent().find('li>a').not(".active").removeAttr('class');
                    $(this).parent().parent().find('li>a').not(".active").css('background-color','#ebecf5');
                    $(this).css('background-color','#85a6c8');
                    $(this).attr('class','hl');
                    $(this).parent().parent().find("li>ul").not($(this).next()).slideUp(200);
                    $(this).next().slideToggle(200);
                    return false;
                }
                else
                {
                    return true;
                }
            });
        }
    });
})(jQuery);
