function OpacitySlideShow(name, imageSources, placeHolderId, placeHolderId2)
{
 this._name = name;
 this._images = new Array();
 for (var idx = 0; idx < imageSources.length; ++idx)
 {
   var img = new Image();
   img.src = imageSources[idx];
   this._images.push(img)
 }
 this._placeHolderId = placeHolderId;
 this._placeHolderId2 = placeHolderId2;
}

OpacitySlideShow.prototype.Run = function(maxOpacity, blendInTime, fixTime)
{
  this._placeHolder = $(this._placeHolderId);
  this._placeHolder2 = $(this._placeHolderId2);
  this._imgIdx = 0;
  SetOpacity(this._placeHolder, 0);
  this._placeHolder.src = this._images[0].src;
  this._placeHolder2.src = this._images[2].src;
  var dt = new Date();
  this._blendInTime = blendInTime;
  this._fixTime = fixTime;
  this._startTime = dt.getTime();
  this._maxOpacity = maxOpacity;
  this._busy = false;
  window.setInterval(this._name + ".RunStep()", 20)
}



OpacitySlideShow.prototype.RunStep = function()
{
  if (this._busy)
  {
    return;
  }
  this._busy = true;
  var dt = new Date();
  var currTime =  dt.getTime();
  if (currTime - this._startTime > 2 * (this._blendInTime + this._fixTime))
  {
    this._startTime = currTime;
    this._imgIdx = (this._imgIdx + 1) % this._images.length;
    var imgIdx2 = (this._imgIdx + 2) % this._images.length;
    this._placeHolder2.src = this._images[imgIdx2].src;
    this._busy = false;
  }
  else
  {

    this.SetImage(currTime);

    var opac = this.GetOpacity(currTime);
    SetOpacity(this._placeHolder, opac)
    SetOpacity(this._placeHolder2, this._maxOpacity - opac);
    this._busy = false;
  }
}

OpacitySlideShow.prototype.SetImage = function(currTime)
{
  if (currTime - this._startTime > this._blendInTime)
  {
    var imgIdx2 = (this._imgIdx + 1) % this._images.length;
    var src = this._images[imgIdx2].src;
    if (this._placeHolder.src != src)
      this._placeHolder.src = src;
  }
}

OpacitySlideShow.prototype.GetOpacity = function(currTime)
{
  var blendFixTime = this._blendInTime + this._fixTime;
  if (currTime - this._startTime < blendFixTime)
    return Math.max(0, this._maxOpacity * (1 - (currTime - this._startTime) / this._blendInTime));
   else
     return Math.min(this._maxOpacity, this._maxOpacity * (currTime - blendFixTime - this._startTime) / this._blendInTime);
}
