//<script language="jscript">

/*
	classes
*/
function clsShow (strContainer, fxOnStop, blnShuffled, blnRepeat) {
	/*
		show controller
	*/
	this.add = fxAdd;
	this.advanceFrame = fxAdvanceFrame;
	this.speed = new clsSpeed();
	this.container = document.all(strContainer);
	this.currentFrameIndex = new clsCurrentFrameIndex();
	this.frames = new Array;
	this.framesOrder = new Array;
	this.getCurrentFrame = fxGetCurrentFrame;
	this.getNextFrame = fxGetNextFrame;
	this.getPreviousFrame = fxGetPreviousFrame;
	this.init = fxInit;
	this.offTime = 500;
	this.onStop = fxOnStop;
	this.pause = fxPause;
	this.previousFrame = fxPreviousFrame;
	this.randomize = fxRandomize;
	this.repeat = blnRepeat == true ? true : false;
	this.show = fxShow;
	this.shuffled = blnShuffled == true ? true : false;
	this.unPause = fxUnPause;
	if (isEmpty(document.preloader)) {
		initPreLoader();
	}   // if
	/*
		members
	*/
	function fxAdd (strContent, numOnTime, strImgSrc) {   // member of clsShow
		/*
			add new frame
			numOnTime: optional. how many seconds to show the frame. decimals are allowed.
		*/
		var objFrame, blnLiteralTime;
		if (isEmpty(numOnTime)) {
			blnLiteralTime = false;
			numOnTime = this.speed.get();
		} else {
			blnLiteralTime = true;
		}   // if
		objFrame = new clsFrame(strContent, this.container, numOnTime,
			blnLiteralTime, this.offTime, this.advanceFrame, strImgSrc);
		objFrame.init();
		this.frames[this.frames.length] = objFrame;
	}   // fxAdd
	
	function fxAdvanceFrame () {   // member of clsShow
		var myParent, theFrame;
		myParent = fxAdvanceFrame._parent;
		// make sure current frame is paused
		// (it won't be if it was manually advanced)
		theFrame = myParent.getCurrentFrame();
		theFrame.pause();
		// show next frame
		theFrame = myParent.getNextFrame();
		theFrame.show();
	}   // fxAdvanceFrame
	
	function fxGetCurrentFrame () {   // member of clsShow
		return(this.frames[this.framesOrder[this.currentFrameIndex.get()]]);
	}   // fxGetCurrentFrame
	
	function fxGetNextFrame () {   // member of clsShow
		var theFrame, i;
		i = this.currentFrameIndex.get();
		do {
			this.currentFrameIndex.increment();
			theFrame = this.getCurrentFrame();
			// following statement prevents infinite loop
			if (i == this.currentFrameIndex.get()) {
				break;
			}   // if
		} while (theFrame.readyState.get() != "complete");   // do
		return(theFrame);
	}   // fxGetNextFrame
	
	function fxGetPreviousFrame () {   // member of clsShow
		var theFrame, i;
		i = this.currentFrameIndex.get();
		do {
			this.currentFrameIndex.decrement();
			theFrame = this.getCurrentFrame();
			// following statement prevents infinite loop
			if (i == this.currentFrameIndex.get()) {
				break;
			}   // if
		} while (theFrame.readyState.get() != "complete");   // do
		return(theFrame);
	}   // fxGetPreviousFrame
	
	function fxInit () {   // member of clsShow
		this.advanceFrame._parent = this;
		this.currentFrameIndex._parent = this;
		this.speed._parent = this;
	}   // fxInit
	
	function fxPause () {   // member of clsShow
		var frameCurrent;
		frameCurrent = this.getCurrentFrame();
		frameCurrent.pause();
		window.status = "Paused";
	}   // fxPause
	
	function fxPreviousFrame () {
		var theFrame;
		// make sure current frame is paused
		// (it won't be if it was manually advanced)
		theFrame = this.getCurrentFrame();
		theFrame.pause();
		// show next frame
		theFrame = this.getPreviousFrame();
		theFrame.show();
	}   // fxPreviousFrame
	
	function fxRandomize () {   // member of clsShow
		var intFL, i, j, arrTemp, arrTempLow, arrTempHigh;
		intFL = this.frames.length;
		arrTemp = new Array;
		// re-init framesOrder
		this.framesOrder = new Array;
		for (i = 0; i < intFL; i++) {
			arrTemp[i] = i;
		}  // for
		for (i = 0; i < intFL; i++) {
			j = Math.random();
			j = j * arrTemp.length;
			j = Math.floor(j);
			this.framesOrder[i] = arrTemp[j];
			arrTempLow = arrTemp.slice(0, j);
			arrTempHigh = arrTemp.slice(j + 1);
			arrTemp = arrTempLow.concat(arrTempHigh);
		}  // for
	}   // fxRandomize
	
	function fxShow () {   // member of clsShow
		/*
			run the show
		*/
		var theFrame;
		if (this.shuffled == true) {
			this.randomize();
		}   // if
		// this.advanceFrame(true);
		theFrame = this.getCurrentFrame();
		theFrame.show();
	}   // fxShow
	
	function fxUnPause () {   // member of clsShow
		var frameCurrent;
		frameCurrent = this.getCurrentFrame();
		frameCurrent.unPause();
		window.status = STATUSTEXT;
	}   // fxUnPause
	
	function clsCurrentFrameIndex () {   // member of clsShow
		this._index = 0;
		this.decrement = fxDecrement;
		this.get = fxGet;
		this.increment = fxIncrement;
		/*
			members
		*/
		function fxDecrement () {
			this._index--;
			if (this._index < 0) {
				this._index = this._parent.frames.length - 1;
			}
		}   // fxDecrement
		
		function fxGet () {
			return(this._index);
		}   // fxGet
		
		function fxIncrement () {
			this._index++;
			if (this._index > this._parent.frames.length - 1) {
				this._index = 0;
			}
		}   // fxIncrement
	}   // clsCurrentFrameIndex

	function clsFrame (strContent, objContainer, numSpeed, blnLiteralTime, intOffTime,
		fxOnStop, strPreLoadImage) {   // member of clsShow
		/*
			frame object
		*/
		this._timer = null;
		this.container = objContainer;
		this.content = strContent;
		this.init = fxInit;
		this.hide = fxHide;
		if (blnLiteralTime == true) {
			this.literalTime = true;
		} else {
			this.literalTime = false;
		}   // if
		this.offTime = intOffTime;
		this.onStop = fxOnStop;
		this.onTime = new clsOnTime(numSpeed, blnLiteralTime);
		this.pause = fxPause;
		this.paused = new clsProp(false);
		this.show = fxShow;
		this.unPause = fxUnPause;
		if (notEmpty(strPreLoadImage)) {
			this.imageID = document.preloader.add(strPreLoadImage);
			this.readyState = new clsReadyState(this.imageID);
		} else {
			this.readyState = new clsReadyState(null);
		}   // if
		/*
			members
		*/
		function clsReadyState (imageID) {   // member of clsFrame
			/*
				readyState values can be:
					uninitialized
					loading
					interactive
					complete
			*/
			this.get = fxGet;
			this.img = document.preloader.item[imageID];
			/*
				members
			*/
			function fxGet () {   // member of clsReadyState
				var strResult;
				if (isEmpty(this.img)) {
					strResult = "complete";
				} else {
					strResult = this.img.readyState.get();
				}   // if
				return(strResult);
			}   // fxGet
		}   // clsReadyState
		
		function fxHide () {   // member of clsFrame
			/*
				blanks screen for offTime
			*/
			objContainer.innerHTML = "&nbsp;";
			this._timer = window.setTimeout(fxHide._parent.onStop, fxHide._parent.offTime);
		}   // fxHide
		
		function fxInit () {   // member of clsFrame
			this.hide._parent = this;
			this.onTime._parent = this;
		}   // fxInit
		
		function fxPause () {   // member of clsFrame
			window.clearTimeout(this._timer);
			this.paused.set(true);
		}   // fxPause

		function fxShow () {   // member of clsFrame
			/*
				show the frame
				<table BORDER="1" CELLSPACING="0" CELLPADDING="50" bordercolor="gray">
					<tr VALIGN="MIDDLE">
						<td CLASS="quotation" valign="top">[CONTENT]</td>
					</tr>
				</table>
			*/
			var strOutput, numTime;
			if (this.literalTime == true) {
				numTime = 1000 * this.onTime.get();
			} else {
				numTime = 50 * this.onTime.get() * this.content.length;
			}   // if
			strOutput = makeTag("td", this.content);
			strOutput = makeTag("tr", strOutput);
			strOutput = makeTag("table", strOutput, "class", "quotation");
			objContainer.innerHTML = strOutput;
			this._timer = window.setTimeout(this.hide, numTime);
		}   // fxShow
		
		function fxUnPause () {
			this.paused.set(false);
			this.hide();
		}   // fxUnPause

		function clsOnTime (numSpeed) {   // member of clsFrame
			/*
				property: how long a frame is shown
				default value is 1.
				The timer is set to 50 miliseconds * this number * characters in the frame contents.
			*/
			this.get = fxGet;
			this.set = fxSet;
			this._theValue = numSpeed;
			/*
				members
			*/
			function fxGet () {
				return(this._theValue);
			}   // fxGet
	
			function fxSet (numNewValue) {
				this._theValue = numNewValue;
				return(this.get());
			}   // fxSet
		}   // clsOnTime
	}   // clsFrame
	
	function clsSpeed () {   // member of clsShow
		/*
			controls frame speed
		*/
		this.get = fxGet;
		this.set = fxSet;
		this._theDefaultValue = 1;
		this._theValue = 1;
		/*
			members
		*/
		function fxGet () {
			return(this._theValue);
		}   // fxGet
	
		function fxSet (vntNewValue) {
			var i, theFrame;
			this._theValue = vntNewValue;
			for (i = 0; i < this._parent.frames.length; i++) {
				theFrame = this._parent.frames[i];
				if (theFrame.literalTime == true) {
					theFrame.onTime.set(this.get() * theFrame.onTime.get());
				} else {
					theFrame.onTime.set(this.get());
				}   // if
				window.status = "Speed: " + Math.floor((1 / this.get()) * 100);
			}   // for
			return(this.get());
		}   // fxSet
	}   // clsSpeed
}   // clsShow
