/* JQuery Scripts */

$(document).ready(function(){
    // Display arrows
    $("div.chapter-menu ul.chap-ul-2").before("<img src='themes/enlist/images/arrow-down.gif' alt='more' class='downexpander' />");
    $("div.chapter-menu ul.js-active").prev("img").attr({ src: "themes/enlist/images/arrow-up.gif", alt: "hide" });
    $("div.chapter-menu ul.js-active").prev("img").removeClass();
    $("div.chapter-menu ul.js-active").prev("img").addClass("upexpander");

    // Hide the subchapters
    $("div.chapter-menu ul li ul:not('.js-active')").hide();

    $("div.chapter-menu ul li img").click(function(){
        $(this).next("ul").slideToggle("fast");
    });
    $("div.chapter-menu ul li img.downexpander").toggle(function() {
        $(this).empty();
        $(this).attr({ src: "themes/enlist/images/arrow-up.gif", alt: "hide" });
    }, function() {
        $(this).empty();
        $(this).attr({ src: "themes/enlist/images/arrow-down.gif", alt: "more" });
    });
    $("div.chapter-menu ul li img.upexpander").toggle(function() {
        $(this).empty();
        $(this).attr({ src: "themes/enlist/images/arrow-down.gif", alt: "more" });
    }, function() {
        $(this).empty();
        $(this).attr({ src: "themes/enlist/images/arrow-up.gif", alt: "hide" });
    });
});
