the lag seams to come from connecting to and retrieving data from the MySQL database, i get the same lag if I try access the gallery rss feed:
If the problem is happening when accessing the database, not much can be done through the php coding.
you can test accessing the database by creating a blank php page in Dreamweaver and adding a recordset to it, then displaying a single record from the recordset.
If the page is still loading slowly, it is the connection between the PHP server and the mySQL server that is causing the lag.
If it is not the connection to the database, then you can try adding an index to the pg1_gallery_images table, using PHPMyQdmin or another database managemet tool, run the following query:
CREATE INDEX gallery_id ON pg1_gallery_images (gallery_id)