/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

function initImgRotation() {
    // create rotating image objects here 
    // arguments: image name, rotation speed (milliseconds)
    var rotator1 = new rotateImgObj('img1',8000); // The number after img1 is the duration an image is displayed in miliseconds. -MMP, JAN/24th/2006
  
    // add the images to rotate into that image object
    rotator1.addImages(
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/DSC2337_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/DSC2633_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/DSC2777_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/DSC2925_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/DSC3038_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/LeBeau_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/apr27th1994_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/beakes2_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/centrifuge_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/diane_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/figure1_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/marcy_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/maria_rotator_image.jpg", 
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/picture1_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/ravislab_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/researcher1_rotator_image.jpg", 
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/researcher6_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/researcher7_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/rowley_pres_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/testtubes_rotator_image.jpg",
	    "http://uccrc.uchicago.edu/bsd_page/images/rotating_images/vannire_rotator_image.jpg"
	);  
  
    // add the corresponding actions to take onclick of those images 
    // destination url or function pointer
     rotator1.addActions(
	     "#"
	 );

     rotator1.rotate();
  
     rotateImgObj.start();
}


// for example function call onclick 
// This function demonstrates how to obtain some of the information available about the rotateImgObj clicked on 
function doMsg() { 
    var obj = rotateImgObjs[0];
    var msg = "You clicked on " + obj.imgObj.src;
    msg += ",\nnumber " + Number(obj.ctr+1) + " in the set. ";
    msg += "It's height is " + obj.imgObj.height + " pixels.";
    alert(msg);
}


// If all the images you wish to display are in the same location, you can specify the path here 
rotateImgObj.imagesPath = "";
// if you want url's to open in a separate window, un-comment this line
//rotateImgObj.tgt = "_blank"; 


// no need to edit code below 
/////////////////////////////////////////////////////////////////////
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 + "]";
}

rotateImgObj.prototype = {
  addImages: function() { // preloads images
    this.imgObj.imgs = [];
    for (var i=0; i<arguments.length; i++) {
      this.imgObj.imgs[i] = new Image();
      this.imgObj.imgs[i].src = rotateImgObj.imagesPath + arguments[i];
    }
  },
  
  addActions: function() {
    this.actions = [];
    for (var i=0; i<arguments.length; i++) { this.actions[i] = arguments[i]; }
  },
  
  rotate: function() {
    if (this.ctr < this.imgObj.imgs.length-1) this.ctr++;
    else this.ctr = 0;
    this.imgObj.src = this.imgObj.imgs[this.ctr].src;
  }
}

// sets up rotation for all defined rotateImgObjs
rotateImgObj.start = function() {
  for (var i=0; i<rotateImgObjs.length; i++) 
    rotateImgObjs[i].timer = setInterval(rotateImgObjs[i].animString + ".rotate()", rotateImgObjs[i].speed);                     
}

// called onclick of images
rotateImgObj.doClick = function(n) {
	if ( document.images && rotateImgObjs[n] ) {
    var obj = rotateImgObjs[n]; // shorten reference 
    if ( obj.actions && obj.actions[obj.ctr] ) {
  		if ( typeof obj.actions[obj.ctr] == "string" ) {
        if ( rotateImgObj.tgt == "_blank" ) {
          // open in separate window (add features here if you want, i.e., chrome, size, position, ...)
          var win = window.open(obj.actions[obj.ctr], "subwin");
          if ( win && !win.closed ) win.focus();
        } else window.location = obj.actions[obj.ctr];
      } else obj.actions[obj.ctr]();
    } 
    return false;
	} else return true;
}

// for stopping/starting onmouseover/out
rotateImgObj.pause = function(n) {	
  if (rotateImgObjs[n]) clearInterval(rotateImgObjs[n].timer); 
}

rotateImgObj.resume = function(n) {
  if ( rotateImgObjs[n] ) {
    var obj = rotateImgObjs[n]; // shorten reference 
    obj.rotate(); // rotate now and resume repeated calls
    obj.timer = setInterval( obj.animString + ".rotate()", obj.speed );
  }
}