// JavaScript Document
Array.prototype.shuffle = function() { 
  var i, temp, i1, i2;
  for (i=0; i<this.length; i++) { 
    i1 = Math.floor( Math.random() * this.length );
    i2 = Math.floor( Math.random() * this.length );
    temp = this[i1];
    this[i1] = this[i2];
    this[i2] = temp;
  }
}
randImgObj1s = []; // holds all random rotating image objects defined
// constructor 
function randImgObj1(s) {
  this.speed=s; this.ctr=0; this.timer=0;  
  this.index = randImgObj1s.length; randImgObj1s[this.index] = this;
  this.animString = "randImgObj1s[" + this.index + "]";  
}
randImgObj1.prototype = {
  addImages: function(ar) { // preloads images
    this.imgObj.imgs = [];
    for (var i=0; ar[i]; i++) {
      this.imgObj.imgs[i] = new Image();
      this.imgObj.imgs[i].src = randImgObj1.imagesPath + ar[i];	  
    }
  },
  rotate: function() { // controls rotation
    var ctr = Math.floor( Math.random() * this.imgObj.imgs.length );
    if (ctr == this.ctr) ctr = (ctr > 0)? --ctr: ++ctr;
    this.ctr = ctr;
    if ( typeof this.imgObj.filters != "undefined" ) {
   		this.imgObj.style.filter = 'blendTrans(duration=1)';
      if (this.imgObj.filters.blendTrans) this.imgObj.filters.blendTrans.Apply();
    }
    this.imgObj.src = this.imgObj.imgs[this.ctr].src;
    if ( typeof this.imgObj.filters != "undefined" && this.imgObj.filters.blendTrans )
      this.imgObj.filters.blendTrans.Play();    
  }
}
// sets up rotation for all defined randImgObj1s
randImgObj1.start = function() {
  for (var i=0; i<randImgObj1s.length; i++) 
    randImgObj1s[i].timer = setInterval(randImgObj1s[i].animString + ".rotate()", randImgObj1s[i].speed);                     
}
randImgObj1.setUpImg = function(imgAr, sp, w, h) {
  var rotator, img, imgStr = "";
  rotator = new randImgObj1(sp);
  randImgObj1s[randImgObj1s.length-1].imgAr = imgAr;
  imgAr.shuffle();
  img = imgAr[ Math.floor( Math.random() * imgAr.length ) ]; 
  imgStr += '<img align="middle" border="0" src="' + randImgObj1.imagesPath + img + '" alt="" ';
  imgStr += 'name="img' + (randImgObj1s.length-1) + '" width="' + w + '" height="' + h + '">';
  document.write(imgStr); 
}
function initRandRotation1()
 {
  for (var i=0; randImgObj1s[i]; i++) {
    var rotator = randImgObj1s[i];
    rotator.imgObj = document.images["img" + i]; // get reference to the image object
    rotator.addImages(rotator.imgAr);
    rotator.rotate();
  }
  randImgObj1.start();
}