/*
   Feel free to use this code for your own *personal* use but please
   leave this comment in.  A link back to Bugimus' page would be much
   appreciated.  bugimus.com
*/
var IE5=NN4=NN6=false
if(document.all)IE5=true
else if(document.layers)NN4=true
else if(document.getElementById)NN6=true

var Xcursor=0
var Ycursor=0
if(NN4)document.captureEvents(Event.MOUSEMOVE)
if(NN6)document.addEventListener("mousemove", handleIt, true)
if(IE5||NN4)document.onmousemove = handleIt
function handleIt(e){  
	if(IE5) {
		Xcursor=event.clientX
		Ycursor=event.clientY
	} else if(NN4) {
		Xcursor=e.pageX
		Ycursor=e.pageY
	} else if(NN6) {
		Xcursor=e.pageX
		Ycursor=e.pageY
	}
}
function MovingObject(obj,img) {
	this.IE5=this.NN4=this.NN6=false
	if(document.all)this.IE5=true
	else if(document.layers)this.NN4=true
	else if(document.getElementById)this.NN6=true

	if(this.NN4)this.obj=eval("document."+obj)
	else if(this.IE5) this.obj=eval("document.all."+obj+".style")
	else if(this.NN6) this.obj=eval("document.getElementById(\""+obj+"\")"+".style")

	if(img) {
		if(this.IE5) this.img=eval("document.all."+img)
		else if(this.NN4) this.img=eval("document."+obj+".document."+img)
		else if(this.NN6) this.img=eval("document."+img)
	}
		
	this.decay = 5

	this.chase = Chase
	this.getx = getX
	this.gety = getY
	this.setx = setX
	this.sety = setY
}
function getX() {
	if(this.IE5)return parseInt(this.obj.pixelLeft)
	else if(this.NN4)return parseInt(this.obj.left)
	else if(this.NN6)return parseInt(this.obj.left)
}
function getY() {
	if(this.IE5)return parseInt(this.obj.pixelTop)
	else if(this.NN4)return parseInt(this.obj.top)
	else if(this.NN6)return parseInt(this.obj.top)
}
function setX(x) {
	if(this.IE5)this.obj.pixelLeft=x;
	else if(this.NN4)this.obj.left=x;
	else if(this.NN6)this.obj.left=parseInt(x + "px");
}
function setY(y) {
	if(this.IE5)this.obj.pixelTop=y;
	else if(this.NN4)this.obj.top=y;
	else if(this.NN6)this.obj.top=parseInt(y + "px");
}
function Chase( x, y ) {
	dx=x-this.getx()
	dy=this.gety()-y
	distance=Math.round(Math.sqrt(dx*dx+dy*dy))
	if(dx==0) angle=Math.PI*((dy>0)?.5:1.5)
	else angle=Math.atan(dy/dx)+(Math.PI*((dx<0)?1:(dy<0)?2:0))
	xstep=(dx>1)?Math.ceil(distance*Math.cos(angle)/this.decay):Math.floor(distance*Math.cos(angle)/this.decay)
	ystep=(dy<1)?Math.ceil(-distance*Math.sin(angle)/this.decay):Math.floor(-distance*Math.sin(angle)/this.decay)
	this.setx(this.getx()+xstep)
	this.sety(this.gety()+ystep)
	if(this.img) eval("this.img.src=chaserimage[Math.floor(180/15*angle/Math.PI)].src")
}
