﻿/// <reference path="../jquery-1.3.x.min.js"/>
$(document).ready(function() {// alter menus to macth folder structure
    if (typeof mMenuTreeAr == 'undefined') { return; }
    // find url and macth  - works on all pages, but has unsolved problem with dupes in side menu and top menu
    // search crawlers will not find these links, but the sitemap solves that

    var matches = findURLinMenu(mMenuTreeAr);
    if (matches.length < 2) { return; }

    if (matches[1].Hide) { return; }

    //the second element has collection of siblings
    var visAR = $.grep(matches[1].SubF, function(sibling, i) {
        return !sibling.Hide;
    });

    if (visAR.length < 1) { return; }

    // top menu
    var foldertitle = matches[1].Title;
    $("#sidebarTitle").text(foldertitle);
    $('#topnav li').each(function(i, tab) {
        if ($(tab).text() == foldertitle) {
            $(tab).addClass('active');
            return false;
        }
    });


    // rewrite side menu
    var $ul = $('#sidemenu ul');
    var $li = $ul.find('li');
    var $t = $($li.get(0)).clone();
    $ul.children('li').remove();

    $.each(visAR, function(i, sibling) {
        var $newli = $t.clone();
        $newli.find('span:last').text(sibling.Title);
        $newli.find('a').attr('href', sibling.URL);
        $ul.append($newli);
    });


});
