﻿$(document).ready(function () {
    $('.menuwrapper ul ul').hide();

    $('.menuwrapper .currentJsPage').show();
    $('.menuwrapper .currentJsPage').parent().show();
    $('.menuwrapper .currentJsPage').parent().parent().show();
    $('.menuwrapper .currentJsPage').parent().parent().parent().show();
    $('.menuwrapper .currentJsPage').children('ul').slideDown('slow');

//    if ($('.menuwrapper li').first().hasClass('currentJsPage')) {
//        $('.menuwrapper .menuHead .menulvl-0').next().show();
//    }

    $('.menuwrapper span').click(function () {
        $(this).parent().click();
    });

    $('.menuwrapper .menuHead').click(function () {
        var toogleUl = $(this).children('ul').first();
        var visUl = $('.menuwrapper ul ul:visible');
        visUl.each(function (index) {
            if ($(this).has(toogleUl).length == 0 &&
                $(toogleUl).has(this).length == 0 &&
                toogleUl[0] !== this) {
                $(this).slideToggle('fast');
            }
        });
        $(this).children('ul').first().slideToggle('fast');
        return false;
    });

    $('.menuwrapper li :not(.menuHead)').click(function (e) {
        e.stopImmediatePropagation();
    });
});
