/**---------------------------------------------------------------------------------------------------
 *
 * File:		dynamicstats.js
 * Date:		25.07.2007
 * Description:	Dynamic Statistics
 *
 * Usage:
 *
 *--------------------------------------------------------------------------------------------------*/

var	COLUP	= 1,
	COLDOWN	= 2;

/**---------------------------------------------------------------------------------------------------
 *
 * Stats methods
 *
 */
function DynamicStats( name )
{
	this.name		= name;
	this.list		= new Array;
	this.count		= new Array;
	this.timer		= new Array;
	this.colUp		= new Array( "#00FF00", "#20FF20", "#40FF40", "#60FF60", "#80FF80", "#A0FFA0", "#C0FFC0", "#E0FFE0", "#FFFFFF" );
	this.colDown	= new Array( "#FF0000", "#FF2020", "#FF4040", "#FF6060", "#FF8080", "#FFA0A0", "#FFC0C0", "#FFE0E0", "#FFFFFF" );
	
	
	/**
	 *
	 */
	this.set = function( name, value )
	{
		if ( value == "" )
			value = 0;
			
		if ( this.list[name] != value && document.getElementById( name ) )
		{
			this.count[name] = 0;
			
			if ( parseInt( this.list[name] ) > parseInt( value ) )
			{
				this.add( name, value );
				this.update( this.name, name, COLDOWN );
			}
			else
			{
				this.add( name, value );
				this.update( this.name, name, COLUP );
			}
		}
	}
	
	/**
	 *
	 */
	this.add = function( name, value )
	{
		this.list[name] = value;
		this.output( name, value );
	}
	
	/**
	 *
	 */
	this.output = function( name, value )
	{
		document.getElementById( name ).innerHTML = value;
	}
	
	/**
	 *
	 */
	this.update = function( obj, name, direction )
	{
		clearTimeout( this.timer[name] );
		
		if ( this.count[name] < this.colUp.length )
		{
			if ( direction == COLUP )
				col = this.colUp[ this.count[name]++ ];
				
			else if ( direction == COLDOWN )
				col = this.colDown[ this.count[name]++ ];
				
			document.getElementById( name ).style.backgroundColor = col;
			
			this.timer[name] = setTimeout( obj + ".update( '" + obj + "', '" + name + "', " + direction + " );", 200 );
		}
		else
			document.getElementById( name ).style.backgroundColor = "";
	}
}


/*--------------------------------------------------------------------------------------------------*/
