/*
Copyright Kevin Gibney 1999 
For jscript programming contact kevingibney@i-t.net

Scripting below can be used freely if credit is kept as written here.
*/

var isNav, isIE;
var coll = "";
var styleObj = "";

if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape") {
		isNav = true;
	}
	else {
		isIE = true;
		coll = "all.";
		styleObj = ".style";
	}
}

//send user to non DHTML page
if (!isNav && !isIE) {
	top.location.href = "index2.html";
}

// DHTML Library //
function IE_WINDOW () {
	this.GetInsideWidth = new Function ("return document.body.clientWidth");
	this.GetInsideHeight = new Function ("return document.body.clientHeight");
}

function NAV_WINDOW () {
	this.GetInsideWidth = new Function ("return window.innerWidth;");
	this.GetInsideHeight = new Function ("return window.innerHeight;");
}

function _sfx_rotate_left(steps,timerID) {
	this.Hide();
	this.X-=steps;

	var LeftX=this.X; 
	this.GetTopRight();
	//alert("this.X="+this.X);
	var RightX=this.X;
	this.X=LeftX;
	
	//alert("this.Width="+this.Width+" RightX="+RightX);
	if (RightX <= 0) {
		this.X=mywin.GetInsideWidth();
		//alert(this.X);
		this.MoveTo(this.X+steps,this.Y);
		this.Show();		
	} else {
		this.MoveTo(this.X,this.Y);		
	}

	this.Show();
}

function _sfx_rotate_right(steps,timerID) {
	this.Hide();
	this.X+=steps;

	var RightX=this.X; 
	this.GetTopLeft();
	//alert("this.X="+this.X);
	var LeftX=this.X;
	this.X=RightX;

	//alert("this.Width="+this.Width+" RightX="+RightX);
	if (LeftX >= mywin.GetInsideWidth()) {
		this.X=-this.Width;
		//alert(this.X);
		this.MoveTo(this.X,this.Y);
		this.Show();		
	} else {
		this.MoveTo(this.X,this.Y);		
	}

	this.Show();
}

function _sfx_follow_mouse(steps,timerID) {
	this.Hide();
	var xleft, xright;
	
	this.GetTopLeft();
	xleft = this.X;
	
	this.GetTopRight();
	xright = this.X;

	if (msDoc.X > xleft && msDoc.X < xright) {
		this.Show();
		return;		
	} else if (msDoc.X > xright) {
		this.X = xleft + steps;
	} else {
		this.X = xleft - steps;
	}
	
	this.MoveTo(this.X,this.Y);
	this.Show();
}

function _sfx_custom_1310_follow_mouse(steps,timerID) {
	this.Hide();
	var xleft, xright, objwidth, objheight, objcentreX,objcentreY, msX, msY, doccentreX, insidewidth;
	
	msX = msDoc.X;
	msY = msDoc.Y;
	
	insidewidth = mywin.GetInsideWidth();
	
	//check for off screen
	var offscreenleft = false;
	var offscreenright = false;
	this.GetTopRight();
	if (this.X < 0) offscreenleft = true;
	
	this.GetTopLeft();
	if (this.X > insidewidth) offscreenright = true;
	//end check for offscreen
	
	doccentreX = parseInt(insidewidth/2);
	
	xleft = this.X;
	ytop = this.Y;
	
	objwidth = this.Width;
	objheight = this.Height;
	
	objcentreX = (objwidth/2) + xleft;
	objcentreY = (objheight/2) + ytop;	
	
	this.GetTopRight();
	xright = this.X;
	
	//define hotspots
	if ((msX  < insidewidth*0.33)) 	{
		//left side of screen - move left
		if (!offscreenleft) this.X = xleft - steps;
		else this.X = xleft
		//if offscreen
	}
	else if ((msX >= insidewidth*0.33) && (msX  <= insidewidth*0.66)) {
		//middle of screen - move to middle
		if (objcentreX < doccentreX) {			
			if ((objcentreX + steps) > doccentreX) {
				this.Show();
				return;
			}
			else this.X = xleft + steps; //move right
		} else if (objcentreX > doccentreX) {
			if ((objcentreX - steps) < doccentreX) {
				this.Show();
				return;
			}
			else this.X = xleft - steps; //move left
		}		
	}
	else if (msX > insidewidth*0.66) {
		//right side of screen - move to right
		if (!offscreenright) this.X = xleft + steps;
		else this.X = xleft;
	}
//window.status = "MOVE=" + move + "   xleft=" + xleft + " ytop=" + ytop + "  width=" + objwidth + ",height="+objheight + "    objcentreX=" + objcentreX + ", doccentreX="+doccentreX + ",insidewidth="+insidewidth;
	this.MoveTo(this.X,this.Y);
	this.Show();
}

function _sfx_open_gate(steps,timerID) {
	var objwidth, objheight;
	
	objwidth = this.Width;
	objheight = this.Height;

	portalgateTop.GetTopLeft();
	portalgateBot.GetTopLeft();
	this.Counter +=1;

	if (this.NofSteps > this.Counter) {
		portalgateTop.Y-=steps;
		portalgateBot.Y+=steps;
	}
	else clearTimeout(timerID);
	portalgateTop.MoveTo(portalgateTop.X,portalgateTop.Y);
	portalgateBot.MoveTo(portalgateBot.X,portalgateBot.Y);
}

