I assume you're using jQuery in your javascript since it is the most incredible thing ever...Have you considered using something like the .next() function in jQuery?
You could set a class on one of the elements like <li class='my_navigator'> . As you guessed, the layout.php file does loop through the images, so all of the LI's would get the class. So, it would be easy to get the next li having that class by using something like: jQuery(".my_navigator").next()
That would give you the next li sibling having the my_navigator class.
Here's the jQuery documentation on that: http://docs.jquery.com/Traversing/next
Donations are always appreciated...especially now that Apple's put their iPad out there ;-) Always fun to have something to save up for!
I'll be thinking about a the use case for a sequential numbering in the layouts. Let me know a little more about what you're trying to accomplish if you don't mind.
Thanks,
BB