//----------------------------------------------------------------------------------------------------------------------
/**
 * This file contains the {@link IconTimer} class
 *
 * @author      Blue Moon IT <info@bluemoonit.net>
 * @copyright   2008, Blue Moon IT
 * @package     ApolloTemplate
 * @subpackage  Javascript
 * @version     SVN: $Id: icontimer.js 117 2009-03-18 14:31:07Z johan $
 */
//----------------------------------------------------------------------------------------------------------------------
/**
 * Class to display the various icons in succession
 *
 * @package     ApolloTemplate
 * @subpackage  Javascript
 * @author      Johan B.W. de Vries <johan@bluemoonit.net>
 */
IconTimer = function()
{
	this.iconCount = 0;

	this.delay     = 3000;

	this.basePath  = '/';

	this.aPrefix   = 'ic';
	this.divPrefix = 'tt';

	this._started     = false;
	this._currentIcon = null;
	this._stopped     = false;

	this.start = function()
	{
		this._started     = true;
		this._stopped     = false;
		this._currentIcon = 1;

		this._nextIcon();
	}

	this.stop = function()
	{
		if( !this._started ) {
			return;
		}

		this._stopped = true;

		this._hideIcon(this._currentIcon - 1);
	}

	this._nextIcon = function()
	{
		if( 1 < this._currentIcon ) {
			this._hideIcon(this._currentIcon - 1);
		}

		if( this._stopped || (this.iconCount < this._currentIcon) ) {
			return;
		}

		this._showIcon(this._currentIcon);

		this._currentIcon++;

		//Run once extra to hide the last icon
		if( this._currentIcon <= this.iconCount + 1 ) {
			var myContext = this;
			window.setTimeout(
				function() {
					myContext._nextIcon.apply(myContext);
				},
				this.delay
			);
		} else {
			this._stopped = true;
		}
	}

	this._getA = function(nr)
	{
		return document.getElementById(this.aPrefix + nr);
	}

	this._getDiv = function(nr)
	{
		return document.getElementById(this.divPrefix + nr);
	}

	this._hideIcon = function(nr)
	{
			var a   = this._getA(nr);
			var div = this._getDiv(nr);

			a.style.backgroundImage = '';

			div.style.display = 'none';
			div.style.display = '';
			div.style.zIndex = '2';
	}

	this._showIcon = function(nr)
	{

		var a   = this._getA(nr);
		var div = this._getDiv(nr);

		a.style.backgroundImage = 'url("' + this.basePath + 'styles/apollo/default/img/icon/icon-'+ nr + '-h.png")';

		div.style.right   = '46px';
		div.style.float   = 'left';
		div.style.display = 'inline';
		div.style.zIndex  = '1';
	}
}
//----------------------------------------------------------------------------------------------------------------------
