/******************************************************************************************************
*Mod  - Oct 19, 2009:
*		Added the feature that the credit is also faded. The Slideshow Object has two added properties
*		that indicate the start and end opacity value for the credit.
*
*
*Mod - Dec 2, 2009:  All data will be handled in point units
*******************************************************************************************************/
var goldenrod
if (!goldenrod) goldenrod = {}





/******************************************************************************************************
*This is a Event Show data class.
*self  = String that is the name of the instance of the object
*eventlist = is an array of occurence Objects 
*i = the index of the current event being processed in eventlist.
*******************************************************************************************************/
goldenrod.Eventshow = function(self, eventlist, eventNum, totalTime, loopNum) {
	this.self = self;
	this.eventList = eventlist;
	this.i = eventNum || 0;		//index for pending event
	this.first = eventNum || 0;	//index of first event
	this.totalTime = totalTime || 0;			//Total time that has past since last event started.
	this.loopNum = loopNum;		//If loopNum = -1 then loop forever
	this.loopCount = 0;
}


/******************************************************************************************************
*This function actually runs an event show.
*It is given one parameter: an Eventshow Object. 
*Note - totalTime and loopCount must always be reset to 0 if this function is explicitly 
*		invoked more than once.
*
*Count - when count is 0 we do not play the event but it will still hold a place in time in the 
*		Event string - because the timing of subsequent events depends on the event before.
*******************************************************************************************************/
goldenrod.Eventshow.prototype.run = function() {
	var returnvalue = true;
	var currentEvent, currentOccurence, time, delay, count;
	//dump_properties("The properties of eventshow are", homeShow)
	
	

	while( (this.loopNum == -1) || (this.loopCount < this.loopNum) ) {	
		time = this.eventList[this.i].eventTime;	//time = time to start current event
		
				 
		
		if ((delay = time - this.totalTime) > 0 ) {	//If total time past is less than time to start
			//alert("this.totalTime = " + this.totalTime + "\n" + "time = " + time + "/n" + 
			//		"pending event (this.i) = " + this.i)
			this.totalTime = time; //Update totalTime to what it will be when we return.
			setTimeout(this.self + ".run()", delay );		//Set delay for this function
			break;	
		}
		else {
			this.totalTime = 0;	//Reset Totaltime because we are going to play the pending event.
			currentEvent = this.eventList[this.i].eventItem //Set currentEvent
			count = this.eventList[this.i].eventCount;
			if(count > 0 ) {this.eventList[this.i].eventCount--; }
			this.i++; if(this.i >= this.eventList.length) this.i = 0;
			if(count != 0) currentEvent.Play();	//play it
			if(this.i == this.first ) {
				this.loopCount++;		//increment loop count when we go back to first event.
			}
		}
			
			

	}
	
	return returnvalue
}


