
var isNav4, isNav6, isIE4, isIE5Mac;

/*
 *  Random Image
 */
function randImage(aOptionsArray) 
{
	vImageNum = Math.floor(Math.random()*(aOptionsArray.length));	
	
	// set the background color
	if (document.styleSheets) {
		document.body.style.background = aOptionsArray[vImageNum][1];	
	}
	// set the background pic
	//setIdProperty( "headerPic", "backgroundImage", "url(images/menu/" + aOptionsArray[vImageNum][0] + ".jpg)" );
	//setIdProperty( "tabBlock", "backgroundImage","url(images/menu/" + aOptionsArray[vImageNum][0] + "-menu.jpg)" );				
	
	return( aOptionsArray[vImageNum][0] );
}
 
 
/* 
 * RollOver Effects
 */
var gActivePage;
 
// Handle the rollover events
function mapOver(aWho, aState) 
{
	if (gActivePage != aWho) {
		if (aState) {
			btFader(aWho + "Tab", "backgroundColor", [255], [228], 
						'"rgb(" + vCurrentNum[0] +","+ vCurrentNum[0] +","+ vCurrentNum[0] +")"', "");
		}
		else {
			btFader(aWho + "Tab", "backgroundColor", [228], [255], 
						'"rgb(" + vCurrentNum[0] +","+ vCurrentNum[0] +","+ vCurrentNum[0] +")"', "");
		}
	}
}
	
function mapIn()
{
	mapOver(this.id, 1);
}
function mapOut()
{
	mapOver(this.id, 0);
}

function initRollovers()
{	
	vButtonList  = new Array( "index",  "games", "bios", "tools");

	for (i = 0; i < vButtonList.length; i++) {
		vButton = getObject(vButtonList[i]);
		if (!isW3C) 
		{
			setIdProperty( vButtonList[i] + "Tab", "visibility", "hidden" ); // Hide from IE4
		}
		else 
		{
			vButton.onmouseover = mapIn;
			vButton.onmouseout = mapOut;
		}
	}
	
	if (gActivePage != "") 
		btFader(gActivePage + "Tab", "backgroundColor", [255], [228], 
			'"rgb(" + vCurrentNum[0] +","+ vCurrentNum[0] +","+ vCurrentNum[0] +")"', "");
}

// ---

/* 
 * Fades: A general interpolation script.
*/
	var gFaderList = new Array();
	var gIsFading = false;
	var fadespeed = 25;
	 
	function btFader( aWho, aWhat, aFromNum, aToNum, aCommand, aDoneCommand ) {
		
		vCheck = checkFaders(aWho);
		if ( vCheck > -1 ) { 
			gFaderList[vCheck].pFromNum = gFaderList[vCheck].pCurrentNum
			gFaderList[vCheck].pToNum = aToNum;
			gFaderList[vCheck].pPerc = 0;
			gFaderList[vCheck].pCommand = aCommand; 
			gFaderList[vCheck].pDoneCommand = aDoneCommand;
		}
		else {
			gFaderList[gFaderList.length] = new makeFader(aWho, aWhat, aFromNum, aToNum, aCommand, aDoneCommand );
			
			if (gIsFading == false) { 
				setTimeout('updateFader()', fadespeed); 
				gIsFading = true;
			}
			
		}
	}

	/* 
	 * Make a fader Object
	 */
	function makeFader( aWho, aWhat, aFromNum, aToNum, aCommand, aDoneCommand )
	{
		this.pWho = aWho;
		this.pWhat = aWhat;
		this.pFromNum = aFromNum;
		this.pToNum = aToNum;
		this.pPerc = 0;
		this.pCurrentNum = aFromNum; 
		this.pCommand = aCommand; 
		this.pDoneCommand = aDoneCommand;
		 
		return this;	
	}

	/* 
	 * Do the fading.
	 */
	function updateFader() {
		if ( gFaderList.length > 0 ) { 
			
			vLen = gFaderList.length - 1;
			for ( iFader = vLen; iFader > -1; iFader-- ) {
							
				with( gFaderList[iFader] ) {
					if ( pPerc < 100 ) {
						pPerc += 2;
						
						vMultiplier = pPerc/100;
//						vMultiplier = Math.sin(Math.PI*(pPerc/100)*.5);
						
// 						vCurrentNum = Math.round(pToNum*vMultiplier + pFromNum*(1-vMultiplier));
// 						pCurrentNum = vCurrentNum;
						
						vLength = pFromNum.length
						vCurrentNum = new Array(vLength);
						for ( i = 0; i < vLength; i++) {
							vCurrentNum[i] = Math.round(pToNum[i]*vMultiplier + pFromNum[i]*(1-vMultiplier));
							pCurrentNum[i] = vCurrentNum[i];
						}
											
						//status = eval( pCommand );
						setIdProperty( pWho, pWhat, eval( pCommand ) ); 
					}
					else {
						if ( pDoneCommand )  eval( pDoneCommand );
						gFaderList = DeleteEntry(gFaderList, iFader);
					}
				}
			}
			
			setTimeout('updateFader()', fadespeed);
		} 
		else { gIsFading = false; }

	}

	/* 
	 * Check if an object is already fading
	 */
	function checkFaders(aWho) {
		for( iFader in gFaderList) {
			if(  gFaderList[iFader].pWho == aWho ) {
				return iFader;
			}
		}
		
		return -1;
	}	
	
	/* 
	 * Delete a fader from the list. 
	 */
	function deleteFader(aWho) {
		vCheck = checkFaders(aWho);
		if ( vCheck > -1 ) { 
			gFaderList = DeleteEntry(gFaderList, vCheck);
		}
	}	

	

