/**
 * Import ColorTools.js first
 * Import EffectHandler.js first
 * (c) 2005 Mat Gessel
 */

/**
 * ThrobEffect
 */
ThrobEffect.RED = 0;
ThrobEffect.GREEN = 1;
ThrobEffect.BLUE = 2;

ThrobEffect.prototype = new AbstractEffect();
ThrobEffect.prototype.constructor = ThrobEffect;

/**
 * Constructor
 * @param interval the animation delay in ms
 * @param steps the number of color steps used to blend the specified colors (including starting and ending steps)
 * @param foreground a six-digit color string in "#00FF99" format
 * @param background a six-digit color string in "#00FF99" format
 */
function ThrobEffect(interval, steps, foreground, background)
{
	this.initThrobEffect(interval, steps, foreground, background);
}

ThrobEffect.prototype.initThrobEffect = function(interval, steps, foreground, background)
{
	this.initAbstractEffect(interval);
	if (foreground == null)
	{
		foreground = "#0064C0";
	}
	if (background == null)
	{
		background = "#FFFFFF";
	}
	this.m_originalColor = null;
	var fgColorArray = ColorTools.parseColor(foreground);
	var bgColorArray = ColorTools.parseColor(background);
	this.m_colorArray = ColorTools.blendColors(steps, bgColorArray, fgColorArray);
	this.m_increment = 1;
	this.m_currentIndex = -1;
};

ThrobEffect.prototype.initState = function()
{
	this.m_currentIndex = 0;
}

ThrobEffect.prototype.doStart = function()
{
	// backup original color
	if (this.m_originalColor == null)
	{
		this.m_originalColor = this.m_target.style.background;
	}
	
	this.initState();
	
	// do first step
	this.startLoop();
};

ThrobEffect.prototype.doStep = function()
{
	var r = this.m_colorArray[ThrobEffect.RED][this.m_currentIndex];
	var g = this.m_colorArray[ThrobEffect.GREEN][this.m_currentIndex]
	var b = this.m_colorArray[ThrobEffect.BLUE][this.m_currentIndex]
	this.m_target.style.background = "rgb(" + r + "," + g + "," + b + ")";
	if (this.m_currentIndex == 0)
	{
		this.m_increment = 1;
	}
	else if (this.m_currentIndex == this.m_colorArray[0].length - 1)
	{
		this.m_increment = -1;
	}
	this.m_currentIndex += this.m_increment;
};

ThrobEffect.prototype.doFinish = function()
{
	this.stopLoop();
	
	// restore original color
	this.m_target.style.background = this.m_originalColor;
};

