/*************************************************************************
  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',12000);
  // add the images to rotate into that image object
  rotator1.addImages("3464.jpg", "3204.jpg", "3943.jpg", "3744.jpg", "3971.jpg", "3209.jpg", "3267.jpg", "3729.jpg", "1905.jpg", "3969.jpg", "3757.jpg", "2863.jpg", "3888.jpg", "3196.jpg", "2787.jpg", "3875.jpg", "3741.jpg", "3920.jpg", "3267.jpg", "3092.jpg", "3217.jpg", "3214.jpg", "3883.jpg", "1018.jpg", "2867.jpg", "1881.jpg", "1904.jpg", "3492.jpg", "2791.jpg", "4077.jpg", "3525.jpg", "3686.jpg", "3518.jpg", "3633.jpg", "4185.jpg", "4157.jpg", "3951.jpg", "4198.jpg", "4220.jpg", "4214.jpg");
  // add the corresponding actions to take onclick of those images 
  // (last one shows how to do nothing onclick)
  rotator1.addActions("http://www.dramatists.com/cgi-bin/db/single.asp?key=3464", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3204", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3943", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3744", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3971", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3209", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3267", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3729", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1905", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3969", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3757", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2863", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3888", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3196", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2787", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3875", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3741", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3920", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3267", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3092", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3217", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3214", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3883", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1018", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2867", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1881", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1904", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3492", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2791", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4077", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3525", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3686", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3518", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3633", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4185", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4157", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3951", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4198", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4220", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4214");
  rotator1.rotate();
  
  var rotator2 = new rotateImgObj('img2', 12000);
  rotator2.addImages("3783.jpg", "895.jpg", "3452.jpg", "3273.jpg", "3351.jpg", "2895.jpg","1892.jpg", "1890.jpg", "1780.jpg", "2807.jpg", "3274.jpg", "3964.jpg", "3132.jpg", "3957.jpg", "3739.jpg", "2489.jpg", "3158.jpg", "3199.jpg", "3222.jpg", "3224.jpg", "3792.jpg", "1379.jpg", "2747.jpg", "2778.jpg", "2784.jpg", "2789.jpg", "3263.jpg", "904.jpg", "1238.jpg", "4080.jpg", "3629.jpg", "4078.jpg", "3885.jpg", "4126.jpg", "913.jpg", "3626.jpg", "4201.jpg", "4229.jpg", "1817.jpg", "4257.jpg");
  // demonstrates how to call another function onclick
  rotator2.addActions("http://www.dramatists.com/cgi-bin/db/single.asp?key=3783", "http://www.dramatists.com/cgi-bin/db/single.asp?key=895", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3452", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3273", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3351", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2895","http://www.dramatists.com/cgi-bin/db/single.asp?key=1892", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1890", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1780", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2807", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3274", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3964", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3132", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3957", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3739", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2489", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3158", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3199", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3222", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3224", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3792", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1379", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2747", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2778", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2784", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2789", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3263", "http://www.dramatists.com/cgi-bin/db/single.asp?key=904", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1238", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4080", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3629", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4078", 
"http://www.dramatists.com/cgi-bin/db/single.asp?key=3885", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4126", "http://www.dramatists.com/cgi-bin/db/single.asp?key=913",  "http://www.dramatists.com/cgi-bin/db/single.asp?key=3626",
"http://www.dramatists.com/cgi-bin/db/single.asp?key=4201", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4229",
"http://www.dramatists.com/cgi-bin/db/single.asp?key=1817", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4257");  
  rotator2.rotate();
  
  var rotator3 = new rotateImgObj('img3', 12000);
  rotator3.addImages("3814.jpg", "3876.jpg", "3959.jpg", "3760.jpg","3242.jpg", "2928.jpg", "3350.jpg", "2961.jpg", "816.jpg", "2973.jpg", "2809.jpg", "3004.jpg", "3864.jpg", "3968.jpg", "3213.jpg", "3809.jpg", "3230.jpg", "2758.jpg", "3880.jpg", "1271.jpg", "3982.jpg", "3013.jpg", "3985.jpg", "2955.jpg", "1381.jpg", "4051.jpg", "3485.jpg", "3621.jpg", "3682.jpg", "3829.jpg", "3855.jpg", "4104.jpg", "4105.jpg", "4108.jpg", "4113.jpg", "4071.jpg", "2737.jpg", "4100.jpg", "4254.jpg", "4263.jpg");
  // demonstrates how to call another function onclick
  rotator3.addActions("http://www.dramatists.com/cgi-bin/db/single.asp?key=3814", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3876", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3959", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3760","http://www.dramatists.com/cgi-bin/db/single.asp?key=3242", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2928", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3350", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2961", "http://www.dramatists.com/cgi-bin/db/single.asp?key=816", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2973", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2809", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3004", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3864", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3968", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3213", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3809", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3230", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2758", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3880", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1271", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3982", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3013", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3985", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2955", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1381", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4051", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3485", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3621", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3682", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3829", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3855", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4104",
"http://www.dramatists.com/cgi-bin/db/single.asp?key=4105", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4108", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4113", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4071", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2737", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4100", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4254", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4263");
  rotator3.rotate();
  
  var rotator4 = new rotateImgObj('img4', 12000);
  rotator4.addImages("3965.jpg", "3754.jpg", "3203.jpg", "3220.jpg", "3436.jpg", "3786.jpg","1606.jpg", "3900.jpg", "959.jpg", "854.jpg", "888.jpg", "3693.jpg", "3852.jpg", "3788.jpg", "3103.jpg", "3524.jpg", "3208.jpg", "1634.jpg", "3237.jpg", "3745.jpg", "3116.jpg", "2594.jpg", "3125.jpg", "3759.jpg", "3775.jpg", "3701.jpg", "3223.jpg", "3432.jpg", "3812.jpg", "2866.jpg", "3605.jpg", "3970.jpg", "4097.jpg", "4111.jpg", "3245.jpg", "4115.jpg", "3967.jpg", "1722.jpg", "4189.jpg");
  // demonstrates how to call another function onclick
  rotator4.addActions("http://www.dramatists.com/cgi-bin/db/single.asp?key=3965", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3754", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3203", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3220", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3436", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3786","http://www.dramatists.com/cgi-bin/db/single.asp?key=1606", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3900", "http://www.dramatists.com/cgi-bin/db/single.asp?key=959", "http://www.dramatists.com/cgi-bin/db/single.asp?key=854",
"http://www.dramatists.com/cgi-bin/db/single.asp?key=888", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3693", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3852", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3788", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3103", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3524", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3208", "http://www.dramatists.com/cgi-bin/db/single.asp?key=1634", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3237", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3745", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3116", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2594", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3125", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3759", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3775", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3701", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3223", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3432", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3812", "http://www.dramatists.com/cgi-bin/db/single.asp?key=2866", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3605", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3970","http://www.dramatists.com/cgi-bin/db/single.asp?key=4097", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4111", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3245",  "http://www.dramatists.com/cgi-bin/db/single.asp?key=4115", "http://www.dramatists.com/cgi-bin/db/single.asp?key=3967",  "http://www.dramatists.com/cgi-bin/db/single.asp?key=1722", "http://www.dramatists.com/cgi-bin/db/single.asp?key=4189"); 
  rotator4.rotate();
  
  rotateImgObj.start();   
}

// for example function call onclick 
// This function demonstrates how to obtain some of the information available about the image clicked on 
function doMsg() { 
  var obj = rotateImgObjs[1]; // refers to 2nd rotateImgObj (i.e., rotator2)
  var msg = "You clicked on " + obj.imgObj.src;
  msg += ". It's height is " + obj.imgObj.imgs[obj.ctr].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 = "http://www.dramatists.com/images/header/";
// if you want url's to open in separate window, un-comment this line
//rotateImgObj.tgt = "_blank"; 

// no need to edit code below 
/////////////////////////////////////////////////////////////////////
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;
  }
}

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() { // 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=2)';
      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 rotateImgObjs
rotateImgObj.start = function() {
 for (var i=0; i<rotateImgObjs.length; i++) 
 rotateImgObjs[i].timer = setInterval(rotateImgObjs[i].animString + ".rotate()", rotateImgObjs[i].speed);                     
}

rotateImgObj.setUpImg = function(imgAr, sp, w, h) {
  var rotator, img, imgStr = "";
  rotator = new rotateImgObj(sp);
  rotateImgObjs[rotateImgObjs.length-1].imgAr = imgAr;
  imgAr.shuffle();
  img = imgAr[ Math.floor( Math.random() * imgAr.length ) ]; 
  imgStr += '<img src="' + rotateImgObj.imagesPath + img + '" alt="" ';
  imgStr += 'name="img' + (rotateImgObjs.length-1) + '" width="' + w + '" height="' + h + '">';
  document.write(imgStr); 
}

// 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 );
// }
