Answer to next
question first.
If you load images at once.
Here is the jsFiddle.
If you use ajax, this function should be instantiated to load image, this would show the ajax-spinner till the image is loaded.
Get your ajax spinner here..
jQuery
//Assuming gallery-overlay is id of the div where you are showing image.
$(function(){
$("#gallery-overlay").html("<img src='ajax-spinner.gif'>");
$.post(url,{variable:variable},function(data){
$("#gallery-overlay").html(data);
//data is whatever your php file returns. The ajax-spinner will be there till this appends the html returned by your php file.
});
})
PHP
//Post variables
//Get the src and image details from table.
$src = $row['src-in-db'];
$alt = $row['alt-in-db'];
$width = $row['width-in-db'];
$height = $row['height-in-db'];
//Echo the html code for #gallery-overlay.
echo "
<img src='".$src."' width='".$width."' height='".$height."' alt='".$alt."'>
";
And then for next and prev buttons too, you will not need the jQuery you have done in your fiddle. You will need another php file that sends you the image html.
Answer to first question
As I told already in your previous question, IMO, it would depend on how many images you load at once. Tell me how many are you loading?
You have also done the jQuery part and all, So I would suggest to keep ajax away for now. If you are loading about 20-25 images too.
Here are some questions which you must see.
Question 1.
Question 2.(These answers are sufficient for your first question)
And since this is a image gallery what I am sure about is you will show the images in the preview outside the modal window, right?
Then there is absolutely no need to use ajax, since the images are cached by browsers.
Conclusion: Don't use ajax. Let it be what you have done already. Just add close button or event handler for esc button to close modal window.
Increase max-age for img cache by browsers,
Do browsers cache images?
How do you cache an image in Javascript