/*
 * Copyright (c) 2006 AWS Convergence Technologies, Inc. 
 * All rights reserved.
 * Visit http://www.aws.com
 *
 * WBState.js
 *
 * This scripts contains the WBState resuable class. A WBState object takes care
 * of the active/inactive state of the widget. This allows us to control the
 * updating of widget data depending on user interaction with the interface (ex:
 * clicking, mouseover, mouseout, etc...)
 */

// Object Definition
function WBTitleAnimator(livedataobj,element,counttoggle,state)
{
	this.object = livedataobj;
	this.stateobject = state;
	this.count = 0;
	this.element = element;
	this.countToggle = counttoggle;
	this.stationVisible;
	this.titleSet = false;
}

// Do not call this function directly, only from an initialized WBTitleAnimator object.
// This sets the title back to the station being visible as well as initial conditions.
WBTitleAnimator.prototype.end = function ()
{
	if(!this.stationVisible)
	{
		this.element.innerHTML = this.object.source;
		this.stationVisible = true;
	}
	this.count = 0;
}

// Do not call this function directly, only from an initialized WBTitleAnimator object.
// This adds one to the current count, then takes action depending on what the value
// of count is.
WBTitleAnimator.prototype.tick = function ()
{
	if(!this.titleSet)
	{
		this.element.innerHTML = this.object.source;
		this.stationVisible = true;
		this.titleSet = true;
	}
	else
	{
		this.count++;
		if(this.count >= this.countToggle)
		{
			this.count = 0;
			if(!this.stationVisible && this.stateobject.state)
			{
				this.element.innerHTML = this.object.source;
				this.stationVisible = true;
			}
			else if(this.stateobject.state)
			{
				this.element.innerHTML = this.object.location;
				this.stationVisible = false;
			}
		}
	}
}