The code was a little convaluted for me to even look at. Instead, I'll just give an example of a random image. Here's what I'd do:
and you just do the array for your iamges and use that function, and it should work. There's no reason to load all the images.
imageArray = new Array("images/image1.gif","image2.jpg","image3.gif");
document.images[image].src = imageArray[ran];