//==================================================
// slide object
//==================================================
function slide(src,link,text) {
  this.src = src;
  this.link = link;
  this.text = text;
  if (document.images) {
    this.image = new Image();
  }

  this.loaded = false;
  //--------------------------------------------------
  this.load = function() {
    if (!document.images) { return; }
    if (!this.loaded) {
      this.image.src = this.src;
      this.loaded = true;
    }
  }

}

//==================================================
// slideshow object
//==================================================
function slideshow( slideshowname ) {
  this.name = slideshowname;
  this.image;
  this.slides = new Array();
  this.current = 0;
  this.timeout = 3000;
  this.timeoutid = 0;

  //--------------------------------------------------
  // Public methods
  //--------------------------------------------------
  this.add_slide = function(slide) {
    var i = this.slides.length;
    slide.load();
    this.slides[i] = slide;
  }

  //--------------------------------------------------
  this.play = function(timeout) {
    this.pause();
    if (timeout) {
      this.timeout = timeout;
    }
    if (typeof this.slides[ this.current ].timeout != 'undefined') {
      timeout = this.slides[ this.current ].timeout;
    } else {
      timeout = this.timeout;
    }
    this.timeoutid = setTimeout( this.name + ".loop()", timeout);
  }

  //--------------------------------------------------
  this.pause = function() {
    if (this.timeoutid != 0) {
      clearTimeout(this.timeoutid);
      this.timeoutid = 0;
    }
  }

  //--------------------------------------------------
  this.update = function() {
    if (typeof this.pre_update_hook == 'function') {
      this.pre_update_hook();
    }
    var slide = this.slides[ this.current ];
    var dofilter = false;
    if (this.image &&
        typeof this.image.filters != 'undefined' &&
        typeof this.image.filters[0] != 'undefined') {

      dofilter = true;
    }

    slide.load();
    if (dofilter) {
      if (slide.filter &&
          this.image.style &&
          this.image.style.filter) {
        this.image.style.filter = slide.filter;
      }
      this.image.filters[0].Apply();
    }

    this.image.src = slide.image.src;
    if (dofilter) {
      this.image.filters[0].Play();
    }

    this.display_text();
    if (typeof this.post_update_hook == 'function') {
      this.post_update_hook();
    }
  }

  //--------------------------------------------------
  this.goto_slide = function(n) {
    if (n == -1) {
      n = this.slides.length - 1;
    }
    if (n < this.slides.length && n >= 0) {
      this.current = n;
    }
    this.update();
  }


  //--------------------------------------------------
  this.next = function() {
    if (this.current < this.slides.length - 1) {
      this.current++;
    } else {
      this.current = 0;
    }
    this.update();
  }


  //--------------------------------------------------
  this.previous = function() {
    if (this.current > 0) {
      this.current--;
    } else {
      this.current = this.slides.length - 1;
    }  
    this.update();
  }


  //--------------------------------------------------
  this.display_text = function(text) {
	var temp = this.slides[this.current].link;
	for(var i = 1; i < 9; i++) {
		this.getElementById("slide-cell"+i).style.backgroundImage = 'url(img_home/slide-item.gif)';
		this.getElementById("slide-link"+i).style.color = '#2E368F';
	}
	this.getElementById("slide-cell"+temp).style.backgroundImage = 'url(img_home/slide-item-hover.gif)';
	this.getElementById("slide-link"+temp).style.color = '#721113';
	this.getElementById("slide-text").innerHTML = this.getElementById("desc"+temp).innerHTML;
  }

  this.golink = function() {
  	window.location.href = "app_industry.php?id=" + this.slides[this.current].link;
  }

  //==================================================
  // Private methods
  //==================================================

  //--------------------------------------------------
  this.loop = function() {
    if (this.current < this.slides.length - 1) {
      next_slide = this.slides[this.current + 1];
      if (next_slide.image.complete == null || next_slide.image.complete) {
        this.next();
      }
    } else {
      this.next();
    }
    this.play( );
  }


  //--------------------------------------------------
  this.getElementById = function(element_id) {
    if (document.getElementById) {
      return document.getElementById(element_id);
    }
    else if (document.all) {
      return document.all[element_id];
    }
    else if (document.layers) {
      return document.layers[element_id];
    } else {
      return undefined;
    }
  }
  
}
