document.observe("dom:loaded", function() {
	// SlideShow
	$('iBanner').show();
	slideShow 	= new window.shogazi.Ticker();
	slideShow.playTicker(5);
});

function shogazi() {}

/* Slide-Show */
shogazi.Ticker = Class.create(
{	
	_speed: 6,						// Geschwindigkeit in Sek. (Solange wird das ein Bild angezeigt)
	_speedAfter: 140,				// Zeitverzögerung nach der Ausblendung in Mili-Sek.
	_timeout: "",
	
	_tickerBoxes: new Array(),
	_tickerIndex: 0,


	/**
	 * Constructor - initializes the NewsTicker-Animation
	 *
	 * @constructs
	 *
	 * @param   {Integer}   pSpeed   Time for FadeIn/FadeOut in Seconts (default: 8 Sek)
	 */
	initialize: function()
	{
		this._tickerBoxes = $("iBanner").select("a");
		this._tickerIndex = this._tickerBoxes.length-1;
	},
	
	
	/**
	 * Start Animation
	 *
	 */
	playTicker: function(pSpeed)
	{
		this._speed = (pSpeed != null) ? pSpeed : this._speed;
		this._switchTickerIn();
	},
	
	
	/**
	 * Stop Animation
	 *
	 */
	stopTicker: function()
	{
		window.clearTimeout(this._timeout);
	},
	
	
	
	/**
	 * Controls the FadeIn/FadeOut Animation. This mehod use the Effect.Fade- and Effect.Appear-method from Script.Aculo.us
	 *
	 */
	_switchTickerIn: function()
	{
		var currentTickerIndex 	= this._tickerIndex;
		var nextTickerIndex 	= (currentTickerIndex >= this._tickerBoxes.length-1) ? 0 : currentTickerIndex+1;
		
		Effect.Fade(this._tickerBoxes[currentTickerIndex]);
		this._timeout = window.setTimeout(this.__switchTickerOut.bind(this, nextTickerIndex), this._speed*this._speedAfter);
	},
	
	__switchTickerOut: function(pCextTickerIndex)
	{
		Effect.Appear(this._tickerBoxes[pCextTickerIndex]);
		
		this._tickerIndex++;
		this._tickerIndex = (this._tickerIndex >= this._tickerBoxes.length) ? 0 : this._tickerIndex;
		
		this._timeout = window.setTimeout(this._switchTickerIn.bind(this), this._speed*1000);
	}
});
