/* *********************************** */
/*  JAVASCRIPT SLIDESHOW Object V1.00  */
/* (c)Copyright 2007 - LOGICIA System  */
/* *********************************** */

function SlideShow (objName, slideImgName, slideShowSpeed, crossFadeDuration) {
  this.objName = objName ;

  this.pictureList = new Array() ;
  this.slideObj = new Array() ;
  this.slideIndex = 0 ;
  this.pictureIndex = 0 ;
  
  this.timeOutID = null ;
  this.slideImgName = slideImgName ;
  this.slideShowSpeed = slideShowSpeed ;
  this.crossFadeDuration = crossFadeDuration ;
  
  this.add_picture = slideShow_add_picture ;
  this.index_slideObj = slideShow_index_slideObj ;
  this.play = slideShow_play ;
  this.change_picture = slideShow_change_picture ;

}

function slideShow_add_picture(picture_fileName) {
  var i = this.pictureList.length ;
  this.pictureList[i] = new Image() ;
  this.pictureList[i].src = picture_fileName ;
}

function slideShow_index_slideObj() {
  var itemName ;
  var i = this.slideObj.length ;
  var RegExpStr = this.slideImgName + "(\\d+)?" ;
  var re = new RegExp(RegExpStr) ;
  
  for (var itemIndex in document.images) {  
    itemName = document.images[itemIndex].name ;
    if (result = re.exec(itemName)) {
      this.slideObj[i] = document.images[itemName] ;
      i++ ;
    }
  }
  
}

function slideShow_change_picture () {
  var currentSlideObj = this.slideObj[this.slideIndex] ;
  var currentPicture = this.pictureList[this.pictureIndex] ;
  var command ;

  if (document.all){
    command = "blendTrans(duration=" + this.objName + ".crossFadeDuration" ;
    currentSlideObj.style.filter = command ;
    currentSlideObj.filters.blendTrans.Apply() ;
  }

  currentSlideObj.src = currentPicture.src ;

  if (document.all){
    currentSlideObj.filters.blendTrans.Play()
  }

  this.slideIndex ++ ;
  if (this.slideIndex >= this.slideObj.length) {
    this.slideIndex = 0 ;
  }

  this.pictureIndex ++ ;
  if (this.pictureIndex >= this.pictureList.length) {
    this.pictureIndex = 0 ;
  }

}

function slideShow_play() {

  var timeout_command ;

  if (this.slideObj.length == 0) {
    this.index_slideObj() ;
  }

  this.change_picture() ;

  timeout_command = this.objName + ".play()" ; 
  this.timeOutID = setTimeout(timeout_command, this.slideShowSpeed) ;

}



