(Pre)loading images into slideshow


I’m here to ask some help.
I have this javascript image slideshow, I want it to preload images.

The idea was that there is an array which contains images to show,
I want the images to be added to the array when loaded,
so there aren’t any half loaded images showing.

Any ideas how to do this? I need the array lenght, (the number of images in the folder), and it isn’t static, the client can remove or add images. I guess I could use php for checking it out. Oh, and I don’t know the names of the images.

Or maybe I don’t have to write it at all, If there already is something like this.