// JavaScript Document

Image0 = new Image();
Image0.src = "/images/bubble.gif";

Amount = 20;
Ymouse = -50;
Xmouse = -50;

Ypos = new Array();
Xpos = new Array();
Speed = new Array();
rate = new Array();
grow = new Array();
Step = new Array();
Cstep = new Array();
nsSize = new Array();

ns = (document.layers) ? 1 : 0;
if(document.captureEvents) document.captureEvents(Event.MOUSEMOVE);

function Mouse(e) {
	if(!e) var e = window.event || window.Event;
	
	if('undefined' != typeof e.pageX) {
		Xmouse = e.pageX;
		Ymouse = e.pageY;
	} else {
		Xmouse = e.clientX + document.body.scrollLeft;
		Ymouse = e.clientY + document.body.scrollTop;
	}
	Ymouse -= 10;
}

(window.onMouseMove) ? window.onMouseMove = Mouse : document.onmousemove = Mouse;

for (i = 0; i < Amount; i++) {
	Ypos[i] = Ymouse;
	Xpos[i] = Xmouse;
	Speed[i] = Math.random() * 4 + 1;
	Cstep[i] = 0;
	Step[i] = Math.random() * 0.1 + 0.05;
	grow[i] = 8;
	nsSize[i] = Math.random() * 15 + 5;
	rate[i] = Math.random() * 0.5 + 0.1;
}

/*if(ns) {
	for (i = 0; i < Amount; i++)
		document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src="+Image0.src+" name='N' width="+nsSize[i]+" height="+nsSize[i]+"></LAYER>");
} else {*/
	document.write('<div style="position:absolute;top:-100px;left:-100px"><div style="position:relative">');
	for (i = 0; i < Amount; i++)
		document.write('<img id="si" src="'+Image0.src+'" style="position:absolute;top:0px;left:0px;filter:alpha(opacity=90)">');
	document.write('</div></div>');
//}

function MouseBubbles() {
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	var pageHeight = (document.layers) ? window.pageYOffset : document.body.scrollTop;
	var pageWidth = (document.layers) ? window.pageXOffset : document.body.scrollLeft;
	for (i = 0; i < Amount; i++) {
		sy = Speed[i] * Math.sin(270 * Math.PI / 180);
		sx = Speed[i] * Math.cos(Cstep[i] * 4);
		Ypos[i] += sy;
		Xpos[i] += sx;
		if (Ypos[i] < -40) {
			Ypos[i] = Ymouse;
			Xpos[i] = Xmouse;
			Speed[i] = Math.random() * 6 + 4;
			grow[i] = 8;
			nsSize[i] = Math.random() * 15 + 5;
		}
		if (ns) {
			document.layers['sn'+i].left = Xpos[i] + pageWidth;
			document.layers['sn'+i].top = Ypos[i] + pageHeight;
		} else {
			si[i].style.pixelLeft = Xpos[i] + pageWidth;
			si[i].style.pixelTop = Ypos[i] + pageHeight;
			si[i].style.width = grow[i];
			si[i].style.height = grow[i];
		}
		grow[i] += rate[i];
		Cstep[i] += Step[i];
		if (grow[i] > 24)
			grow[i] = 25;
	}
	setTimeout('MouseBubbles()', 10);
}

function addEvent(obj, evType, fn) { 
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else
		return false;
}

addEvent(window, 'load', MouseBubbles);