<!--
var spriteURL;						// URL path to sprite image
var nsprites;						// Total number of sprites
var group;							// How many sprites are of a specific kind
var whichSprite;					// Which sprite to use for a particular animation
var first, last;					// Range of sprites    for a particular animation

var ns4up = (document.layers) ? 1 : 0;	// Browser sniffer
var ie4up = (document.all) ? 1 : 0;
var ns6up = (document.getElementById && !document.all) ? 1 : 0;

var ddx, dx, xp, yp;				// coordinate and position variables
var amp, stx, sty;					// amplitude and step variables
var i,	doc_width  = 800,
		doc_height = 600;

var dt;								// Time step for moving sprites (ms)
var timeSteps;						// Number of time steps for animation

// Reset position of sprites
function resetPosition()
{
	for (i=1; i<=nsprites; ++i)
	{	
		dx[i] = 0;								// set coordinate variables
		xp[i] = Math.random()*(doc_width-50);	// set position variables
		yp[i] = Math.random()*doc_height;

		whichSprite = Math.floor((i-1)/group);	// Index to sprite image

		// Set amplitude variables
		switch (whichSprite)
		{
			case 0:
				// Rain
				amp[i] = 10.0;
				stx[i] =  0.1;
				sty[i] =  3.0;
				break;
			case 1:
				// Snow
				amp[i] = Math.random()*20;
				stx[i] = .02 + Math.random()/10;
				sty[i] = .70 + Math.random();
				break;
			case 2:
				// Leaf
				amp[i] = Math.random()*40;
				stx[i] = .02 + Math.random()/10;
				sty[i] = .50 + Math.random();
				break;
			default:
				amp[i] = Math.random()*20;
				stx[i] = .02 + Math.random()/10;
				sty[i] = .70 + Math.random();
		}
	}
}

// Initialize all sprites
// Call this function in top of BODY tag prior to any animation.
function initSprites()
{
	if (ns4up || ns6up)
	{
		doc_width  = self.innerWidth;
		doc_height = self.innerHeight;
	}
	else if (ie4up)
	{
		doc_width  = document.body.clientWidth;
		doc_height = document.body.clientHeight;
	}

	nsprites  = 30;
	spriteURL = new Array("images/rain3.gif","images/snow3.gif","images/leaf3.gif");
	group     = Math.floor(nsprites/spriteURL.length);

	dx  = new Array();
	xp  = new Array();
	yp  = new Array();
	amp = new Array();
	stx = new Array();
	sty = new Array();

	resetPosition();

	for (i=1; i<=nsprites; ++i)
	{	
		whichSprite = Math.floor((i-1)/group);	// Index to sprite image

		// Set up layers
		if (ns4up)
		{
			document.write("<layer name=\"sprite"+ i +"\" left=\"15\" top=\"15\" visibility=\"hide\"><img src=\""+spriteURL[whichSprite]+"\" border=\"0\"><\/layer>");
		}
		else if (ie4up || ns6up)
		{
			document.write("<div id=\"sprite"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: hidden; TOP: 15px; LEFT: 15px;\"><img src=\""+spriteURL[whichSprite]+"\" border=\"0\"><\/div>");
		}
	}
}

// Show the sprites
function showSprites(animation)
{
	dt        =   15;				// How frequently sprites move (ms)
	timeSteps = 11000;				// Total animation time = timeSteps * dt (ms)

	if (animation == "rain" || animation == "Rain" || animation == "RAIN")
	{
		whichSprite = 0;
	}
	else if (animation == "snow" || animation == "Snow" || animation == "SNOW")
	{
		whichSprite = 1;
	}
	else if (animation == "leaf" || animation == "Leaf" || animation == "LEAF")
	{
		whichSprite = 2;
	}
	else
	{
		alert ("Animation " + animation + " not available!");
	}

	first =  1 + group * whichSprite;
	last  = first + group - 1;

	for (i=first; i<=last; ++i)
	{
		if (ns4up)
		{
			document.layers("sprite"+i).style.visibility="show";
		}
		else if (ie4up)
		{
			document.all["sprite"+i].style.visibility="visible";
		}
		else if (ns6up)
		{
			document.getElementById("sprite"+i).style.visibility="visible";
		}
	}
}

// Hide the sprites
function hideSprites()
{
	for (i=1; i<=nsprites; ++i)
	{
		if (ns4up)
		{
			document.layers("sprite"+i).style.visibility="hide";
		}
		else if (ie4up)
		{
			document.all["sprite"+i].style.visibility="hidden";
		}
		else if (ns6up)
		{
			document.getElementById("sprite"+i).style.visibility="hidden";
		}
	}
}

// Main animation function
function move()
{
	for (i=first; i<=last; ++i)
	{
		// iterate for every sprite
		yp[i] += sty[i];
		if (yp[i] > doc_height-50)
		{
			xp[i] = Math.random()*(doc_width-amp[i]-30);
			yp[i] = 0;

			switch (whichSprite)
			{
				case 0:
					// Rain
					stx[i] =  0.1;
					sty[i] =  3.0;
					break;
				case 1:
					// Snow
					stx[i] = .02 + Math.random()/10;
					sty[i] = .70 + Math.random();
					break;
				case 2:
					// Leaf
					stx[i] = .02 + Math.random()/10;
					sty[i] = .50 + Math.random();
					break;
				default:
					stx[i] = .02 + Math.random()/10;
					sty[i] = .70 + Math.random();
			}

			if (ns4up)
			{
				doc_width  = self.innerWidth;
				doc_height = self.innerHeight;
			}
			else if (ie4up)
			{
				doc_width  = document.body.clientWidth;
				doc_height = document.body.clientHeight;
			}
			else if (ns6up)
			{
				doc_width  = window.innerWidth;
				doc_height = window.innerHeight;
			}
		}
		dx[i] += stx[i];

		if (whichSprite > 0)
			ddx = amp[i] * Math.sin(dx[i]);
		else
			ddx = - amp[i] * dx[i];

		if (ns4up)
		{
			document.layers["sprite"+i].top  = yp[i];
			document.layers["sprite"+i].left = xp[i] + ddx;
		}
		else if (ie4up)
		{
			document.all["sprite"+i].style.pixelTop  = yp[i];
			document.all["sprite"+i].style.pixelLeft = xp[i] + ddx;
		}
		else if (ns6up)
		{
			document.getElementById("sprite"+i).style.top  = yp[i];
			document.getElementById("sprite"+i).style.left = xp[i] + ddx;
		}	 
	}
	// Animation loop
	if (timeSteps > 0)
	{
		setTimeout("move()", dt);
		timeSteps -= dt;
	}
	else
	{
		hideSprites();
	}
}

// Start animation
function animate(animation)
{
	hideSprites();
	resetPosition();
	showSprites(animation);
	move();
}
//-->
