var exhibitionImagesIds = new Array();

$(document).ready(function(){
    $("#exhibitionImageLeftArrow").click(function() {
        getPreviousExhibitionImage();
    });
    $("#exhibitionImageRightArrow").click(function() {
        getNextExhibitionImage();
    });

    try {
        getFirstExhibitionImage();
    } catch(e) {}
});

function getFirstExhibitionImage() {
    var exhibition_global_id = $("#exhibition_global_id").attr("exhibition_global_id");
    $.ajax({
        type: "POST",
        url: "ajax/getFirstExhibitionImage.php",
        data: "exhibition_global_id="+exhibition_global_id,
        dataType:"json",
        success: function(data){
            if(data.result==false) {
                $(".slideshowClass").hide();
            } else {
                $("#exhibitionImageTd").css("background-image","url('"+data.result.exhibition_photo_folder+data.result.exhibition_photo_filename+"')");
                $("#exhibitionImageTd").css("background-repeat","no-repeat");
                exhibitionImagesIds.push(data.result.exhibition_photo_sort+"#"+data.result.exhibition_photo_folder+data.result.exhibition_photo_filename);
            }
        }
    });
}


function getPreviousExhibitionImage() {
    if(exhibitionImagesIds.length==1);
    else {
        exhibitionImagesIds.pop();
        if(exhibitionImagesIds.length>0) {
            var data = exhibitionImagesIds[exhibitionImagesIds.length-1];data = data.split("#");
            $("#exhibitionImageTd").css("background-image","url('"+data[1]+"')");
        }
    }
}

function getNextExhibitionImage() {
    document.body.style.cursor = "wait";
    var exhibition_global_id = $("#exhibition_global_id").attr("exhibition_global_id");
    var data = exhibitionImagesIds[exhibitionImagesIds.length-1];data = data.split("#");
    $.ajax({
        type: "POST",
        url: "ajax/getNextExhibitionImage.php",
        data: "exhibition_global_id="+exhibition_global_id+"&lastSort="+data[0],
        dataType:"json",
        success: function(data){
            document.body.style.cursor = "default";
            if(data.result!=false) {
                $("#exhibitionImageTd").css("background-image","url('"+data.result.exhibition_photo_folder+data.result.exhibition_photo_filename+"')");
                exhibitionImagesIds.push(data.result.exhibition_photo_sort+"#"+data.result.exhibition_photo_folder+data.result.exhibition_photo_filename);
            }
        }
    });
}
