function fadein(imageid, millisec) {
  var speed = Math.round(millisec / 200);
  var timer = 0;
  var imgobj = document.getElementById(imageid);
  if (imgobj.src.indexOf('\/s.gif') < 0) {
    window.status = (imgobj.src);
    for(i=0;i<=100;i++) {
      setTimeout("changeOpac(" + i + ",'" + imageid + "')", (timer*speed));
      timer++;
    }
  } else {
    //alert('ha');
  }
}

function changeOpac(opacity, id) {
  var object = document.getElementById(id).style;
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(divid, imageid, imagefile, millisec) {
  var speed = Math.round(millisec / 200);
  var timer = 0;
  // fade out image
  for(i=100;i>=0;i--) {
    setTimeout("changeOpac(" + i + ",'" + imageid + "')", (timer*speed));
    timer++;
  }
  // timer = timer + 10;
  // fade in image
  //setTimeout("changeImage('" + imageid + "', '" + imagefile + "')", (timer*speed));
  for(i=0;i<=100;i++) {
    if (i==0) {
      setTimeout("changeImage('" + imageid + "', '" + imagefile + "')", (timer*speed));
      timer++;
    }
    setTimeout("changeOpac(" + i + ",'" + imageid + "')", (timer*speed));
    timer++;
  }
}

function changeImage(imageid, imagefile) {
  // set the current image
  document.getElementById(imageid).src = imagefile;
}

function RotImage (imgid, time) {
  this.imgid = imgid;
  this.time= time;
  this.pos = 0;
  this.imgs = new Array();
  this.stop = true;
  this.preloads = new Array();
  this.blending = true;
}

RotImage.prototype.addImageSrc = function(src) {
  // if (this.pos == -1) {
    // this.pos = 0;
  // }
  RotImage_preloadImages(src);
  this.imgs[this.imgs.length] = src;
  var pimg = new Image();
  this.preloads[this.preloads.length] = pimg;
  pimg.src = src;
}

RotImage.prototype.rotate = function() {
  if (this.imgs.length<=1) return;
  this.pos = (this.pos + 1) % this.imgs.length;
  if (this.blending) blendimage(this.imgid + '_div', this.imgid, this.imgs[this.pos], 1500);
  else document.getElementById(this.imgid).src = this.imgs[this.pos];
  if (this.stop == false) {
    var instance = this;
    setTimeout(function(){instance.rotate()}, this.time);
  }
}

RotImage.prototype.stop = function() {
  this.stop = true;
}

RotImage.prototype.start = function() {
  this.stop = false;
  var instance = this;
  if (this.imgs.length>0) {
    document.getElementById(this.imgid).style['display'] = '';
    changeImage(this.imgid, this.imgs[0]);
  }
  setTimeout(function(){instance.rotate()}, this.time);
}

function RotImage_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=RotImage_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
