
function Slideshow(){
	this.FADE_DELTA= 3;				// The geometric rate of fade-in change (2-10 is good)
	this.FADE_INTERVAL= 200; 		// Time interval between fading steps (milliseconds)
	this.NEXT_ITEM_INTERVAL= 2000;  // Time interval between when an item is 100% and when it goes blank
	this.CLEAR_DURATION= 400;		// Time interval between items (while blank)	
	this.autoAnimTimer= null;		// The timing object
	this.imgIndex= 0;					// Index of the current headline


	//Property setters. No getters; adds overhead, no need.
	Slideshow.prototype.setPlaceholder= function(placeholder){
		this.placeholder= placeholder;
	}

	Slideshow.prototype.setImages= function(images){
		this.images= images;
	}

	Slideshow.prototype.setNextButtonId= function(nextButtonId){
		this.nextButtonId= nextButtonId;
	}

	Slideshow.prototype.setPreviousButtonId= function(previousButtonId){
		this.previousButtonId= previousButtonId;
	}
	
	Slideshow.prototype.setContainerId= function(containerId){
		this.containerId= containerId;
	}
	
	Slideshow.prototype.getContainer= function(){
		return (document.getElementById(this.containerId));
	}

	//loop does the actual fading
	Slideshow.prototype.fadeIn= function (){
		var o= this.getOpacity();
		var delta= (this.getMaxOpacity()- o)/ this.FADE_DELTA;
	
		if(delta > .009){
			this.setOpacity(delta);
		 	this.autoAnimTimer= setTimeout('slideshow.fadeIn()', this.FADE_INTERVAL);
		} else{
			this.autoAnimTimer= setTimeout('slideshow.clearImage();', this.NEXT_ITEM_INTERVAL);
		}
	}

	// clears the current item, makes for a nice pause in between
	Slideshow.prototype.clearImage= function(){
		this.resetOpacity();
		this.autoAnimTimer= setTimeout('slideshow.changeImage()', this.CLEAR_DURATION);
	}

	// populate the next item
	Slideshow.prototype.changeImage= function(manual){
		this.getNextImage();
		lastIndex= (this.imgIndex-1<0) ? this.images.length-1: this.imgIndex-1;
		
		document.getElementById('th_'+lastIndex ).className= 'img0';
		document.getElementById('th_'+this.imgIndex).className= 'img1';
		
		this.imgIndex++;
	
		if(this.imgIndex> this.images.length- 1) this.imgIndex= 0;
		
		if(!manual){
			this.fadeIn();
		}
	}
	
	Slideshow.prototype.previousImage= function(manual){
		this.imgIndex-=2;
		if(this.imgIndex< -1){this.imgIndex= this.images.length-2};
		if(this.imgIndex< 0){this.imgIndex= this.images.length-1};
	
	}

	//	the manual override goes forward/back
	Slideshow.prototype.manualControl= function(direction, srcIndex){
		if(this.autoAnimTimer!= null){	
			window.clearTimeout(this.autoAnimTimer);
			this.autoAnimTimer= null;
				
			if(direction && (direction== 'stop')){
					this.revealPhoto();

				var sBtn= new Image();
					 sBtn.src= './images/btnPlay_1.gif';
				document.getElementById('btn_stop').src= sBtn.src;
					
				return;
			}
			if(direction && (direction== 'previous')){
				this.previousImage();
				this.clearImage();
			}
			if(direction && (direction== 'next')){
				this.clearImage();
			}
			if(direction && (direction== 'jump')){
				this.imgIndex= srcIndex-1;
				this.changeImage();
			}
		} 	
		else{
			if(direction && (direction== 'next')){
				this.changeImage(true);
			}
			if(direction && (direction== 'previous')){
				this.previousImage();
				this.changeImage(true);
			}
			if(direction && (direction== 'stop')){
				var sBtn= new Image();
					sBtn.src= './images/btnPause_1.gif';
				document.getElementById('btn_stop').src= sBtn.src;
				
				this.clearImage();
			}
			if(direction && (direction== 'jump')){
				this.imgIndex= srcIndex-1;
				this.changeImage(true);
			}
		}
	}
	
	Slideshow.prototype.setOpacity= function(delta){
		if(IE){
			var o= parseFloat(this.getContainer().filters.alpha.opacity);
			
			var newO= o+ (delta*100)
			this.getContainer().filters.alpha.opacity= newO;
		} else{
			var o= parseFloat(this.getContainer().style.opacity);
			this.getContainer().style.opacity= o+ delta;
		}
	}
	
	Slideshow.prototype.resetOpacity= function(){
		if(IE){
			this.getContainer().filters.alpha.opacity= 0;
		} else{
			this.getContainer().style.opacity= 0;
		}
	}
	
	Slideshow.prototype.revealPhoto= function(){
		if(IE){
			this.getContainer().filters.alpha.opacity= 100;
		} else{
			this.getContainer().style.opacity= 1;
		}
	}
	
	
	//	gets the current opacity of the item
	Slideshow.prototype.getOpacity= function(){
		var o;
		if(IE){
			o= parseFloat(this.getContainer().filters.alpha.opacity)/ 100;
		} else{
			o= parseFloat(this.getContainer().style.opacity);
		}
		return (o);
	}
	

	//	returns the correct maximum opacity setting
	Slideshow.prototype.getMaxOpacity= function(){
		return(1);
	}
	
	//	the headline html
	Slideshow.prototype.getNextImage= function(){
		var d=this.getContainer().getElementsByTagName('TD')[0];
		
		var img= this.images[this.imgIndex][1];
	
		d.innerHTML= '<img src="'+ img.src+'" />';
	}
}
