
/***
  * Globals
  */
var JS_SLIDESHOW_LOADED = true;     	
var JS_SLIDESHOW_FILE = 'slideshow.js';			
var JS_SLIDESHOW_VERSION = '0.1';
var JS_SLIDESHOW_BUILD_DATE = '2005/09/12';


/***
   * Parenting
   */
SlideShow.prototype = new Gallery();
SlideShow.prototype.constructor = SlideShow;
SlideShow.superclass = Gallery.prototype; // TODO ? why is this needed ?

/***
   * Slideshow
   */
function SlideShow( opts )
{
	if (JS_GALLERY_LOADED == undefined) {
		// warn - gallery not loaded
		return 0; }
	
	this.init( opts ); // init using Gallery superclass

	// defaults
	this.options.interval = 500; 
	
}

	
	
/***
  * decrease_speed: increasing the speed of the gallery by decreasing the time between the setInterval call. 
  */  
 SlideShow.prototype.decrease_interval = function ( interval_int )
 	{
		if ( ( this.options.interval - interval_int ) < 99 )
  			return false;
			// too slow
		
		this.set_interval( this.options.interval - interval_int );	
		return true;					
	}


/***
  * increase_speed: decreasing the speed of the gallery by increasing the time between the setInterval call. 
	*/  
 SlideShow.prototype.increase_interval = function ( interval_int )
 	{	
		this.set_interval( this.options.interval + interval_int );
		return true;
	}

	
/***
  * play: 
  */
SlideShow.prototype.play = function ( )  //TODO - pass arg, 'times' 1 = play once, 
	{
		if ( this.slideshow_ref != undefined )
		 	this.stop(); // stop any existing thing first, partly UI a responsibility too
		var self = this;  // dereference 'this' to retain object scope upon setinterval event
		this.slideshow_ref = window.setInterval( function() { self.next(); }, this.options.interval ); // instance setinterval with self reference
		// this method is in homage to - http://www.codingforums.com/archive/index.php/t-10531.html		
		
	  	return true;
	}


/***
  * play_random: 
  */
SlideShow.prototype.play_random = function ( ) 	
	{
	var self = this;
	this.slideshow_ref = window.setInterval( function() { self.go_to_random(); }, this.options.interval );	
	}
	
	
/***
  * set_interval: 
  */
 SlideShow.prototype.set_interval = function ( interval_int )
 	{	
		if ( isNaN( interval_int ) || interval_int < 1 )
			return false;
			
		this.options.interval = interval_int;

		if ( this.slideshow_ref != undefined )
		{
			this.stop();
			this.play();
		}
		
	 	return true;
	}

	
/***
  * stop: 
  */
 SlideShow.prototype.stop = function ( )
 	{
		this.slideshow_ref = window.clearInterval( this.slideshow_ref );
 		this.slideshow_ref = undefined;
	 	return true;
	}

