$(function() {
    $(".toggle").click(function(event) {
        event.preventDefault(); $("#hidden").toggle("slow");
    });
    
    $("div.slide").click(function(event) {
        event.preventDefault();
        $("#" + $(this)[0].title).animate({ "height": "toggle", "opacity": "toggle" });

        //also change the image of the toggle button

        if ($(this).find('img')[0].src.match("expand")) {
            $(this).find('img')[0].src = "./images/collapseButton.gif";
        } else {
            $(this).find('img')[0].src = "./images/expandButton.gif";
        }
    });

    $("#expandAll").click(function(event) {
        event.preventDefault();
        $(".hidden").toggle(true);
    
        //also change the image of the toggle button
        var imgs = $(".slide").find("img");

        for (i = 0; i < imgs.length-1; i++) {
            imgs[i].src = "./images/collapseButton.gif";
        }
    });

    $("#collapseAll").click(function(event) {
        event.preventDefault();
        $(".hidden").toggle(false);
       
        //also change the image of the toggle button
        var imgs = $(".slide").find("img");

        for (i = 0; i < imgs.length-1; i++) {
            imgs[i].src = "./images/expandButton.gif";
        }
    });
});

