/*******************************************************************
*
* File    : JSFX_snow.js © JavaScript-FX.com
*
* Created : 2000/05/16
*
* Author  : Roy Whittle www.Roy.Whittle.com
*           
* Purpose : To create animated snow in the browser window
*
* History
* Date         Version        Description
*
* 2001-03-17	2.0		Converted for javascript-fx
***********************************************************************/
/*
 * Class Snow extends Object
 */
JSFX.Snow = function(n, theImage, stopTime)
{
	JSFX.Snow.running = true;

	var i;
	for(i=0 ; i<n ; i++)
	{
		mySprite = new JSFX.Sprite(theImage, 0, 0);

		mySprite.x = Math.random() * (JSFX.Browser.getCanvasWidth()-40);
		mySprite.y = -40;
		mySprite.dx = Math.random() * 4 - 2;
		mySprite.dy = Math.random() * 6 + 2;
		mySprite.ang = 0;
		mySprite.angStep = .2;
		mySprite.amp = 10;
		mySprite.running = true;
		mySprite.animate = JSFX.Snow.animate;

		mySprite.moveTo(mySprite.x,mySprite.y);
		mySprite.show();
	}
	JSFX.Sprite.startSprites();
	if(stopTime)
		setTimeout("JSFX.Snow.running = false",stopTime*1000);
}

JSFX.Snow.animate = function()
{
	if(!this.running)
		return;

	this.x += this.dx;
	this.y += this.dy;
	this.ang += this.angStep;

	this.moveTo(this.x + this.amp*Math.sin(this.ang), this.y);

	if( (this.x > JSFX.Browser.getMaxX()-20)
	 || (this.x < JSFX.Browser.getMinX()-0)
	 || (this.y > JSFX.Browser.getMaxY()-40) )
	{
		this.running = JSFX.Snow.running;
		if(!this.running)
		{
			this.moveTo(-100,-100);
			this.hide();
		}
		else
		{
			this.x = Math.random() * (JSFX.Browser.getCanvasWidth()-40);
			this.y = -40;
			this.dx = Math.random() * 4 - 2;
			this.dy = Math.random() * 6 + 2;
			this.ang = 0;
		}
	}
}
