/**********************************************************************************
     TMCS - ensure the currently opened menu is the first item in the menu list
***********************************************************************************/
$(function() {
    var sidemenu = $(".sidebar > ul") ; 
    var menuitems = sidemenu.children('li');  
    $.each(menuitems, function(index, element) {
        if ($(element).hasClass('current') || $(element).hasClass('ancestor')) {
            // this element to be first in list
            element.customOrder = 0;
        } else {
            // leave other items in their natural order
            element.customOrder = index + 1;
        }
    }); 
    // sort by customOrder & apply the sorted items back to their list        
    menuitems.sort(function(a, b) {return (a.customOrder - b.customOrder); });
    $.each(menuitems, function(index, element) { sidemenu.append(element); });
});
