if (!window.IBubble)
	var IBubble = new Object();

IBubble.Methods = {
	IBubble : false,
	waitingList : new Array(),
	options : {
		idBubble : 'infoBubble',
		defaultDuration : 3, // secondes
		defaultTop : 200 // px
	},
	// Ajout/Suppression de favori
	show : function(text, params){
		if(this.IBubble === false){
			$$('body')[0].insert( {bottom : '<div id="'+this.options.idBubble+'" class="d_infos_general t_infos_general s_infos_general" style="display: none;"><img src="inc/img/icons-infos.png" alt="informations" width="5" height="28" /><p></p></div>'} );
			this.IBubble = $(this.options.idBubble);
		}		
	
		i = 0;
		while(typeof(this.waitingList[parseInt(this.waitingList.length+i)]) != 'undefined')
			i++;
			
		found = false;
		if(typeof(text) != 'undefined' && text == 'AJAX_connexion_failure'){
			// Vérifier qu'il n'y a pas déjà des message de ce type en attente, le chat risque de surcharger la liste en cas de déco
			this.waitingList.each( function(t){
					if(t[0] == 'AJAX_connexion_failure')
						found = true;
				});
		}
		
		if(typeof(text) != 'undefined' && found == false)
			this.waitingList[parseInt(this.waitingList.length+i)] = [text, params];
		
		if(!this.IBubble.visible())
			this._show();
	},
	_show : function(){
		if(this.waitingList.length != 0){
			i = 0;
			while(typeof(this.waitingList[i]) == 'undefined')
				i++;
			text = this.waitingList[i][0];
			params = this.waitingList[i][1];
			
			// Paramètres :
			var newTop = 0;
			if(typeof(params) != 'undefined'){
				// top
				if(typeof(params.top) != 'undefined')
					newTop = params.top;
				else
					newTop = this.options.defaultTop;
				// duration
				if(typeof(params.duration) != 'undefined')
					duration = params.duration;
				else
					duration = this.options.defaultDuration;
			}
			else{
				newTop = this.options.defaultTop;
				duration = this.options.defaultDuration;
			}
			
			this.IBubble.firstDescendant().next().update(text);
			this.IBubble.setStyle({
					top : newTop+'px',
					left : parseInt($$('body')[0].getWidth()/2 - (this.IBubble.getWidth()/2))+'px'
				});
			this.IBubble.appear();
			this.waitingList = this._unset(i);
			
			(function(){
					this.IBubble.hide();
					this.show();
				}).bind(this).delay(duration);
		}
	},
	_unset : function(index){
		tmp = new Array();
		
		for(i=0;i<=this.waitingList.length;i++){
			if(typeof(this.waitingList[i]) != 'undefined' && i != index)
				tmp[tmp.length] = this.waitingList[i]
		}
		
		return tmp;
	}
};

Object.extend(IBubble, IBubble.Methods);