// JavaScript Document
var img1_ar = new Array("display_1.gif", "display2.jpg", "display3.jpg", "display4.jpg", "display5.jpg","display6.jpg");

// for the second set of rotating images 
//var img2_ar = new Array("pic1.jpg", "pic2.jpg", "asusign.jpg", "pic4.jpg", "sunset2.jpg", "pic8.jpg", "pic9.jpg", "pic10.jpg");

// If all the images you wish to display are in the same location, you can specify the path here 
rotateImgObj.imagesPath = "images/";
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;
  }
}

// shuffle arrays set up above 
img1_ar.shuffle();

function initImgRotation() {
  // create rotating image objects here 
  // arguments: image name, rotation speed
  var rotator1 = new rotateImgObj('img1',5000);
  // add the images to rotate into that image object (point to arrays set up above)
  rotator1.addImages(img1_ar);
  rotator1.rotate();
    
 
  
  // starts rotation for all defined rotateImgObjs
  for (var i=0; i<rotateImgObjs.length; i++) 
    rotateImgObjs[i].timer = setInterval(rotateImgObjs[i].animString + ".rotate()", rotateImgObjs[i].speed);
}

rotateImgObjs = []; // holds all rotating image objects defined
// constructor 
function rotateImgObj(nm,s) {
  this.speed = s; this.ctr=0; this.timer=0;  
  this.imgObj = document.images[nm]; // get reference to the image object
  this.index = rotateImgObjs.length; rotateImgObjs[this.index] = this;
  this.animString = "rotateImgObjs[" + this.index + "]";
  
  this.addImages = addRotatingImages;
  this.rotate = rotateImg;
}

// preloads images
function addRotatingImages(ar) {
  this.imgObj.imgs = [];
  for (var i=0; i<ar.length; i++) {
    this.imgObj.imgs[i] = new Image();
    this.imgObj.imgs[i].src = rotateImgObj.imagesPath + ar[i];
  }
}

// controls rotation
function rotateImg() {
  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)';
    this.imgObj.filters.blendTrans.Apply();
  }
  this.imgObj.src = this.imgObj.imgs[this.ctr].src;
  if ( typeof this.imgObj.filters != "undefined" ) this.imgObj.filters.blendTrans.Play();    
}


