// JavaScript Document

/* 
   Implements the random image swapping on second
   level pages.  Internet Explorer uses a fade-in
   effect.  Other browsers just swap the images.
   
   Requires the javascript array named randImg 
   to be defined previously (i.e. include 
   rotate_ab_images.js).   randImg should contain
   the list of image names to be used in the set
   of rotating images for the html page this script
   is included in.  It is assumed that the image
   names will contain a sequential integer at the end
   of the image file name prior to the image file 
   extension 
   (i.e. image-something1.jpg, image-something2.jpg, etc)
   
*/

/* this code prevents flicker bug on internet explorer*/
/*@cc_on @*/
/*@if (@_jscript_version >= 4)
document.execCommand("BackgroundImageCache", false, true);
/*@end @*/



/* below are the main javascript functions for image swaping 
   and random number generation */

var ix = 0;
var totalImages = randImg.length;
var imgObj = document.getElementById("rotatingImage");
var lastNo=-1;
var fadeOutMS = 5000; /* how much time each image 
						 is displayed in milliseconds */

function rotateImages() {
  window.status = "";
  var imgObj = document.getElementById("rotatingImage");

  if(typeof imgObj.filters != "undefined"){
  		imgObj.style.filter='blendTrans(duration=1)';
  		imgObj.filters.blendTrans.Apply();
  		imgObj.filters.blendTrans.play();
  }  
  
  var ix = getRandom();
  var nextImage = randImg[ix];
  //imgObj.src=nextImage;
  imgObj.style.backgroundImage= "url('"+nextImage+"')";
  imgObj.style.backgroundRepeat = "no-repeat";
  imgObj.style.backgroundPosition="100% 0";

  /* this line swaps the images, the number represents how
     much time each image is displayed in milliseconds  */
  setTimeout("rotateImages()", fadeOutMS);

}

function getRandom() {
	
	/* get a random whole number within the range of the
	   number of images in the randImg array.  If the next
	   random number is the same as the previous random number
	   then try again to avoid duplicates.
	*/
	var randNo = Math.floor(Math.random()*randImg.length);
	if (randNo == lastNo) {
		randNo = getRandom();
	}
	else {
		lastNo = randNo;
	}
	return randNo;
}

function delayStart() {
	setTimeout("rotateImages()", fadeOutMS);
}