you can use php to pass those variables.
the thumpnail link would be
<a href="java script:openNewWindow('http://www.mydomain/folder/pop-ups.php?img=08925')">
And then on pop-ups.php
<a href="#" onClick="window.close()">
<?php
echo "<img src://www.mydomain/Images/fantasy/$_GET[img].jpg> ";
</a>
That should take care of your problem
If the thumbnails are all number sequentially you can use a while loop to build the thumbnal links as well. (That is if they are all on a couple pages)