Heavily modified gallery.pl designed for dynamic usage