I'm not going to explain the rest of the code, other than to say that you shouldn't touch anything outside of the bold areas; explaining that entire function would be a lesson in and of itself, and that's more Stephen Chapman's area. Take a look at his GuideSite on Javascript, if you're interested in learning more.
And if you're interested in seeing how the popup windows are supposed to look, take a look at my finished gallery. Click on the Portfolio button, and then try out the different thumbnails to open the various bits and pieces of my artwork that I used to build the gallery.
You should repeat the Javascript for each one of your thumbnails, changing the HTML file that it opens to match the correct one for the popup and changing the other parameters as you see fit.

