Is there a way of checking a file exists before linking to it?

I sell didjeridoos and handdrums.
I was hoping to create small html program for each drum, somthing like this....

thisdrum=new Image()
thisdrum src=drum001.gif
<script src=createpage.js>

and saved as drum000 to drum999

Now I need a function included in the creatpage.js, that checks if a file exists,(eg drum000.html) if it does, go there, if it doesn't, try drum001.html

any suggestions on how I could go about it?