
if (!document.all) {
  window.attachEvent = function(event, func) {
    if (event.substr(0, 2).toLowerCase() == "on") {
      event = event.substr(2);
    }
    this.addEventListener(event, func, true);
  }
}

function Rotate(id, images, options) {
  this.name = "image_rotate";
  this.obj = eval(this.name + "=this");

  this.id = id;
  this.index = 0;
  this.images = images;
  this.delay = 2500;
  if (options && options['delay']) {
    this.delay = options['delay'];
  }
  this.element = document.getElementById(this.id);
  if (document.getElementById(this.id+'_add')){
    this.element_add = document.getElementById(this.id+'_add');
  }
  this.timer = null;

  this.go = function() {
    if (!this.element) return;
    this.element.style.backgroundImage = 'url(' + this.images[this.index] + ')';
    if (this.element_add) {
        this.element_add.style.backgroundImage = 'url(' + this.images[this.index] + ')';
    }
    this.index++;
    if (this.index >= this.images.length) {
      this.index = 0;
    }
    clearTimeout(this.timer);
    this.timer = setTimeout(this.name + '.go()', this.delay);
  }

  this.preload = function() {
    var imgs = [];
    for (var i = 0; i < this.images.length; i++) {
      var img = new Image();
      img.src = this.images[i];
      imgs.push(img);
    }
  }

  this.preload();
  this.go();
}

