$(document).ready(
function() {
    // Process each gallery separate.
    $(".accommodation_gallery").each(make_accomodation_gallery);
});

function make_accomodation_gallery()
{
    $(this).find(".gallery_link").lightBox(
    {
        imageLoading: 'images/ImageViewer/loading.gif',
        imageBtnClose: 'images/ImageViewer/close.gif',
        imageBtnPrev: 'images/ImageViewer/prev.gif',
        imageBtnNext: 'images/ImageViewer/next.gif',
        fixedNavigation: true,
        txtOf: 'Of'
    });

    var gallery = $(this);
    var current_photo = 1;
    var total_photos = $(this).find(".gallery_photo").length;

    $(this).find(".previous_photo > a").click(function()
    {
        // Hide current photo
        gallery.find(".image_" + current_photo).css("display", "none");
        // Decrement counter
        current_photo--;

        // Display new photo
        gallery.find(".image_" + current_photo).css("display", "block");

        // Display and hide link
        if (current_photo == 1)
            gallery.find(".previous_photo").css("display", "none");
        gallery.find(".next_photo").css("display", "block");

        return false;
    });

    $(this).find(".next_photo > a").click(function()
    {
        // Hide current photo
        gallery.find(".image_" + current_photo).css("display", "none");
        // Decrement counter
        if(current_photo != total_photos)
            current_photo++;

        // Display new photo
        gallery.find(".image_" + current_photo).css("display", "block");

        // Display and hide link
        if (current_photo == total_photos)
            gallery.find(".next_photo").css("display", "none");
        gallery.find(".previous_photo").css("display", "block");

        return false;
    });
}