issue with Javascript image changer
<p>I have a script running on my page to change the images. I want to repeat it 6 times to use in other places on the same page, but it wont work when I repeat it.</p>

<pre><code>  var delay = 2000 //set delay in miliseconds
  var curindex = 0

  var randomimages = new Array()

  randomimages[0] = "hhh200.jpg"
  randomimages[1] = "ray200.jpg"

  var preload = new Array()

   for (n = 0; n &lt; randomimages.length; n++) {
      preload[n] = new Image()
      preload[n].src = randomimages[n]
  }

  document.write('&lt;img name="defaultimage" src="' + randomimages[Math.floor(Math.random() * (randomimages.length))] + '"&gt;')

   function rotateimage() {

      if (curindex == (tempindex = Math.floor(Math.random() * (randomimages.length)))) {
          curindex = curindex == 0 ? 1 : curindex - 1
      } else curindex = tempindex

      document.images.defaultimage.src = randomimages[curindex]
  }

  setInterval("rotateimage()", delay)
</code></pre>

<p>Can anyone see why it's not working?</p>
