
if (document.images) {
 document.imagePreload = {};
 var oo = document.imagePreload
 oo.elem =  new Image();
 // set image urls
 oo.stack = new Array();
 oo.serverPath = "./images/";
 oo.stack.push("dk.john.jpg");
 oo.stack.push("dmw.jpg");
 oo.stack.push("dk.john2.jpg");
 for (var ii=0,mm=oo.stack.length;ii<mm;ii++) {
  oo.stack[ii] =oo.serverPath + oo.stack[ii];
  oo.elem.src = oo.stack[ii];
 }
}

var rotaters = [];

// static method: there's only one setTimeout stack
function Rotater() {
 for (var ii=0,mm=rotaters.length;ii<mm ;ii++ ) {
  rotaters[ii].idx++;
  if (rotaters[ii].idx>=rotaters[ii].maxi) { rotaters[ii].idx = 0;}
  rotaters[ii].targ.src = rotaters[ii].stack[rotaters[ii].idx];
 }
 //setTimeout(Rotater,rotateTime);

}
// static property, there's only one time limit for setTimeout
var rotateTime = 4000;

function Rotate() {
 this.stack =[];
 this.targ = null;
 this.idx = 0;
 this.maxi = 0;
}

Rotate.prototype = {
 // wait til the page is built to do this
 init:function() {
  var _this = this;
  setInterval(Rotater,rotateTime);
 },

 // wait til the element exists to do this
 setTarg:function(elem) {
  this.targ = elem;
 },
 /**
  * @param either N-scalar values or an array
  * the source attributes for the rotated imate
  */
 setStack:function () {
  if ("object" == typeof arguments[0]) {
   for (var i=0,m=arguments[0].length;i<m;i++ ) {
    this.stack.push(arguments[0][i]);
   }

  }
  else {
   for (var i=0,m=arguments.length;i<m ;i++ ) {
    this.stack.push(arguments[i]);
   }
  }
  this.maxi = this.stack.length;
 }

}

rotaters[0] = new Rotate();

// if there's only one rotater, just include everything in
document.images.stack

rotaters[0].setStack(document.imagePreload.stack);
