﻿/// <reference path="jquery-1.4.2.min.js" />

$(document).ready(function () {
    AdjustSectionMenu();
});

function AdjustSectionMenu() {
    $('li.smc-submenu').each(function (i) {
//        if ($.cookie('submenuMark-' + i)) {
//            $(this).show().prev().children('a').addClass('smc-expanded');
//        } else {
//            $(this).hide().prev().children('a').removeClass('smc-expanded');
//        }

        var submenu = $(this).hide();

        $(submenu).prev().children('a').attr('href', '#' + i).click(function () {
            if ($(submenu).css('display') == 'none') {
                $(submenu).slideDown(200, function () {
                    $(submenu).prev().children('a').addClass('smc-expanded');
                    //cookieSet(i);
                    StretchSideBars();
                });
            } else {
                $(submenu).slideUp(200, function () {
                    $(submenu).prev().children('a').removeClass('smc-expanded');
                    //cookieDel(i);
                    StretchSideBars();
                });
            }
            return true;
        });
    });

    // Раскрываем дерево до текущего раздела
    $('.smc-current').parents('li.smc-submenu').each(function (i) {
        $(this).show().prev().children('a').addClass('smc-expanded').addClass('smc-current');
        //cookieSet(i);
    });

    // Отмечаем состояние разделов
    $('.smc-new').text(' (новый)');
    $('.smc-archive').text(' (архив)');

    StretchSideBars();
}

//function cookieSet(index) {
//    $.cookie('submenuMark-' + index, 'opened', { expires: null, path: '/' });
//}

//function cookieDel(index) {
//    $.cookie('submenuMark-' + index, null, { expires: null, path: '/' });
//}

function RefreshMenu(currentSectionId) {
    $.post(GetLocalePath("/Section/GetMenu/" + currentSectionId), function (result) {
        $("ul#smc-menu").html(result);
        $("ul#smc-menu a.locale").each(function (i) { $(this).attr('href', GetLocalePath($(this).attr('href'))); });
        AdjustSectionMenu();
    });
}
