Hmm, actually it's possible if your middle page is script generated. (and final one of course)
So if you've got:
TGP -> html gallery -> final page
then it's not doable. But if you've got:
TGP -> script generated gallery -> final page
it's doable.
You can get referrer url thanks to the script generated gallery and pass it to the final page (in cookie, in url).
------------------
Custom Programming - CubeInnovations - http://www.cubeinnovations.com