/******************************************************************* 
* File    : JSFX_Circle.js  © JavaScript-FX.com
* Created : 2001/08/19 
* Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com 
* Purpose : A mouse trailer based on a script by Doc Ozone - www.ozones.com
*           as seen at http://www.wsabstract.com/script/script2/cursoreffect.shtml
* History 
* Date         Version        Description 
* 2001-08-19	1.0		First converted version
* 2001-08-28	1.1		Added the text version
***********************************************************************/ 
/*
 * Class Circle extends Object (requires PlayField)
 */
JSFX.Circle = function(theImage, max, radius, speed)
{
	var i;
	var htmlStr = "<IMG SRC='"+theImage+"'>";
	if(max == null) max=10;
	if(radius == null) radius = 200;
	if(speed == null) speed = 0.2;

	for(i=0 ; i<max ; i++)
	{
		mySprite = new JSFX.CircleSprite(htmlStr, i, max, radius, speed);
		JSFX.pf.addSprite(mySprite);

	}
	JSFX.pf.start();
}
/*
 * Class CircleText extends Object (requires PlayField)
 */
JSFX.CircleText = function(theStr, font, color, size, radius, speed)
{
	var i;
	var max=theStr.length;
	if(radius == null) radius = 200;
	if(speed == null) speed = 0.2;

	for(i=0 ; i<max ; i++)
	{
		mySprite = new JSFX.CircleSprite("<FONT FACE='"+font+"' SIZE='"+size+"' COLOR='"+color+"'>"+theStr.charAt(i)+"</FONT>", i, max, radius, speed);
		JSFX.pf.addSprite(mySprite);

	}
	JSFX.pf.start();
}
/*
 * Class CircleSprite extends Layer
 */
JSFX.CircleSprite = function(htmlStr, n, max, radius, speed)
{
	this.superC = JSFX.Layer;
	this.superC(htmlStr,0,0);

	this.x 	= Math.random() * (JSFX.Browser.getMaxX()-40);
	this.y 	= Math.random() * (JSFX.Browser.getMaxY()-40);
	this.r	= radius;
	this.s	= speed;
	this.a 	= -(2 * n * Math.PI/max);
	this.targetX = 200 + this.r * Math.sin(this.a);
	this.targetY = 200 + this.r * Math.cos(this.a);
	this.show();
}
JSFX.CircleSprite.prototype = new JSFX.Layer;

JSFX.CircleSprite.prototype.animate = function()
{
	var mx = JSFX.Browser.mouseX;
	var my = JSFX.Browser.mouseY;
	var dir = this.s;

	if(my < JSFX.Browser.getMaxY()/2)
	{
		if(mx < JSFX.Browser.getMaxX()/2)
			dir = -dir;
	}
	else
	{
		if(mx > JSFX.Browser.getMaxX()/2)
			dir = -dir;
	}

	this.a += dir
	this.targetX = mx + this.r * Math.sin(this.a) - 10;
	this.targetY = my + this.r * Math.cos(this.a) - 10;
	this.x += (this.targetX - this.x)/20;
	this.y += (this.targetY - this.y)/20;

	this.moveTo(this.x, this.y);
}
