﻿var swapImage = function(src, caption) {
    $("#imgMain").attr({"src": src});
    $("#caption").text(caption);
}
$(document).ready(function() {
    //Set initial image
    $firstimg = $(".thumb:first");
    if ($firstimg.length) {
        swapImage($firstimg.attr("href"), $firstimg.find("img:eq(0)").attr("alt"));
    }
    $("#btn-slide").click(function() {
        $button = $(this);
        $panel = $("#panel");
        $panel
            .slideToggle("slow")
            .queue(function() {
                $button
                    .text($button.text() == "Show Text [+]" ? "Hide Text [-]" : "Show Text [+]");
                $panel.dequeue();
            });
        return false;
    });
    $(".thumb").click(function() {
        /*$thumb = $(this);
        $("#panel")
        .slideUp("slow")
        .queue(function() {
        $("#btn-slide").text("Show Text [+]");
        $(this).dequeue();
        })
        .queue(function() {
        swapImage($thumb.attr("href"), $thumb.find("img:eq(0)").attr("alt"));
        $(this).dequeue();
        });*/
        $thumb = $(this);
        swapImage($thumb.attr("href"), $thumb.find("img:eq(0)").attr("alt"));
        return false;
    });
});