Typically, on a free site your thumbs would link to a bigger image, not directly to a site.
On your internal links you would link a thumb to an html page with a bigger image and a sponsor banner top and bottom perhaps.
For galleries you would have almost the same thing but some lists still do not allow the image to be on an html page so there the thumbs would link to just a bigger image and the banners would be on the page with the thumbs.
You can do all of that by hand without any need of a programmer or a database. Flat html is much better (imho) then dynamic pages for SEO purposes.
Some old school tutorials - These are out of date in that nowadays you would probably be using styles (css) to achieve colors and so forth, but all the code still works and probably will for the forseeable future:
Learn the HTML code to make a site in an Hour
Basic HTML for Newbie Webmasters
Basic Free Site Building
Basic TGP Gallery Building
.