
function Slideshow(obj_id, speed, fade)
{
  this.speed = speed ;
  this.fade = fade ;

  this.images = new Array() ;
  this.objId = obj_id ;
  this.obj = null ;
  this.img = null ;
  this.width = 300 ;
  this.height = 300 ;
  this.currentIndex = 0 ;

  this.addImage = function (src, alt, width, height)
  {
    //var img =  new Image(width, height) ;
    var img =  new Image() ;
    img.src = src ;
    img.alt = alt ;
        
    if (height < this.height)
    {
      var pad = Math.floor((this.height-height)/2)
      img.style.paddingTop = pad +'px' ;
      img.style.paddingBottom = (this.height-height-pad) +'px' ;
    }

    if (width < this.width)
    {
      var pad = Math.floor((this.width-width)/2) ;
      img.style.paddingLeft = pad +'px' ;
      img.style.paddingRight = (this.width-width-pad) +'px' ;
    }

    this.images.push(img) ;

//    if (width > this.width)
//      this.width = width ;
//    if (height > this.height)
//      this.height = height ;
  }

  this.next = function (index)
  {
    // FIXME: cross fade transition is ie only
    if (this.img.style && this.img.style.filter!=null)
    {
      this.img.style.filter
          ='blendTrans(duration='+this.fade+')';

      if (this.img.filters && this.img.filters[0])
      {
        
        this.img.filters[0].Apply();
    		this.img.filters[0].Play();
      }
    }

    this.img.src = this.images[index].src;
    this.img.alt = this.images[index].alt;
    this.img.style.paddingTop = this.images[index].style.paddingTop;
    this.img.style.paddingBottom = this.images[index].style.paddingBottom;
    this.img.style.paddingLeft = this.images[index].style.paddingLeft;
    this.img.style.paddingRight = this.images[index].style.paddingRight;

    if (this.img.filters && this.img.filters[0])
    {
      this.img.filters[0].Play();
    }


/*
    if (this.images[index].style 
        && this.images[index].style.filter!=null 
        && this.images[index].blendTrans) {
		}
*/
    index++ ;
    if (index > (this.images.length - 1)) index = 0;
    
    var that = this ;
    var func = function ()
    {
      that.next(index) ;
    }
    setTimeout(func, this.speed);
  }
  
  this.start = function ()
  {
//    alert (this.objId) ;
    this.obj = getObj(this.objId) ;
//    alert (this.obj) ;
    this.img = this.obj.getElementsByTagName('img')[0] ;


    if (this.img.height < this.height)
    {
      var pad = Math.floor((this.height-this.img.height)/2)
      this.img.style.paddingTop = pad +'px' ;
      this.img.style.paddingBottom = (this.height-this.img.height-pad) +'px' ;
    }

    if (this.img.width < this.width)
    {
      var pad = Math.floor((this.width-this.img.width)/2) ;
      this.img.style.paddingLeft = pad +'px' ;
      this.img.style.paddingRight = (this.width-this.img.width-pad) +'px' ;
    }
    
//    for (var i=0 ; i < this.images.length ; i++)
//    {
//    }
    this.obj.style.width = this.width +'px' ;
    this.obj.style.height = this.height +'px' ;
    this.obj.style.textAlign = 'left' ;
    
    var that = this;
    doit = function() {
      that.next(1);
    }
    setTimeout('doit()',this.speed);
  }
  
}

var doit ;
