function TextEffect(targetID)
{
	if (!document.getElementById) { return; }
	if (!document.createElement) { return; }
	this.target = document.getElementById(targetID);
	this.step = 0;
	var text = this.target.innerHTML;
	this.target.innerHTML = "";
	this.chars = [];
	for(var i=0; i < text.length; i++)
	{
		this.chars[i] = document.createElement("span");
		if (text.charAt(i) == " ")
		{
			this.chars[i].innerHTML = "&nbsp;";
		}
		else
		{
			this.chars[i].innerHTML = text.charAt(i);
		}
		this.target.appendChild(this.chars[i]);
		this.chars[i].style.zoom = 1;
		this.chars[i].style.position = "relative";
		var trajectory = Math.random() * Math.PI * 2;
		this.chars[i].xTrans = Math.cos(trajectory);
		this.chars[i].yTrans = Math.sin(trajectory);
	}
}

TextEffect.prototype = {
	
	delay: function(opt)
	{
		setTimeout(function(){if (opt.callback) { opt.callback(); }}, opt.duration);
	},

	disperse: function(opt)
	{
		if (this.step == 0)
		{
			if (!opt){ opt = {}; }
			opt.fadeOut = true;
			opt.disperse = true;
			this.run(opt);
		}
	},

	assemble: function(opt)
	{
		if (this.step == 0)
		{
			if (!opt){ opt = {}; }
			opt.fadeIn = true;
			opt.assemble = true;
			this.run(opt);
		}
	},

	fadeIn: function(opt)
	{
		if (this.step == 0)
		{
			if (!opt){ opt = {}; }
			opt.fadeIn = true;
			this.reset();
			this.run(opt);
		}
	},

	fadeOut: function(opt)
	{
		if (this.step == 0)
		{
			if (!opt){ opt = {}; }
			opt.fadeOut = true;
			this.run(opt);
		}
	},

	reset: function()
	{
		for(var i=0; i < this.chars.length; i++)
		{
			this.chars[i].style.left = "0px";
			this.chars[i].style.top = "0px";
		}
	},

	run: function(opt)
	{	
		if (this.step == 0) { this.target.style.visibility = 'visible'; }
		if (!opt.steps) { opt.steps = 20; }
		if (!opt.stepSize) { opt.stepSize = 1; }
		if (!opt.stepDelay) { opt.stepDelay = 25; }
		this.step++;
		for(var i=0; i < this.chars.length; i++)
		{
			if (opt.fadeOut)
			{
				this.setOpacity(this.chars[i], 1-(this.step/opt.steps));
			}
			if (opt.fadeIn)
			{
				this.setOpacity(this.chars[i], this.step/opt.steps);
			}
			if (opt.assemble)
			{
				this.chars[i].style.left = (opt.stepSize * this.chars[i].xTrans * (opt.steps - this.step)) + 'px';
				this.chars[i].style.top = (opt.stepSize * this.chars[i].yTrans * (opt.steps - this.step)) + 'px';
			}
			if (opt.disperse)
			{
				this.chars[i].style.left = (opt.stepSize * this.chars[i].xTrans * this.step) + 'px';
				this.chars[i].style.top = (opt.stepSize * this.chars[i].yTrans * this.step) + 'px';
			}
		}
		if (this.step == opt.steps)
		{
			this.step = 0;
			if (opt.disperse || opt.fadeOut) { this.reset(); this.target.style.visibility = 'hidden'; }
			if (opt.callback) { opt.callback(); }
		}
		else
		{
			var self = this;
			setTimeout(function(){self.run(opt)}, opt.stepDelay);
		}
	},
	
	setOpacity: function (obj, op)
	{
		if(op>.99) {
			op = .99;
			return;
		}
		obj.style.opacity = op;
		obj.style.MozOpacity = op;
		obj.style.filter = "alpha(opacity=" + (op*100) + ")";
	}
}