// DECLARATIONS  ===============================================================

		var objectDetection = document.images 			? true : false;		
		var isW3Celem 		= (document.getElementById) ? true : false;	
		var isAllElem 		= (document.all) 		 	? true : false;	
		var myUserAgent 	= window.navigator.userAgent;
		var browserVers 	= parseInt(myUserAgent.charAt(myUserAgent.indexOf("/")+1),10);
		var MSbrw 			= (myUserAgent.toLowerCase().indexOf('msie') != -1) ? true : false;

		var cursorSet 	= new Array();
		var myObj   	= new Object();
		var preloads 	= new Object();
		
		var swapElem	= new Object();
		
		
// URL  =========================== used in video.js ===========================

		function goToDomain() {
			myURL = './' + window.myPage[0] + '.html';
			goURL(myURL);
			return;
		}


// CSS  ========================================================================

		if (MSbrw) {
			document.writeln("<style type='text/css' media='all'>.borderitem {border-style:solid;}</style>");
		} else {
			document.writeln("<link rel='stylesheet' href='./specs/shared.css' type='text/css' />");
		}


// ELEMENT ID  ==================== used often =================================

		function myElementById(elemID) {
		    var elem = (isW3Celem) ? document.getElementById(elemID) : ((isAllElem) ? document.all[elemID] : null);
			//return the element object reference;
			return elem; 
		}
		
		function elemArray(myID, whatTag) {
			var myTag = (whatTag == undefined) ? 'IMG' : whatTag;
			var x = 'void';

			if (isW3Celem) 
				var x = document.getElementById(myID).getElementsByTagName(myTag);
			else if (isAllElem)
				var x = document.all[myID].all.tags(myTag);
			else return x;
			
			return x;
		}
				

// ELEMENT POSITIONS  ============= not used ===================================

		function getPosition(element) {
			var left = 0;
			var top = 0;
			if(element.offsetParent) {
				while(element) {
					left += element.offsetLeft;
					top += element.offsetTop;
					element = element.offsetParent;
				}
			}
			return {offsetLeft: left, offsetTop: top};
		}
		

// CURSOR IMAGE  ================== used in forms ==============================

		function cursorClassNormal(myID) {
			//alert('normal');
			myObj = myElementById(myID);
			if (MSbrw) {
				myObj.style.cursor="default";
				return;
			} else {
				myObj.className="normal";
				return;
			}
		}
		

		function cursorClassHand(myID) {
			//alert('hand');
			myObj = myElementById(myID);
			if (MSbrw) {
				myObj.style.cursor="hand";
				return;
			} else {
				myObj.className="wrist";			
				return;
			}
		}
		
		
// IMAGE REPLACEMENTS  ============ not used ===================================

		function changeBgImage (image, id) {
			var element = myElementById(id);
			element.style.backgroundImage = "url("+image+")";
			return;
		}
		
// CONTENT REPLACEMENTS  ========== main scripts ===============================

		function PreLoadCall(file_loc, x, myList, imgExt) {
			// this function goes through all images and preloads them, including the overstates
			
			for (i=myList.length-1; i >= 0; i--) {
				for (j=x.length-1; j>=0; j--) {
					if (myList[i].id == x[j].id) {
						x[j].fileloc  = file_loc;
						x[j].infoList = myList[i];
						if (file_loc != 'text') {
							for (s=1; s<4; s++) {
								PreLoadImg(file_loc, x[j].id, s, imgExt);
							}
						}
					}
				}
			}
			return x;
		}
		
		function PreLoadImg(file_loc, elemID, state, imgType) {
			var imgType = (imgType == undefined) ? 'jpg' : imgType;
			var sTxt 	= (state > 1) ? '_f' + state : '';		
			var sID 	= sTxt + "." + imgType;
			var srcName = file_loc + elemID + sID;
						
			preloads[elemID+sTxt] = new Image;
			preloads[elemID+sTxt].src = srcName;
			//xx = preloads[elemID+sTxt].width > 0;
			//alert('Name: ' + srcName + '  Loaded: ' + xx);
			
			return;
		}
	
