// JavaScript Document
jQuery.fn.fbdGallery = function(galleryGroup, gallerySequence)
{
    var galleryCount = $("#" + galleryGroup).attr("pagecount");


    if (galleryCount == 1)
    {
        $('.fd-galleryright').hide();
        $('.fd-galleryleft').hide();
    }
    else
    {
        $('.fd-galleryright').show();
        $('.fd-galleryleft').show();

        $('.fd-galleryright').hover(function()
        {
            $(this).addClass('fd-galleryrighthover');
        }, function()
        {
            $(this).removeClass('fd-galleryrighthover');
        });

        $('.fd-galleryright').unbind('click');

        $('.fd-galleryright').bind('click', function()
        {
            gallerySequence++;
            if (gallerySequence > galleryCount) gallerySequence = 1;
            loadGallery(galleryGroup, gallerySequence, galleryCount);
        });

        $('.fd-galleryleft').hover(function()
        {
            $(this).addClass('fd-gallerylefthover');
        }, function()
        {
            $(this).removeClass('fd-gallerylefthover');
        });

        $('.fd-galleryleft').unbind('click');

        $('.fd-galleryleft').bind('click', function()
        {
            gallerySequence--;
            if (gallerySequence < 1) gallerySequence = galleryCount;
            loadGallery(galleryGroup, gallerySequence, galleryCount);
        });
    }

    loadGallery(galleryGroup, gallerySequence, galleryCount);

};

loadGallery = function(galleryGroup, gallerySequence, galleryCount)
{
    $('#GalleryThumbs').empty();

    var gallery;
    if (galleryGroup == "Intro")
        gallery = "gallery.htm #GalleryIntro";
    else
        gallery = galleryGroup + '.htm #' + galleryGroup + "-" + gallerySequence;

    $('<div id="thumbs" />').load(gallery,
            function()
            {
                $(this).hide()
			            .appendTo('#GalleryThumbs')
			            .fadeIn(2000);
                $("a[rel^='prettyPhoto']").prettyPhoto();
            });

    /*
    $('#GalleryInfo').empty();

    var info = galleryGroup + +gallerySequence + '.htm #GalleryInfo';

    $('<div id="info" />').load(info,
    function() {
    $(this).appendTo('#GalleryInfo');
    $('#GalleryInfo').replaceWith($('#GalleryInfo').html());
    });
    */
    $("#GalleryPage").text(gallerySequence + "/" + galleryCount);
};


