// JavaScript Document
//global variables
	
var oldX=0;
var oldY=0;
	
function swapWeb(section){
	// swap the web image to show where the link is headin for this section
	var objWebImage=document.getElementById("webImage");
	objWebImage.src="../assets/images/small_webs/Web" + section + ".gif";
}

function pageHeight() {
	var myHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
    	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
    	myHeight = document.body.clientHeight;
  	}
	return myHeight
} 

function pageWidth() {
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
    	myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
    	myWidth = document.body.clientWidth;
  	}
	return myWidth
} 
	
function centerX() {
	var centerX = (pageWidth()/2)-325
	return centerX
}

function centerY() {
	var centerY = 155
	return centerY
}

function spiderimageFile(angle){
	var image="../assets/images/spiders/spider" + angle + ".gif";
	return image;
}

function followmouse(e){
	if (!e) var e = window.event;
	//first lets sort out the fly movement
	var	mouseX=(e.clientX) ? e.clientX : e.pageX;	//get the mouse's X coord
	var	mouseY=(e.clientY) ? e.clientY : e.pageY;	//get the mouse's Y coord
	mouseX=(mouseX<0 || isNaN(mouseX)) ? 0 : mouseX; //make sure the mouse X coord is valid
	mouseY=(mouseY<0 || isNaN(mouseY)) ? 0 : mouseY; //make sure the mouse Y coord is valid
	
	offX=mouseX-centerX();
	offY=mouseY-centerY();
	var angle = Math.round((180+(-Math.atan2(offX,offY)/(Math.PI/180)))/22.5)+1;
	if (angle>16) angle=1;
	spiderImgObj=document.getElementById("spiderImg");
	spiderImgObj.src=spiderimageFile(angle);
}

function showInfo(text){
	objInfo=document.getElementById("infoDiv");
	objInfo.innerHTML=text;
	objInfo.style.visibility="visible";
}
	

function afterLoad(){
	// this function is ran only after the document body is loaded
	// and only if broser is DOM compatible
	if (!document.getElementById) return;
	
	//hide the 'no javascript warning
	document.getElementById("noscript").innerHTML = "";
	//now set the handler function for the onmousemove event
	document.onmousemove=followmouse;
}

window.onload = afterLoad //call the afterLoad function when the document has finished loading

