﻿$.elementReady("brand-leftnav", function () {

    $(".lft-nav .root > li > ul").each(function () {

        $(this).toggle();

        $(this).parent().addClass("hasSubMenu");

        $(this).parent().prepend(
            $("<a>").click(function () {

                if ($(this).attr("menustats") == "off") {
                    $(this).attr("menustats", "on");
                } else {
                    $(this).attr("menustats", "off");
                }
                $(this).parent().find("ul").toggle();

            }).addClass("ChildLink").attr("menustats", "on")
        );

        //If the parent item is open. Open the child menu
        if ($(this).parent().hasClass("selected")) {
            $(this).toggle();
            $(this).parent().find(".ChildLink").attr("menustats", "off");
        }

        //If a child is selected. Open the menu
        $(this).find("li.selected").each(function () {
            $(this).parent().show();
            $(this).parent().parent().find(".ChildLink").attr("menustats", "off");
        });

    });

});

$.elementReady("brand-leftnav-meta-filter", function () {

    //Fix the scroll
    $(this).find('div[id*="TreeViewRememberScroll"]').removeAttr("style").removeAttr("onscroll");

    $(this).find('a[title*="Subject"]').text("View Photos by Subject");

    //Click open the subjects
    $(this).find('a[href*="TreeView_PopulateNode"]').each(function () {
        jQuery.globalEval($(this).attr("href"));
    });



});

