/* 
 * Core Javascript functions
 * (c) Darren Coleman 2005
 */
function BrowserCheck() {
	var b = navigator.appName;
	if (b == "Netscape") this.b = "NS";
	else if (b == "Microsoft Internet Explorer") this.b = "IE";
	else this.b = b;
	this.v = parseInt(navigator.appVersion);
	this.NS = (this.b == "NS" && this.v>=4);
	this.NS4 = (this.b == "NS" && this.v == 4);
	this.NS5 = (this.b == "NS" && this.v == 5);
	this.IE = (this.b == "IE" && this.v>=4);
	this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	if (this.IE5 || this.NS5) this.VER5 = true;
	if (this.IE4 || this.NS4) this.VER4 = true;
	this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
	this.min = (this.NS||this.IE);
}

is = new BrowserCheck();

iter = 0;
setId = 0;
down = true;
up = false;
right = true;
left = false;
bouncingBall = (is.VER5) ? document.getElementById("ee").style : (is.NS) ? document.layers["ee"] : document.all["ee"].style;

function bounceEgg() {
	winH = (is.NS) ? window.innerHeight - 32 : document.body.offsetHeight - 32;
	winW = (is.NS) ? window.innerWidth - 32 : document.body.offsetWidth - 32;

	if (setId != 0) clearInterval(setId);
	rspd = parseInt(7 * Math.random()) + 3;
	bouncingBall.visibility="visible";
	iter = 0;
	setId = setInterval("generateGravity("+rspd+")", 20);
	return true;
}

function generateGravity(rspd) {
	if (parseInt(bouncingBall.left) > (winW-32)) 
		right = false;
	else if (parseInt(bouncingBall.left)-rspd < 0)
		right = true;
	if ((parseInt(bouncingBall.top)+iter < winH) && down) {
		bouncingBall.top = parseInt(bouncingBall.top) + iter;
		bouncingBall.left = (right) ? parseInt(bouncingBall.left) + rspd : parseInt(bouncingBall.left) - rspd;
		iter++;
		return;
	} else {
		if ((parseInt(bouncingBall.top)< winH) && down) {
			bouncingBall.top = winH + 5;
			bouncingBall.left = (right) ? parseInt(bouncingBall.left) + rspd : parseInt(bouncingBall.left) - rspd;
			return;
		}
		down = false;
		up = true;
		if (iter < 0 && parseInt(bouncingBall.top) > winH) {
			clearInterval(setId);
			bouncingBall.visibility = "hidden";
			bouncingBall.left = 0;
			bouncingBall.top = 0;
			setId = 0;
		}
		if (parseInt(bouncingBall.top) > 0 && up && iter >= 0) {
			bouncingBall.top = parseInt(bouncingBall.top) - iter;
			bouncingBall.left = (right) ? parseInt(bouncingBall.left) + rspd : parseInt(bouncingBall.left) - rspd;
			iter--;
			if (iter%3 == 0) iter--;
			return;
		}
		down = true;
		up = false;
	}
}
 
function eeTg() {
	if (!bouncingBall) return;
	
	if (bouncingBall.visibility == 'hidden') {
		bouncingBall.visibility = 'visible';
		bounceEgg();
	} else {
		clearInterval(setId);
		bouncingBall.visibility = "hidden";
		bouncingBall.left = 0;
		bouncingBall.top = 0;
		setId = 0;
	}	
}