I'm trying to build a slideshow page in Javascript. It's dynamically built and all of that is working, but the Javascript timing is giving me trouble.

First, a PHP script builds an array of Image objects to preloads. I have a 'Loading pictures....' message appear in the foreground of the page. This message should disappear after the final image has been preloaded. I'm using Javascript's onLoad() event of the last image to change the message's CSS div display property to hidden, but it always executes immediately, even though the browser is obviously still working.

Is there a way just to tell Javascript "do not proceed with the rest of the code until this task has finished"? I'm open to any ideas.