﻿function ShowMenuItem(mainMenuItemId, menuItemId) {
    if (mainMenuItemId != null) {
        $('#' + mainMenuItemId).removeClass('collapsed').addClass('expanded').next().show();
    }
    if (menuItemId != null) {
        $('#' + menuItemId).removeClass('disactiveLink').addClass('activeLink');
    }
}

$(document).ready(function() {
    $('#main-menu span.main-menu-text').each(function(i) { // Check each submenu:
        $(this).click(function() { // Attach an event listener
            var $item = $(this).next();
            var this_i = $('#main-menu span.main-menu-text').index($(this)); // The index of the submenu of the clicked link
            if ($item.css('display') == 'none') {

                // When opening one submenu, we hide all same level submenus:
                $('#main-menu span.main-menu-text').each(function(j, item) {
                    if (j != this_i) {
                        $(this).removeClass('expanded').addClass('collapsed');
                        $(this).next().slideUp(200, function() { });
                    }
                });
                // :end

                $item.slideDown(200, function() { // Show submenu:
                    $(this).prev().removeClass('collapsed').addClass('expanded');
                });
            } else {
                $item.slideUp(200, function() { // Hide submenu:
                    $(this).prev().removeClass('expanded').addClass('collapsed');
                });
            }
        });
    });
});
function cookieLinkSet(index) {
    $.cookie('link-' + index, 'opened', { expires: null, path: '/' }); // Set mark to cookie (submenu is shown):
}
function cookieLinkDel(index) {
    $.cookie('link-' + index, null, { expires: null, path: '/' }); // Delete mark from cookie (submenu is hidden):
}
function cookieSet(index) {
    $.cookie('submenuMark-' + index, 'opened', { expires: null, path: '/' }); // Set mark to cookie (submenu is shown):
}
function cookieDel(index) {
    $.cookie('submenuMark-' + index, null, { expires: null, path: '/' }); // Delete mark from cookie (submenu is hidden):
}
