/*jslint browser: true */
/*global $ */

function start_treeview() {
    $("#example").treeview();
}

function close_search_results_pane() {
    $(".pane .delete").click(function () {
        $(this).parents(".pane").animate({ opacity: 'hide' }, "slow");
    });
}

function hide_examples() {

    // Check for special sections.  Chris Zarate says:
    //
    // Those IDs identify exceptions to the model of using the plural when there
    // are two or more "extra" examples. While those sections do contain more
    // than one extra example, the examples function as a single unit (a list of
    // works cited) and should be referred to in the singular. There isn't a
    // good way to identify these exceptions using jQuery selectors, so it
    // became necessary to hardcode them.
    var allowPlural = ($("div#hb6\\.4\\.3").length + $("div#hb6\\.4\\.7").length) === 0;

    $("div.show_more div.extra").prepend($('<a href="#" class="hideExamples">[–]  Hide extra example</a>'));
    if (allowPlural) {
        $("div.show_more div.extra:has(div.example ~ div.example) a.hideExamples").text('[–]  Hide extra examples');
    }
    
    $("a.hideExamples").click(function (event) {
        $(this).parent().parent().children('a').toggle();
        $(this).parent().toggle();
        event.preventDefault();
    });
    
    $("div.show_more").prepend($('<a href="#" class="showExamples">[+]  Show extra example</a>'));
    if (allowPlural) {
        $("div.show_more:has(div.extra div.example ~ div.example) a.showExamples").text('[+]  Show extra examples');
    }

    $("a.showExamples").click(function (event) {
        $(this).parent().children('div').toggle();
        $(this).toggle();
        event.preventDefault();
    });
    
    $("div.show_more div.extra").hide();
}
