/*
 * Copyright (c) 2006 AWS Convergence Technologies, Inc. 
 * All rights reserved.
 * Visit http://www.aws.com
 *
 * WBProgressAnimator.js
 *
 * This scripts contains the WBProgressAnimator resuable class. A WBProgressAnimator
 * animates our progress during a task (such as a search.)
 */
 
 // Object definition
function WBProgressAnimator(div,steps,delay,path,timerString)
{
	this.progressDiv = div;       // the element that we're animating
	this.totalSteps = steps;      // the total number of animation steps
	this.delayTime = delay;       // time in miliseconds between animation steps
	this.path = path;             // path to the progress indicator images folder without the trailing '/'
	this.isIncrementing = true;   // controls direction of animation
		
	if( this.path.charAt(this.path.length - 1) != "/" )
		this.path += "/";
	
	this.currentStep = 0;         // sets the current animation being step to 0
	this.finishStep = steps - 1;  // sets the last step
	this.animating = false;       // current state of animating

	// Set the initial conditions of the layer
	this.progressDiv.style.visibility = "hidden";
	this.progressDiv.style.backgroundImage = "url('"+this.path+"0.png')";
	
	this.timer; // holds the timer for the drawing event		
}

// Do not call this function directly, only from an initialized WBProgressAnimator object.
// This starts the whole animation process.
WBProgressAnimator.prototype.start = function (timerString)
{
	if(this.animating == false)
	{
		this.isIncrementing = true;
		this.progressDiv.style.visibility = "visible";
		this.animating = true;
		this.timer = setInterval(timerString,this.delayTime);
	}
}

WBProgressAnimator.prototype.drawStep = function ()
{
	if(this.isIncrementing == true)
	{
		this.currentStep++;
		if(this.currentStep > this.finishStep)
			this.currentStep = 0;
	}
	else
	{
		this.currentStep--;
		if(this.currentStep < 0)
			this.currentStep = this.finishStep;
	}
	this.progressDiv.style.backgroundImage = "url('"+this.path+this.currentStep+".png')";
}

WBProgressAnimator.prototype.switchDirection = function ()
{
	if(this.isIncrementing == true)
		this.isIncrementing = false;
	else
		this.isIncrementing = true;
}

WBProgressAnimator.prototype.stop = function ()
{
	clearInterval(this.timer);
	this.progressDiv.style.visibility = "hidden";
	this.animating = false;
}