var isMenuVisible = false;
var curMenu = -1;
function MenuClick(event){
    event.stopPropagation();
    var classList = $(this).attr('class').split(' ');
    var curMenuPos = -1;
    var curMenuRegEx = /^menu-item-([0-9]{1,5})$/;
    for (var curClass in classList){
        var matches = classList[curClass].match(curMenuRegEx);
        if(matches){
            curMenuPos=matches[1];
            break;
        }
    }
    if(curMenuPos == -1 )
        return;
    if((curMenu == curMenuPos) && (isMenuVisible)){        
        $('.dinamic-menu-content').hide();
        isMenuVisible = false;
        return;
    }    
    curMenu = curMenuPos;
    $('.dinamic-menu-items .menu-item').removeClass('active');
    $('.dinamic-menu-items .menu-item-'+curMenu).addClass('active');
    $('.dinamic-menu-content').show();
    $('.dinamic-menu-content .menu-content').hide();
    $('.dinamic-menu-content .menu-content-'+curMenu).show();
    isMenuVisible = true;
}
$(document).ready(function(){
    $('.dinamic-menu-items .menu-item').click(MenuClick);
$('body').click(function(){
       $('.dinamic-menu-items .menu-item').removeClass('active');
       $('.dinamic-menu-content .menu-content').hide();
       isMenuVisible = false;
    });
   
    $('.dinamic-menu-content .menu-content').click(function(event){
	event.stopPropagation();
    });
    //$('.dinamic-menu-content .link').hover(function(){$(this).addClass('active');}, function(){$(this).removeClass('active');});
});

