/*
@name: /htdocs/js/lib/oggetti/effectlist.js
@desc: Componente javascript moo effect list
@authors: Marco Biondi
@lastauthor: Marco Biondi
*/
var EffectList = Class.create();
EffectList.prototype = {
	initialize: function() {
		this._list = new Array();
		this._playing = false;
	},

	cleanList: function() {
		this._list = new Array();
	},

	addEffect: function(fx, a, b) {
		var foo = new Object();
		foo.efx = fx;
		fx.options.onComplete = function() {this.__ctrl._onComplete();};
		fx.__ctrl = this;

		if(arguments.length == 3)
		{
			foo.a = a;
			foo.b = b;
		}

		this._list.unshift(foo);
	},

	playList: function() {
		if(!this._playing)
			this._onComplete();
	},

	pauseList: function() {
		//TODO: blocca l'esecuzione dell'effetto corrente e lo reinserisce in lista
	},

	isPlaying: function() {
		return(this._playing);
	},

	_onComplete: function() {
		if(this._list.length > 0)
		{
			var foo = this._list.pop();
			if(foo.a)
				foo.efx.custom(foo.a,foo.b);
			else
				foo.efx.toggle();
			this._playing = true;		
		}
		else
			this._playing = false;
	}
}
