/*******************************************************************
*
* File    : JSFX_Bubble.js © JavaScript-FX.com
*
* Created : 2000/05/16
*
* Author  : Roy Whittle www.Roy.Whittle.com
*           
* Purpose : To create animated bubbles that float up the page
*
* History
* Date         Version        Description
*
* 2001-03-17	2.0		Converted for javascript-fx
* 2001-12-09	2.1		Remove requirment for JSFX.Sprite
***********************************************************************/
/*
 * Class RisingSprite extends Layer
 */
JSFX.RisingSprite = function(theHtml)
{
	//Call the superclass constructor
	this.superC	= JSFX.Layer;
	this.superC(theHtml);

	this.x = Math.random() * (JSFX.Browser.getMaxX()-40);
	this.y = JSFX.Browser.getMaxY();
	this.dx = Math.random() * 4 - 2;
	this.dy = -Math.random() * 8 - 4;
	this.state = "RUN";

	this.moveTo(this.x,this.y);
	this.show();
}
JSFX.RisingSprite.prototype = new JSFX.Layer;

JSFX.RisingSprite.prototype.animate = function()
{
	if(this.state == "OFF")
		return;

	this.x += this.dx;
	this.y += this.dy;

	this.moveTo(this.x, this.y);

	if( (this.x > JSFX.Browser.getMaxX()-20)
	 || (this.x < JSFX.Browser.getMinX()-0)
	 || (this.y < JSFX.Browser.getMinY() ) )
	{
		this.running = JSFX.Bubble.running;
		if(this.state == "STOPPING")
		{
			this.moveTo(-100,-100);
			this.hide();
			this.state = "OFF";
		}
		else
		{
			this.x = Math.random() * (JSFX.Browser.getMaxX()-40);
			this.y = JSFX.Browser.getMaxY();
			this.dx = Math.random() * 4 - 2;
			this.dy = -Math.random() * 8 - 4;
		}
	}
}
/*
 * Static Class Bubble, creates bubble objects
 */
JSFX.Bubble = function(n, theImage, stopTime)
{
	return new JSFX.RisingObj(n, theImage, stopTime);
}
/*** Class RisingObj extends Object ***/
JSFX.RisingObj = function(numSprites, theImage, stopTime)
{
	this.id = "JSFX_RisingObj_"+JSFX.RisingObj.count++;
	this.sprites = new Array();
	for(i=0 ; i<numSprites; i++)
		this.sprites[i]=new JSFX.RisingSprite(theImage);

	window[this.id]=this;
	this.animate();

	if(stopTime)
		setTimeout("window."+this.id+".stop()", stopTime*1000);

}
JSFX.RisingObj.count = 0;

JSFX.RisingObj.prototype.stop = function()
{
	for(i=0 ; i<this.sprites.length ; i++)
		this.sprites[i].state = "STOPPING";
}

JSFX.RisingObj.prototype.animate = function()
{
	setTimeout("window."+this.id+".animate()", 40);

	for(i=0 ; i<this.sprites.length ; i++)
		this.sprites[i].animate();

}
/*** END Class RisingObj ***/