/* 
 * Goto a URL
 */
function go(aWhere) { window.location = aWhere + ".html" } 

/* 
 * Delete Entry from an Array
 */
function DeleteEntry(MyArr, Entry)
{
   var count=0;
   var TmpArr = new Array()
   for(i=0;i<MyArr.length;i++)
      if(i!=Entry)
         TmpArr[count++] = MyArr[i];
   return TmpArr;
}


/* 
 *Easy Object Detection Utility -- developer.apple.com
 */
var isW3C = (document.getElementById) ? true : false
var isAll = (document.all) ? true : false

function getObject(elemID) {
    var elem = (isW3C) ? document.getElementById(elemID) : ((isAll) ? document.all[elemID] : null);
    return elem;
}


/* AListApart.com DOM Utilities
 *
 * Browser version snooper; determines your browser
 * (Navigator 4, Navigator 6, or Internet Explorer 4/5)
 */
function setBrowser()
{
    if (navigator.appVersion.charAt(0) == "4")
    {
        if (navigator.appName.indexOf("Explorer") >= 0)
        {
            isIE4 = true;
        }
        else
        {
            isNav4 = true;
        }
    }
    else if (navigator.appVersion.charAt(0) > "4")
    {
        isNav6 = true;
    }
    
    isIE5Mac = ((navigator.userAgent.indexOf("MSIE 5.") != -1) && (navigator.userAgent.indexOf("Mac") != -1));
    //alert("Nav6:" + isNav6 + "  ie4:" + isIE4 );

}

/*
 *
 * Given an id and a property (as strings), set
 * the given property of that id to the value provided.
 *
 * The property is set directly on the tag, not in the
 * stylesheet.
 *
 */
function setIdProperty( id, property, value )
{
    if (isW3C)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
    }
    else if (isNav4)
    {
        document[id][property] = value;
    }
    else if (isIE4)
    {
         document.all[id].style[property] = value;
    }
  
}

setBrowser();


// Function To remove IE annoying dotted line. -- http://www.1choice.co.uk/codebank/remove_ie_linkborder.htm
function ExplorerFix()
{
	for (a in document.links) document.links[a].onfocus = document.links[a].blur;
}

if (document.all)
{
	document.onmousedown = ExplorerFix;
}

// Wacky Testing

// window.onload = function() { 
// 	document.onkeydown = keyHandler;	
// 	//document.onkeyup = keyHandler; 
// }

// function keyHandler(e)
// {
// 	if (!e) e = window.event;
// 	pressedCharacter = String.fromCharCode(e['keyCode']);
// 	//alert(pressedCharacter);
// 	if (pressedCharacter == "W") { imageheighttestingtesting(-10); }
// 	if (pressedCharacter == "S") { imageheighttestingtesting(10); }
// 	if (pressedCharacter == "Q") { imageheighttestingtesting(220 - pHeaderHeight); }
// 	if (pressedCharacter == "E") { alert(pHeaderHeight); }
// }

// pHeaderHeight = 220;

// function imageheighttestingtesting(vAmount) 
// {
// 	pHeaderHeight = pHeaderHeight + vAmount;
// 	setIdProperty( "headerpic", "height", pHeaderHeight );
// }
