﻿$(document).ready(function() {
    //var path = '/sites/customnavigation/_layouts/viewlsts.aspx?BaseType=1';
    //var path = '/sites/customnavigation/Gedeelde%20documenten/Forms/AllItems.aspx';
    var path = window.location.pathname;
    $("table#zz2_QuickLaunchMenu > tbody > tr[id]").filter(function() {
        return ($(this).next().attr('id') == "");
    }).click(function(event) {
        if ($(event.target).is("a")) {
            return;
        }
        var found = false;

        $(this).nextAll().filter(function(index) {
            if ($(this).attr('id') != "") {
                found = true;
            }
            return !found;
        }).toggle();

        $(this).find("td").toggleClass('expandable');
    }).mouseover(function() {
        $(this).css('cursor', 'pointer');
    });

    /*ga alle TR's bij langs en controleer welk menu item opengeklikt is*/
    $("table#zz2_QuickLaunchMenu > tbody > tr").filter(function() {
        var selected = false;

        //check of de A overeenkomt met de url
        $(this).find("a[href='" + path + "']").each(function(index) {
            //zet de TD van de A op 'selected'
            $(this).parent().toggleClass('selected');
            selected = true;
        });

        //check of deze TR kinderen bevat zodat hij dichtgeklapt kan worden
        if ($(this).attr('id') != '' && $(this).next().attr('id') == "")
            $(this).addClass('haschildren')

        //klik alleen de TR's aan waarvan de kinderen of hijzelf niet geselecteerd zijn.
        return ($(this).attr('id') != '' && !selected && $(this).next().find("a[href='" + path + "']").attr("href") != path);
    }).click();

    /*stel class in op qicklaunch div voor styling*/
    $("div.ms-quickLaunch").addClass('ExpandableMenu');

});