// JavaScript Document
function Slide(imageFilename, delay, transitionEffectId, link, linkText) {
	// properties:
	this.image = new Image();
	this.image.src = imageFilename;
	this.delay = delay;

	if (transitionEffectId == -1) {
		this.transition = -1;
	}
	if (transitionEffectId == -2) {
		this.transition=-2;
	}
	else if (transitionEffectId >= 0 && transitionEffectId < Slide.prototype.numFilters) {
		this.transition = Slide.prototype.filters[transitionEffectId];
		//alert(this.transition);
	}

	this.link = link;
	this.linkText = linkText;
	
	// functions to 
	this.isReady = function() {
		return this.image.complete;
	};

	// returns the current filter and rotates filter 
	this.getFilter = function() {
		// -1 indicates no filter
		if (this.transition == -1)
			return 0;
		//  -2 indicates use any
		if (this.transition && this.transition != -2)
			return this.transition;
	
		Slide.prototype.currentFilter++;
		if (Slide.prototype.currentFilter > Slide.prototype.numFilters)
	 		Slide.prototype.currentFilter = 0;
		return Slide.prototype.filters[Slide.prototype.currentFilter];
	};
	
	// returns the number of miliseconds of the delay value specified
	this.getDelay = function(){return this.delay*1000;};
	this.getImage = function(){return this.image;};
	this.getImageWidth = function(){return this.image.width;};
	this.getImageHeight = function(){return this.image.height;};
	this.getImageSrc = function(){return this.image.src;};
	this.getSize = function(){return this.size;};
	this.getLink = function(){return this.link;};
	this.getLinkText = function() {
		if (this.linkText == "")
	   	return "&nbsp;";
	  	return this.linkText;
	};
   // increment counter (counts how many slides there are)
	Slide.prototype.size++;	   
}

// Static method.  It increments static variables "numFilters" and stores filters in "filters" static array
Slide.prototype.addFilter=function(filter){
	Slide.prototype.filters[Slide.prototype.numFilters++]=filter
};
// how fast or slow the transition animation will play (in seconds)
var transitionSpeed = 2;
var slides = new Array();
var curImage = -1;
// NO NEED TO CHANGE THIS PORTION
Slide.prototype.transitionSpeed=transitionSpeed;				// seconds
Slide.prototype.size=0;
Slide.prototype.numFilters=0;
Slide.prototype.currentFilter=0;
Slide.prototype.filters=new Array();
//********************************************
// LIST OF TRANSITIONS
// you may take out the ones you don't want to use or add more.
//*******************************************
Slide.prototype.addFilter("blendTrans(duration="+transitionSpeed+");");					  // 0 fade
Slide.prototype.addFilter("revealTrans(transition=5, duration="+transitionSpeed+");");  // 1 wipe down
Slide.prototype.addFilter("revealTrans(transition=0, duration="+transitionSpeed+");");  // 2 Box In
Slide.prototype.addFilter("revealTrans(transition=1, duration="+transitionSpeed+");");  // 3 Box Out
Slide.prototype.addFilter("revealTrans(transition=2, duration="+transitionSpeed+");");  // 4 Circle in
Slide.prototype.addFilter("revealTrans(transition=3, duration="+transitionSpeed+");");  // 5 Circle out
Slide.prototype.addFilter("revealTrans(transition=10, duration="+transitionSpeed+");"); // 6 Horizontal Checkerboard
Slide.prototype.addFilter("revealTrans(transition=11, duration="+transitionSpeed+");"); // 7 Vertical Checkerboard
Slide.prototype.addFilter("revealTrans(transition=12, duration="+transitionSpeed+");"); // 8 Dissolve
Slide.prototype.addFilter("revealTrans(transition=4, duration="+transitionSpeed+");");  // 9 Wipe up
Slide.prototype.addFilter("revealTrans(transition=20, duration="+transitionSpeed+");"); // 10 Strips
Slide.prototype.addFilter("revealTrans(transition=14, duration="+transitionSpeed+");"); // 11 Barn
Slide.prototype.addFilter("revealTrans(transition=21, duration="+transitionSpeed+");"); // 12 horizontal lines

//*******************************************
// This function is the core of this application.
// It swaps the image contained in "myImage" object.
// You should therefore declare your image on the page like this:
// <IMG ID="myImage" width="0" height="0" src=""> so that 
// the first image will not be displayed.
// If you wish to set an initial image, you can use
// <IMG ID="myImage" src=imageName>.
//
// Calling method: uses "setTimeout()" to call itself
// periodically depending on
// the delay value specified on each picture.
// If the picture to be displayed has not been loaded yet,
// the function will call itself every 0.5 seconds
// until the picture is loaded.  
//********************************************
function slidePicture() {
	if (document.images) {
		var oldCurImage = curImage;
		curImage++;
		if (curImage >= slides[0].getSize()) {
			curImage = 0;
		}
		var canBeFiltered = false;
		if (document.images[page]) { // && 
  			target=document.images[page];
  		   if (document.images[page].style) { // && document.images['home'].style.filters)
				canBeFiltered=true;
			}
		}
		if (document.all && document.getElementById(page)) {
			target = document.getElementById(page);
			// If the browser doesn't support "style" or
			// if user specified filter value of 0, then do not use filter
			if (target.style && slides[curImage].getFilter()!=0)
				canBeFiltered = true;
		}

       // 	Check if the next image is loaded yet.
       // Note here, if you put an invalid filename on
       // your list, the slide might get stuck here,
       // So make sure all the image filenames are
       // correct.
		if (slides[curImage].isReady())
		{
			if (canBeFiltered)
			{
      			target.style.filter=slides[curImage].getFilter();
      			if (target.filters && target.filters[0])
      			{
		       	target.filters[0].Apply();
		       }
 	       }
 	       
			target.src=slides[curImage].getImageSrc();
			// netscape 4.8 doesn support these, so you might want to use
			// same sized image if you want it to look nice on that browser
			target.height=slides[curImage].getImageHeight();
			target.width=slides[curImage].getImageWidth();
			
			// chane link text
			if (document.getElementById && document.getElementById("myImageLink"))
 				document.getElementById("myImageLink").innerHTML=slides[curImage].getLinkText();
 				
			if (canBeFiltered) {
				if (target.filters && target.filters[0]) {
	  		   	target.filters[0].Play();
				}
			}
			// This basically says:
			// Execute this function again after showing
			// the image for the time specified in the delay.
			setTimeout("slidePicture()", slides[curImage].getDelay());
		}	
		// Next image is not loaded yet, restore counter
		// and check back in 500 miliseconds
		else {
			curImage = oldCurImage;
			setTimeout("slidePicture()", 500);
		}
	}
}