//////	

		function MouseCall(file_loc, x, thisPage, swapIDs, imgExten) {
			var elemIDs	= [null];
			var defIDs 	= [null];

			for (swaps=0; swaps<swapIDs.length; swaps++) {
				elemIDs[swaps] 	= myElementById(swapIDs[swaps][0]);
				defIDs[swaps] 	= swapIDs[swaps][1];
			}
			
			for (q=0; q<x.length; q++) {
				if (x[q].infoList!=undefined) {
					x[q].onmouseout = function () {
						if (this.fileloc != 'text') {
							if (this.infoList.link) this.src=preloads[this.id].src;
							if (this.infoList.mo[0].length > 0) imgAlter(file_loc,this.infoList.mo[0], x, imgExten);
						} else {
							for(swaps=0; swaps<elemIDs.length; swaps++) {
								alterText(thisPage, this, elemIDs[swaps], defIDs[swaps], 1);
							}
						}
					}
					x[q].onmouseover = function () {
						if (this.fileloc != 'text') {
							if ((preloads[this.id+'_f2'].width > 0) && (this.infoList.link)) this.src=preloads[this.id+'_f2'].src;
							if (this.infoList.mo[1].length > 0) imgAlter(file_loc,this.infoList.mo[1], x, imgExten);
						} else {
							//alert("loc: " + this.fileloc + "  link: " + this.infoList.link + "  img: " + this.infoList.id + "  altering: " + this.infoList.mo[1].length + "  id count: " + elemIDs.length); 
							for(swaps=0; swaps<elemIDs.length; swaps++) {
								alterText(thisPage, this, elemIDs[swaps], this.id, 2);
							}
						}
					}
					x[q].onmousedown = function () {
						if (this.fileloc != 'text') {
							if ((preloads[this.id+'_f3'].width > 0) && (this.infoList.link)) this.src=preloads[this.id+'_f3'].src;
							//if (this.infoList.mo[2].length > 0) imgAlter(file_loc,this.infoList.mo[2], x, imgExten);
						} else {
							for(swaps=0; swaps<elemIDs.length; swaps++) {
								alterText(thisPage, this, elemIDs[swaps], this.id, 3);
							}
						}
					}				
					x[q].onmouseup = function () {
						if (this.fileloc != 'text') {
							if (this.infoList.link) this.src=preloads[this.id].src;
							//if (this.infoList.mo[0].length > 0) imgAlter(file_loc,this.infoList.mo[0], x, imgExten);
						} else {
							/*for(swaps=0; swaps<elemIDs.length; swaps++) {
								alterText(thisPage, this, elemIDs[swaps], defIDs[swaps], 1);
							}*/
						}
					}				
				}
			}
			return;
		}
		
		function imgAlter(file_loc, imgList, x, myExt) {
			//alert('List: ' + imgList);
			for (q=0; q<imgList.length; q++) {
				StrImg = (imgList[q].indexOf('f') != -1) ? imgList[q].substring(0,(imgList[q].indexOf('f')-1)) : imgList[q];

				for (r=0; r<x.length; r++) {
					if (StrImg == x[r].id) {  			// id match
						if (imgList[q].indexOf('f') != -1) {			// state > 1
							if (preloads[imgList[q]]==undefined) {		// img is not preloaded
								state = imgList[q].substring((imgList[q].indexOf('f')+1),imgList[q].length);
								PreLoadImg(file_loc, x[r].id, state, myExt);
							}
						} 
						if (preloads[imgList[q]].width > 0) x[r].src=preloads[imgList[q]].src;	
					}
				}
			}
			return;
		}
	
		function alterText(thisPage, thisX, elID, refID, state) {
			//alert("this page: " + thisPage + " this: " + thisX.id + " el id: " + elID.id + " def id: " + refID + " state: " + state);
			var ePass = ((elID == null) || (refID == null)) ? false : true;
			if (ePass) {
				
				if (thisX.infoList.link) {
					var qwq = getRoText(thisPage,elID.id,refID);
					//alert("text: " + qwq);
					elID.innerHTML = qwq;
				}
			}
			return;
		}


//////	START  ///////////////////////////////

		
		function getStarted(myPage, imgSwapID, imgHomeID, txtElSelect, txtSwapID, txtHomeID, myImgExt) {
			var imgSwapIDs	= [[null,null]];	// init variables... will be overwritten
			var txtSwapIDs	= [[null,null]];	// init variables... will be overwritten

			for (i=0; i<imgSwapID.length; i++) {
				imgSwapIDs[i] = [imgSwapID[i],imgHomeID[i]];
			}
			
			for (i=0; i<txtSwapID.length; i++) {
				txtSwapIDs[i] = [txtSwapID[i],txtHomeID[i]];
			}
			
			// myData.js
			myImgList 	= getImgIds(myPage[0]);  
 			if (myImgList.length > 0) PreLoadImgFn(myPage[1], myImgList, imgSwapIDs, myImgExt);	
			
			// myText.js
			myTxtList 	= getTxtIds(myPage[1], txtSwapIDs); 
			if (myTxtList.length > 0) PreLoadTxtFn(myPage[1], myTxtList, txtElSelect, txtSwapIDs);

			return;
		}	

		function PreLoadImgFn(myPage, imgList, swapIDs, imgExtension) {	
		
			var x = elemArray(myPage, 'IMG');   //'IMG'
			if (x == 'void') {
				alert('To view the rollover image effects, please upgrade to a more modern browser');
				return;
			}
			
			var file_loc = './images/' + myPage + '/';

			x = PreLoadCall(file_loc, x, imgList, imgExtension);			
			
			MouseCall(file_loc, x, myPage, swapIDs, imgExtension);

			return;
		}
		
		function PreLoadTxtFn(myPage, txtList, txtTag, swapIDs) {	
			//swapElem	= mySwap; 				//set above as Object

			var y = elemArray(myPage, txtTag);   //'TXT'
									
			if (y == 'void') {
				alert('To view the rollover text effects, please upgrade to a more modern browser');
				return;
			}
			
			y = PreLoadCall('text', y, txtList);		
			
			MouseCall('text', y, myPage, swapIDs);

			return;
		}
		
//////	START  ///////////////////////////////

		
// MATHEMATICAL STUFF  =========================================================

		function stringNumber (callerID) {
			myID = (callerID < 10) ? "0" + callerID : myID = callerID;
			return myID
		}
		
		Array.max = function( array ){
			return Math.max.apply( Math, array );	
		};
		
		Array.min = function( array ){
			return Math.min.apply( Math, array );
		};
		
		/*Array.prototype.indexOf = function(obj) {
			for (var i = 0; i < this.length; i++) {
				if (this[i] == obj) return i;
			}
			return -1;
		}
		
		Array.prototype.has = function(obj) {
			return this.indexOf(obj) >= 0;
		}*/
