<!--
// YOU DON'T NEED TO MAKE ANY MODIFICATIONS TO THIS FILE TO USE THE
// SWARM SCRIPT AS IS.

/*  Swarm.js by Bugimus                                December 1999

	You are free to use this swarm script for your own personal use.  
    A link back to  http://bugimus.com/ would be greatly appreciated.  
	Please leave this comment intact.
*/
// first determine the type of browser you're dealing with
NN4 = (document.layers);
IE4 = (document.all);
GN4 = (NN4 || IE4);

// Capture mousemove event and set global mouse coordinates
var Xm=0;
var Ym=0;
if( NN4 ) document.captureEvents( Event.MOUSEMOVE );
document.onmousemove = handleMousemove;
function handleMousemove(e) {
	if( GN4 ) {
		Xm = (NN4)?e.pageX:event.x+document.body.scrollLeft
		Ym = (NN4)?e.pageY:event.y+document.body.scrollTop
	}
}

// Define swarm object
function swarm(obj,number,widthdivisor,heightdivisor,speed) {
	this.timer = null;
	if( NN4 ) this.obj = eval("document."+obj);
	if( IE4 ) this.obj = eval(obj+".style");
	this.speed = speed
	this.yBase = 300
	this.xBase = 300
	this.delay = 15
	this.yAmpl = 3
	this.yMax = 8
	this.step = 0.3
	this.ystep = 0.3
	this.currStep = 0
	this.tAmpl=1
	this.wd = widthdivisor
	this.hd = heightdivisor
	this.j = number
	this.x = parseInt(this.obj.left)
	this.y = parseInt(this.obj.top)
	this.centerX = this.x
	this.centerY = this.y
	this.distance = 0
	this.alpha = 0
	this.qzone = 2
	this.swarm = swarmMove
	this.chase = cursorChase
	this.show = showDiv
	this.hide = hideDiv
}

function showDiv() {
	this.obj.visibility = "visible";
}

function hideDiv() {
	this.obj.visibility = "hidden";
}

function swarmMove( x, y ) {
	/* The code that produces the swarm movement is based on code from Doc Ozone (www.ozones.com) who got it from 
	   fullerene.com originally.  Thanks to both of these sites for allowing the Swarm to thrive!
	*/
	if( NN4 ) {
		width=window.innerWidth;
		height=window.innerHeight;
	} else if( IE4 ) {
		width=document.body.clientWidth;
		height=document.body.clientHeight+document.body.scrollTop;
	} else {
		width=500;
		height=400;
	}
	this.xBase = height/this.wd;
	this.yBase = width/this.hd;
    this.x = x + Math.sin((20*Math.sin(this.currStep/30))+this.j*70)*this.xBase*(Math.sin(10+this.currStep/(10+this.j))+0.2)*Math.cos((this.currStep + this.j*55)/10);
    this.y = y + Math.cos((20*Math.sin(this.currStep/(30+this.j)))+this.j*70)*this.yBase*(Math.sin(10+this.currStep/10)+0.2)*Math.cos((this.currStep + this.j*55)/10);
	this.currStep += this.step;
	if( IE4 ) {
		if( this.x < 0 ) this.x=0;
		if( this.x > width-15 ) this.x=width-15;
		if( this.y < 0 ) this.y=0;
		if( this.y > height-20 ) this.y=height-20;
	}
	this.obj.left = this.x;
	this.obj.top = this.y;
}

function cursorChase( x, y ) {
    step = 2;
	dx = this.x - x + 0;
	dy = this.y - y + 0;
	this.distance = parseInt(Math.sqrt(dx*dx+dy*dy));
	if( dx!=0 ) this.alpha = Math.atan( dy/dx );
	else this.alpha = Math.PI/2;
	if( dx>0 ) this.alpha+=Math.PI;
	xstep = step*Math.cos(this.alpha);
	ystep = step*Math.sin(this.alpha);
	dspeed = 0.5 + this.distance/75;
	if( Math.abs(dx) > this.qzone ) {
		this.x+=xstep*dspeed;
		this.obj.left = this.x;
	} 
	if( Math.abs(dy) > this.qzone ) {
		this.y+=ystep*dspeed;
		this.obj.top = this.y;
	}
}

function moveBugs() {
	var nulltimer1 = null;
	target.chase(Xm,Ym);
	bug0.swarm(target.x,target.y);
	bug1.swarm(target.x,target.y);
	bug2.swarm(target.x,target.y);
	bug3.swarm(target.x,target.y);
	bug4.swarm(target.x,target.y);
	bug5.swarm(target.x,target.y);
	bug6.swarm(target.x,target.y);
	nulltimer1=setTimeout("moveBugs()", bug0.speed);
}

function initialize() {
	Xtarget=0;
	Ytarget=0;
	if( NN4 ) {
		eval("document.targetDiv.document.left=Xtarget");
		eval("document.targetDiv.document.top=Ytarget");
	} else {
		eval("document.all.targetDiv.style.left=Xtarget");
		eval("document.all.targetDiv.style.top=Ytarget");
	}
	target = new swarm("targetDiv",0,5,5,20)
	bug0 = new swarm("bug0Div",0,5,5,20)
	bug1 = new swarm("bug1Div",1,5,5,20)
	bug2 = new swarm("bug2Div",2,5,5,20)
	bug3 = new swarm("bug3Div",3,5,5,20)
	bug4 = new swarm("bug4Div",4,5,5,20)
	bug5 = new swarm("bug5Div",5,5,5,20)
	bug6 = new swarm("bug6Div",6,5,5,20)

    moveBugs();
}
//-->

