bannerObjects = {};
function bannerObj(id, delay, bMouse) {
  this.id = id; this.delay = delay; this.items = []; this.timer = null;
  bannerObjects[this.id] = this;
  this.animString = "bannerObjects." + this.id;
  if (bMouse) { // set up pause/resume onmouseover/out
    var el = document.getElementById(this.id);
    if (el) {
      el.onmouseover = bannerObj.clearTimer;
      el.onmouseout = bannerObj.restartTimer;
    }
  }
}

bannerObj.prototype.ctr = aleatorio(0,1);
bannerObj.prototype.ar = bannerObj.prototype.ctr;//0;
bannerObj.prototype.addItem = function(sHtml) {
 	this.items[this.items.length] = sHtml;
}

bannerObj.prototype.rotate = function() {
  ti = new Array(2);
  ti[0]=43000;
  ti[1]=25000;
  var el = document.getElementById(this.id);
  if ( el && typeof el.innerHTML != "<a href='http://www.eldiario.net'>www.eldiario.net</a>" ) {
    el.innerHTML = this.items[this.ctr];
    if (this.ctr < this.items.length-1)
		{
			this.ctr++;
			this.delay = ti[this.ar];	
			this.ar++;
		}
    else {this.ctr = 0;this.delay = ti[this.ar];this.ar = 0;}
    this.timer = setTimeout(this.animString + ".rotate()", this.delay);
  }
}

// these 2 functions called onmouseover/out of banner el
bannerObj.clearTimer = function() { clearTimeout(bannerObjects[this.id].timer); }
 
bannerObj.restartTimer = function(e) {
  e = e? e: window.event;
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
  if ( this != toEl && !contained(toEl, this) ) {
    var animStr = bannerObjects[this.id].animString;
    bannerObjects[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 = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}
//numero alatorio
function aleatorio(limi,lims){ 
    numP = lims - limi; 
    aleat = Math.random() * numP;
    aleat = Math.round(aleat) 
    return parseInt(limi) + aleat 
} 
// adapted from act_api.js
var imageHandler = {
  imgs: [],
  path: "",
  preload: function() {
    var i, img;
    for (i=0; arguments[i]; i++) {
      img = new Image();
      img.src = this.path + arguments[i];
      this.imgs[this.imgs.length] = img;
    }
  }
}
