bookObjects = {};
function bookObj(id,delay) {
  this.id = id; this.delay = delay; this.items = []; this.timer = null;
  bookObjects[this.id] = this;
  this.animString = "bookObjects." + this.id;
}

bookObj.prototype.ctr = 0;
bookObj.prototype.addItem = function(sHtml) {
 	this.items[this.items.length] = sHtml;
}

bookObj.prototype.rotate = function() {
  var el = document.getElementById(this.id);
  el.innerHTML = this.items[this.ctr];
  if (this.ctr < this.items.length-1) this.ctr++;
  else this.ctr = 0;
  this.timer = setTimeout(this.animString + ".rotate()", this.delay);
}

bookObj.prototype.setMouseEvents = function() {
  var el = document.getElementById(this.id);
  
  el.onmouseover = function(e) {
    clearTimeout(bookObjects[this.id].timer);
  }
  
  el.onmouseout = function(e) {
    e = e? e: window.event;
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( this != toEl && !contained(toEl, this) ) {
      var animStr = bookObjects[this.id].animString;
      bookObjects[this.id].timer = setTimeout(animStr + ".rotate()",500);
    }
  }  

  // returns true of oNode is contained by oCont (container)
  function contained(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode.parentNode ) {
      oNode = oNode.parentNode;
      if ( oNode == oCont ) return true;
    }
    return false;
  }
  
}

var imageHandler = {
  imgs: new Array(),
  path: "",
  preload: function () {
    for (var i=0; i<arguments.length; i++) {
      var img = new Image();
      img.src = this.path + arguments[i];
      this.imgs.push(img);
    }
  }
}

if (Array.prototype && !Array.prototype.push) {
	Array.prototype.push = function() {
		for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
		return this.length;
	};
}

