Source of www.robertnabbe.com/
Images should go in a folder within 'gallery/' folder (eg. 'gallery/first_gallery'). An click on an element with a ".gal_link" class will create an ajax call to getimg.php, which in turn will return the content of the folder corresponding to the element's 'data-gal' attr. (eg. "data-gal="first_gallery").
First image is loaded and faded in. After the initial photo has loaded, both the next and previous photo is loaded in the background, so when the users navigates forwards/backwards, the photo displays smoothly without (seemingly) having to be downloaded.