
	// Produced by Moonwalk Sthlm
	// contact@moonwalk.se
	// www.moonwalk.se

var x = y = null;
var nextStar = 0;
var maxY = 690;

var stars = new Array();
for(var i = 0; i < 10; i ++) {
	stars[i] = new starLayerObject(('docstar' + (i + 1)));
}

function mouseTrace(e) {
	x = (event.clientX + document.body.scrollLeft);
	y = (event.clientY + document.body.scrollTop);
	var n = getNextStar();
	stars[n].fall(n);
}

function getNextStar() {
	var n = (nextStar == (stars.length - 1)) ? 0 : (nextStar + 1) ;
	nextStar = n;
	if(stars[n].initialized) {
		stars[n].initialized = false;
		stars[n].x = null;
		stars[n].y = null;
		stars[n].x2 = null;
		stars[n].xspeed = null;
		stars[n].yspeed = 1;
	}
	return n;
}

function starLayerObject(id) {
	this.id = id;
	this.x = null;
	this.y = null;
	this.x2 = null;
	this.yspeed = 1;
	this.runcount = 0;
	this.initialized = false;
}

function layerMoveTo(layer, x, y) {
	getLayer(layer).top = getPositionStr(y);
	getLayer(layer).left = getPositionStr(x);
}

function layerShow(layer) {
	getLayer(layer).visibility = 'visible';
}

function layerHide(layer) {
	getLayer(layer).visibility = 'hidden';
}

function layerFall(index) {

	if(!stars[index].initialized) {

// window.status=stars[index].id;
// return ;

		stars[index].show(stars[index].id);


		stars[index].moveTo(stars[index].id, x, y);
		stars[index].x = (x + (Math.floor(Math.random()*15)));
		stars[index].y = y;
		stars[index].xspeed = Math.floor(Math.random() * 20) - 10;
		stars[index].x2 = stars[index].x + stars[index].xspeed;
	} else {
		stars[index].yspeed /= .98;
		stars[index].y = stars[index].y + stars[index].yspeed;
		stars[index].x += (stars[index].x2 - stars[index].x) / 10;
	}

	stars[index].initialized = true;
	stars[index].moveTo(stars[index].id, stars[index].x, stars[index].y);

	if(stars[index].y < maxY) {
		setTimeout('layerFall(' + index + ')', 0001);
	} else {
		stars[index].initialized = true;
		stars[index].hide(stars[index].id);
	}
}

function getLayer(id) {
	var r;
	if(document.layers)
		r = document.layers[id];
	else if(document.getElementById)
		r = document.getElementById(id).style;
	else
		r = document.all[id].style;
	return r;
}

function getPositionStr(coord) {
	var r = coord;
	if(!document.layers)
		r = r + 'px';
	return r;
}

starLayerObject.prototype.moveTo = layerMoveTo;
starLayerObject.prototype.show = layerShow;
starLayerObject.prototype.hide = layerHide;
starLayerObject.prototype.fall = layerFall;

function startGlitter() {

	// TEST TEST
//	return ;

	if((document.all) && (navigator.platform.toString().toLowerCase().indexOf('win') != -1)) {
		document.onmousemove = mouseTrace;
	}
}

