// fire links with targets on menu to open
$(document).on('click', 'nav a[target="_menu"]', function(e) {
    e.preventDefault();
    $this = $(e.currentTarget);
    window.setTimeout(function() {
        if (!$this.hasClass('menu-opened')) {
            $this.addClass("menu-opened");
            
            $.ajax({
                type : "GET",
                url : $this.attr('href'),
                dataType : 'json',
                cache : false,
                success : function(data) {
                    var html = '';
                    for (var i = 0; i < data.length; i++) {
                        html += '<li><a href="' + data[i].url + '">' + data[i].label + '</a></li>'
                    }
                    $this.next().html(html);
                    return false;
                },
                error : function(xhr, ajaxOptions, thrownError) {
                    $this.next().html('<li><a href=""><i class="fa fa-times-circle"></i> Error</a></li>');
                },
                async : false
            });
            
        } else {
            $this.removeClass("menu-opened");
            $this.next().html('<li><a href="">Loading ...</a></li>');
        }
        
    }, 200);
});

function displayLoader(element)
{
    if (typeof element == 'undefined') {
        element = '#content';
    }
    $(element).html('<h1><i class="fa fa-cog fa-spin"></i> Loading...</h1>');
    
    return true;
}

function switchLoaderFullPage(state)
{
    if (typeof state == 'undefined') {
        state = 'on';
    }
    
    if (state == 'on') {
        $(document).scrollTop(0);
        $('#loader-fullpage').show();
    } else {
        $('#loader-fullpage').hide();
    }
    
    return true;
}

function orchestraAjaxLoad(url, method, successCallback)
{
    displayLoader();
    
    if (typeof method == 'undefined') {
        method = 'POST';
    }
    
    $.ajax({
        url: url,
        type: method,
        success: function(response) {
            if (response.success) {
                window.location.hash = response.data;
            } else {
                $('#content').html(response);
                if (typeof successCallback !== 'undefined') {
                    successCallback();
                }
            }
        }
    });
}

function callAndReload(action)
{
    displayLoader();
    $.post(action, function(response) {
        if (response.success) {
            Backbone.history.navigate('#', true);
            window.location.reload();
        }
    });
}

function displayMenu()
{
    $.ajax({
        url: $('#left-panel nav').data("url"),
        type: 'GET',
        success: function(response) {
            // render menu
            $('#left-panel nav').replaceWith(response);
            
            // activate menu
            $('nav ul').jarvismenu({
                accordion : true,
                speed : $.menu_speed,
                closedSign : '<em class="fa fa-expand-o"></em>',
                openedSign : '<em class="fa fa-collapse-o"></em>'
            });
            
            // tag selected path 
            $('nav li:has(a[href="#node/show/root"])').addClass("active open");

            // open menu ?
        }
    });
}

@@ -2552,24 +2552,85 @@
 layMenu()%0A%7B%0A
+    var selectedPath = %22#%22 + Backbone.history.fragment;%0A    %0A
     $.ajax(%7B
@@ -2856,16 +2856,23 @@
 ctivate 
+jarvis 
 menu%0A   
@@ -2884,31 +2884,19 @@
     
-$('nav ul').jarvismenu(
+var opts = 
 %7B%0A  
@@ -3101,32 +3101,73 @@
 %3E'%0A            %7D
+;%0A            $('nav ul').jarvismenu(opts
 );%0A            %0A
@@ -3238,23 +3238,28 @@
 ef=%22
-#node/show/root
+' + selectedPath + '
 %22%5D)'
@@ -3280,44 +3280,362 @@
 tive
- open%22);%0A%0A            // open menu ?
+%22);%0A            %0A            // open selected path%0A            $('#left-panel nav').find(%22li.active%22).each(function() %7B%0A                $(this).parents(%22ul%22).slideDown(opts.speed);%0A                $(this).parents(%22ul%22).parent(%22li%22).find(%22b:first%22).html(opts.openedSign);%0A                $(this).parents(%22ul%22).parent(%22li%22).addClass(%22open%22)%0A            %7D);
 %0A   

Add menu opening