// <script language="jscript">
/*
	globals
*/

var garrOnLoadEvents = new Array;

/*
	classes
*/

function clsPreLoader () {
	/*
		manages image preloading
		call initPreLoader() to instantiate this class
	*/
	this._timer = null;
	this.add = fxAdd;
	this.currentImage = -1;
	this.item = new Array;
	this.update = fxUpdate;
	if (isEmpty(document.preloads)) {
		document.preloads = new Array;
	}   // if
	/*
		members
	*/
	function fxAdd (strSrc) {   // member of clsPreLoader
		var i;
		i = this.item.length;
		document.preloads[i] = new Image;
		this.item[i] = new clsImage(document.preloads[i], strSrc);
		// if 1st img, start timer
		if (i == 0) {
			this._timer = window.setInterval("document.preloader.update()", 100);
		}   // if
		return(i);
	}   // fxAdd
	
	function fxUpdate () {   // member of clsPreLoader
		/*
			checks readyStates of images in queue
			& advances to next image for loading
		*/
		var strImgReadyState;
		/*
		// ===================================================
		if (isEmpty(fxUpdate.counter)) {
			fxUpdate.counter = 1;
		} else {
			fxUpdate.counter++;
		}
		window.status = "fxUpdate.counter==" + fxUpdate.counter;
		// ===================================================
		*/
		if (this.currentImage == -1) {
			this.currentImage++;
			this.item[0].load();
		}
		if (this.currentImage > this.item.length - 1) {
			window.clearInterval(this._timer);
		} else {
			strImgReadyState = document.preloads[this.currentImage].readyState;
			switch (strImgReadyState) {
				case "complete" :
					this.currentImage++;
					if (this.currentImage < this.item.length) {
						this.item[this.currentImage].load();
					}   // if
					break;
				default :
					break;
			}   // switch
		}   // if
		return(strImgReadyState);
	}   // fxUpdate
	
	function clsImage (image, strSrc) {   // member of clsPreLoader
		this.image = image;
		this.load = fxLoad;
		this.readyState = new clsReadyState(this.image);
		this.src = strSrc;
		/*
			members
		*/
		function fxLoad () {   // member of clsImage
			this.image.src = this.src;
		}   // fxLoad
		
		function clsReadyState (image) {   // member of clsImage
			this.get = fxGet;
			this.image = image;
			/*
				members
			*/
			function fxGet () {   // member of clsReadyState
				return(this.image.readyState);
			}   // fxGet
		}   // clsReadyState
	}   // clsImage
}   // clsPreLoader

/*
	functions
*/
function addBodyOnLoadEvent (strFx) {
	/*
		appends to array of functions to exec on body load
	*/
	garrOnLoadEvents[garrOnLoadEvents.length] = strFx;
}   // addBodyOnLoadEvent

function doBodyOnLoad () {
	/*
		execs all methods queued with addBodyOnLoadEvent()
	*/
	var i;
	for (i = 0; i < garrOnLoadEvents.length; i++) {
		eval(garrOnLoadEvents[i]);
	}   // for
}   // doBodyOnLoad

function firstChar (s) {
   /*
      returns the first character of string s
   */
   var c;
   if (notEmpty(s)) {
      c = s.charAt(0);
   } else {
      c = "";
   }   // if
   return(c);
}   // firstChar

function initPreLoader () {
	/*
		sets up the document image preloader
	*/
	document.preloader = new clsPreLoader();
}   // initPreLoader

function isEmpty (x) {
   if (x == null) { return(true); }
   if (typeof(x) == "object") { return(false); }
   if ((typeof(x) == "boolean") && (x == false)) { return(false); }
   if (x == "undefined") { return(true); }
   if (typeof(x) == "number") { return(false); }
   if (x == "") { return(true); }
   return(false);
}   // isEmpty

function lastChar (s) {
   /*
      returns the last character of string s
   */
   var c;
   if (notEmpty(s)) {
      c = s.charAt(s.length - 1);
   } else {
      c = "";
   }
   return(c);
}   // lastChar

function makeAttrib (strName, strValue) {
	var strResult;
	strResult = "";
	if (isEmpty(strName) || isEmpty(strValue)) {
		strResult = "";
	} else {
		strValue = quote(strValue);
		strResult = " " + strName + "=" + strValue;
	}   // if
	return(strResult);
}   // makeAttrib

function makeTag (strTag, strText) {
   var strResult, i;
   strText = trim(strText);
   strTag = trim(strTag);
   strResult = "<" + strTag;
   for (i = 2; i < makeTag.arguments.length; i += 2) {
		strResult += makeAttrib(makeTag.arguments[i], makeTag.arguments[i + 1]);
   }
   strResult += ">" + strText + "</" + strTag + ">";
   return(strResult);
}   // makeTag

function notEmpty (x) {
   return(!isEmpty(x));
}   // notEmpty

function quote (s) {
	/*
		returns s enclosed in quotes
	*/
	var qq;
	qq = "\"";
	// force s to string data type
	s = ("" + s);
	if (firstChar(s) != qq) {
		s = qq + s;
	}
	if (lastChar(s) != qq) {
		s += qq;
	}
	return(s);
}   // quote

function trim (s) {
   /*
      trims leading & trailing space from a string "s"
   */
   var c;
   // force s to string
   s = ("" + s);
   if (notEmpty(s)) {
      c = s.charAt(0);
      while (c == " ") {
         s = s.substr(1);
         c = s.charAt(0);
      }
      c = s.charAt(s.length-1);
      while (c == " ") {
         s = s.slice(0,-1);
         c = s.charAt(s.length-1);
      }
   }   // if
   return(s);
}   // trim

/*
	classes
*/

function clsProp (vntInitValue) {
	this.get = fxGet;
	this.set = fxSet;
	this._theValue = vntInitValue;
	/*
		members
	*/
	function fxGet () {
		return(this._theValue);
	}   // fxGet
	
	function fxSet (vntNewValue) {
		this._theValue = vntNewValue;
		return(this.get());
	}   // fxSet
}   // clsProp
