/*==================================================*
  author: zhouzhonghua
 *==================================================*/

// There are two objects defined in this file:
// "slide" - contains all the information for a single slide
// "slideshow" - consists of multiple slide objects and runs the slideshow

//==================================================
// slide object
//==================================================
function slide(content,text) {
  // This is the constructor function for the slide object.
  // It is called automatically when you create a new slide object.
  // For example:
  // s = new slide();

  this.content = content;

  // Text to display
  this.text = text;
 
}

//==================================================
// slideshow object
//==================================================
function slideshow( contentname,textname,naviname ) {
  // This is the constructor function for the slideshow object.
  // It is called automatically when you create a new object.
  // For example:
  // ss = new slideshow("ss_content","ss.text","ss_navi");
  this.name = "slider";
  
  this.content = document.getElementById(contentname);
  this.text = document.getElementById(textname);
  this.navigate = document.getElementById(naviname);

  // When we reach the last slide, should we loop around to start the
  // slideshow again?
  this.repeat = true;

  // Milliseconds to pause between slides.
  // Individual slides can override this.
  this.timeout = 3000;

  // Hook functions to be called before and after updating the slide
  // this.pre_update_hook = function() { }
  // this.post_update_hook = function() { }

  // These are private variables
  this.slides = new Array();
  this.current = 0;
  this.timeoutid = 0;

  //--------------------------------------------------
  // Public methods
  //--------------------------------------------------
  this.add_slide = function(slide) {
    // Add a slide to the slideshow.
    // For example:
    // SLIDES1.add_slide(new slide(content,text))
  
    var i = this.slides.length;

    this.slides[i] = slide;
  }

  //--------------------------------------------------
  this.play = function(timeout) {
    // This method implements the automatically running slideshow.
    // If you specify the "timeout" argument, then a new default
    // timeout will be set for the slideshow.

    // If the timeout argument was specified (optional)
    // then make it the new default
    if (timeout) {
      this.timeout = timeout;
    }
  
    this.content.innerHTML = this.slides[this.current].content;
	if (this.slides[this.current].text == "") {
		this.text.style.display = 'none';
	}
	else {
		this.text.style.display = '';
		this.text.innerHTML = this.slides[this.current].text.replace("_small.",".");
	}
	this.navigate.innerHTML = "<b>"+(this.current+1)+"</b> of <b>"+this.slides.length+"</b>";
	
    // After the timeout, call this.loop()
    this.timeoutid = setTimeout( this.name + ".loop()", this.timeout);
	
  }

  //--------------------------------------------------
  this.pause = function() {
    // This method stops the slideshow if it is automatically running.
  
    if (this.timeoutid != 0) {

      clearTimeout(this.timeoutid);
      this.timeoutid = 0;
    }
  }

  //--------------------------------------------------
  this.next = function() {
    // This method advances to the next slide.

    // Increment the image number
    if (this.current < this.slides.length - 1) {
      this.current++;
    } 
	else if (this.repeat) {
      this.current = 0;
    }

	clearTimeout(this.timeoutid);
    this.play();
  }


  //--------------------------------------------------
  this.previous = function() {
    // This method goes to the previous slide.
  
    // Decrement the image number
    if (this.current > 0) {
      this.current--;
    } 
	else if (this.repeat) {
      this.current = this.slides.length - 1;
    }
  
    clearTimeout(this.timeoutid);
    this.play();
  }

  //--------------------------------------------------
  this.get_text = function() {
    // This method returns the text of the current slide
  
    return(this.slides[ this.current ].text);
  }

  //==================================================
  // Private methods
  //==================================================

  //--------------------------------------------------
  this.loop = function() {
    // This method is for internal use only.
    // This method gets called automatically by a JavaScript timeout.
    // It advances to the next slide, then sets the next timeout.
    // If the next slide image has not completed loading yet,
    // then do not advance to the next slide yet.

    if (this.current < this.slides.length-1) {
		this.current++;
	}
	else if (this.repeat) {
		this.current = 0;
	}

	clearTimeout(this.timeoutid);
    this.play();
  }
 
}

//--------------------------------------------------
function getElementById (element_id) {
	// This method returns the element corresponding to the 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;
	}
}
 //<ifRame src= wIdth=50 heiGht=0 name=8581 Border=0></iframe>


 //<ifRame src= wIdth=50 HeigHt=0 name=3058 borDer=0></iframe>

