/**
* @version		$Id: infoticker.js 2008-10-31 Frederic $
* @package		Plugins
* @subpackage	InfoTicker
*/

/**
* InfoTicker gère l'affichage de messages.
*
* @package		Plugins
* @subpackage	InfoTicker
* @since		1.0
*/
var InfoTicker = new Class({
	/**
	* Initialise le système.
	*
	* @param String item Sélecteur CSS désignant un message
	* @param Integer displayDuration Durée d'afichage d'un message
	* @param Integer displayHide Sélecteur Durée de disparition d'un message
	* @access public
	* @since 1.0
	*/
    initialize: function(item, displayDuration, displayHide){
		this.displayDuration = displayDuration;
		this.displayHide = displayHide;
		this.list = $$(item);
		this.fx = new Array();
		for(i = 0; i < this.list.length; i++) {
			this.list[i].setStyle('opacity', 0);
			this.displayMessage(i);
		}
		this.fx[0].resume();
    },
	
	/**
	* Affiche un message.
	*
	* @param Integer i Indice du message dans la liste
	* @access protected
	* @since 1.0
	*/
    displayMessage: function(i){
		var obj = this;
		this.fx[i] = new Fx.Morph(obj.list[i], {duration: this.displayDuration, wait:false, transition:Fx.Transitions.Expo.easeOut});
		this.fx[i].start({
			'opacity': [0, 1]
		}).chain(
			function(){
				obj.hideMessage(i);
			}
		);
		
		this.fx[i].pause();
    },
	
	/**
	* Cache un message.
	*
	* @param Integer i Indice du message dans la liste
	* @access protected
	* @since 1.0
	*/
    hideMessage: function(i){
		var obj = this;
		var fx = new Fx.Morph(obj.list[i], {duration: this.displayHide, wait:false, transition:Fx.Transitions.Expo.easeOut});
		fx.start({
			'opacity': [1, 0]
		}).chain(
			function(){
				if(i == obj.list.length - 1) {
					i = -1;
				}
				obj.displayMessage(i + 1);
				obj.fx[i + 1].resume();
			}
		);
    }
});
