var success_storyImagesIds = new Array();

$(document).ready(function(){
    $("#success_storyImageLeftArrow").click(function() {
        getPrevioussuccess_storyImage();
    });
    $("#success_storyImageRightArrow").click(function() {
        getNextsuccess_storyImage();
    });

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

function getFirstsuccess_storyImage() {
    var success_story_global_id = $("#success_story_global_id").attr("success_story_global_id");
    $.ajax({
        type: "POST",
        url: "ajax/getFirstsuccess_storyImage.php",
        data: "success_story_global_id="+success_story_global_id,
        dataType:"json",
        success: function(data){
            if(data.result==false) {
                $(".slideshowClass").hide();
            } else {
                $("#success_storyImageTd").css("background-image","url('"+data.result.success_story_photo_folder+data.result.success_story_photo_filename+"')");
                $("#success_storyImageTd").css("background-repeat","no-repeat");
                success_storyImagesIds.push(data.result.success_story_photo_sort+"#"+data.result.success_story_photo_folder+data.result.success_story_photo_filename);
            }
        }
    });
}


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

function getNextsuccess_storyImage() {
    document.body.style.cursor = "wait";
    var success_story_global_id = $("#success_story_global_id").attr("success_story_global_id");
    var data = success_storyImagesIds[success_storyImagesIds.length-1]; data = data.split("#");
    $.ajax({
        type: "POST",
        url: "ajax/getNextsuccess_storyImage.php",
        data: "success_story_global_id="+success_story_global_id+"&lastSort="+data[0],
        dataType:"json",
        success: function(data){
            document.body.style.cursor = "default";
            if(data.result!=false) {
                $("#success_storyImageTd").css("background-image","url('"+data.result.success_story_photo_folder+data.result.success_story_photo_filename+"')");
                success_storyImagesIds.push(data.result.success_story_photo_sort+"#"+data.result.success_story_photo_folder+data.result.success_story_photo_filename);
            }
        }
    });
}
