document.write('<link rel="stylesheet" href="/css/menu-javascript.css" type="text/css" media="screen"/>');

function showPage( page )
{
    $("li:contains(" + page + ")").addClass( "expand" );
    $(".submenu li:contains(" + page + ")").css( "list-style-type", "disc" );
    $(".submenu li:contains(" + page + ")").css( "font-style", "italic" );
}
function showProject( page )
{
    $("#sub-menu li:contains(" + page + ")").css( "font-style", "italic" );
    // $("#sub-menu li:contains(" + page + ") a").css( "color", "#66a" );
}

jQuery.fn.initMenu = function() {  
    return this.each(function(){
        var theMenu = $(this).get(0);
        $('.acitem', this).hide();
        $('li.expand > .acitem', this).show();
        $('li.expand > .acitem', this).prev().addClass('active');
        $('li a', this).click(
            function(e) {
                e.stopImmediatePropagation();
                var theElement = $(this).next();
                var parent = this.parentNode.parentNode;
                if($(parent).hasClass('noaccordion')) {
                    if(theElement[0] === undefined) {
                        window.location.href = this.href;
                    }
                    $(theElement).slideToggle('normal', function() {
                        if ($(this).is(':visible')) {
                            $(this).prev().addClass('active');
                        }
                        else {
                            $(this).prev().removeClass('active');
                        }    
                    });
                    return false;
                }
                else {
                    if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                        if($(parent).hasClass('collapsible')) {
                            $('.acitem:visible', parent).first().slideUp('normal', 
                            function() {
                                $(this).prev().removeClass('active');
                            }
                        );
                        return false;
                    }
                    return this.href.substr(-1) != "#";
                }
                if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                    $('.acitem:visible', parent).first().slideUp('normal', function() {
                        $(this).prev().removeClass('active');
                    });
                    theElement.slideDown('normal', function() {
                        $(this).prev().addClass('active');
                    });
                    return this.href.substr(-1) != "#";
                }
            }
        }
    );
});
};

$(document).ready(function() {
    $('.topmenu').initMenu(); 
});