function NAV_OBJ(obj,toplayers) {
		obj += "";
		this.callers="";
		this.obj = (obj=="undefined")?"":eval(toplayers + "document." + obj);
		this.contentObj = (obj=="undefined")?"":eval(toplayers + "document." + obj);		
		this.X = 0;
		this.Y = 0;
		this.Width = (obj=="undefined")?"":this.contentObj.clip.width;
		this.Height = (obj=="undefined")?"":this.contentObj.clip.height;
		this.Steps=0;
		this.Speed=0;
		this.Counter=0;

		this.SFX_OpenGate = _sfx_open_gate;
		this.SFX_RotateLeft = _sfx_rotate_left;
		this.SFX_RotateRight = _sfx_rotate_right;
		this.SFX_Custom1310FollowMouse = _sfx_custom_1310_follow_mouse;	
		this.SFX_FollowMouse = _sfx_follow_mouse;
}


function IE_OBJ(obj) {
		obj += "";
		this.callers="";
		this.obj = (obj=="undefined")?"":document.all[obj].style;
		this.contentObj = (obj=="undefined")?"":document.all[obj];		
		this.X = 0;
		this.Y = 0;
		this.Width = (obj=="undefined")?"":this.contentObj.clientWidth;
		this.Height = (obj=="undefined")?"":this.contentObj.clientHeight;
		this.Steps=0;
		this.Speed=0;
		this.Counter=0;
				
		this.SFX_OpenGate = _sfx_open_gate;
		this.SFX_RotateLeft = _sfx_rotate_left;
		this.SFX_RotateRight = _sfx_rotate_right;
		this.SFX_Custom1310FollowMouse = _sfx_custom_1310_follow_mouse;
		this.SFX_FollowMouse = _sfx_follow_mouse;			
}


//***Mouse Events***//
if (isNav) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
document.onmousemove = GetMousePos;

function GetMousePos(evt) {
	if (isNav) { 
		msDoc.X=evt.pageX;
		msDoc.Y=evt.pageY;
	} else {
		msDoc.X=window.event.clientX;
		msDoc.Y=window.event.clientY;
	}
}

function MousesMovement() {
	this.X=0;
	this.Y=0;
}
new MousesMovement();
var msDoc = new MousesMovement();


//*** end Mouse Events ***//


function init(){
	if (isIE) {
		new IE_OBJ();
		IE_OBJ.prototype.GetTopLeft = new Function ("this.X=this.obj.pixelLeft; this.Y=this.obj.pixelTop");
		IE_OBJ.prototype.GetTopRight = new Function ("this.X=this.obj.pixelLeft+this.Width; this.Y=this.obj.pixelTop");
		IE_OBJ.prototype.GetBottomLeft = new Function ("this.X=this.obj.pixelLeft; this.Y=this.obj.pixelTop+this.Height");
		IE_OBJ.prototype.GetBottomRight = new Function ("this.X=this.obj.pixelLeft+this.Width; this.Y=this.obj.pixelTop+this.Height");
		IE_OBJ.prototype.MoveTo = new Function ("X","Y","this.obj.pixelLeft=X;this.obj.pixelTop=Y");
		IE_OBJ.prototype.Show = new Function ("this.obj.visibility = 'visible'");
		IE_OBJ.prototype.Hide = new Function ("this.obj.visibility = 'hidden'");	
		IE_OBJ.prototype.Reposition = new Function ("Xp","Yp","this.X=parseInt(mywin.GetInsideWidth()*Xp/100-this.Width/2);this.Y=parseInt(mywin.GetInsideHeight()*Yp/100-this.Height/2);this.MoveTo(this.X,this.Y)");
	} else if (isNav) {
		new NAV_OBJ();
		NAV_OBJ.prototype.GetTopLeft = new Function ("this.X=this.obj.left; this.Y=this.obj.top");
		NAV_OBJ.prototype.GetTopRight = new Function ("this.X=this.obj.left+this.Width; this.Y=this.obj.top");
		NAV_OBJ.prototype.GetBottomLeft = new Function ("this.X=this.obj.left; this.Y=this.obj.top+this.Height");
		NAV_OBJ.prototype.GetBottomRight = new Function ("this.X=this.obj.left+this.Width; this.Y=this.obj.top+this.Height");
		NAV_OBJ.prototype.MoveTo = new Function ("X","Y","this.obj.left=X;this.obj.top=Y");
		NAV_OBJ.prototype.Show = new Function ("this.obj.visibility = 'visible'");
		NAV_OBJ.prototype.Hide = new Function ("this.obj.visibility = 'hidden'");
		NAV_OBJ.prototype.Reposition = new Function ("Xp","Yp","this.X=parseInt(mywin.GetInsideWidth()*Xp/100-this.Width/2);this.Y=parseInt(mywin.GetInsideHeight()*Yp/100-this.Height/2);this.MoveTo(this.X,this.Y)");
	}

	main();
}

function main() {
	if (isIE) {	
		thirteen10 = new IE_OBJ("obj1310");
		mywin = new IE_WINDOW();		
	} else if (isNav) {
		thirteen10 = new NAV_OBJ("obj1310","");
		mywin = new NAV_WINDOW();	
	}
	
	thirteen10.Custom1310 = new Function ("this.SFX_Custom1310FollowMouse(this.Steps,setTimeout('thirteen10.Custom1310()',this.Speed))");	
		
	//Thirteen Ten Custom function	
	thirteen10.Steps = 20;//pixels
	thirteen10.Speed = 10;//msecs		
	thirteen10.Hide();
	thirteen10.Custom1310();
}