
var ScriptLoader = function(scripts){

 	this.scripts = scripts || [];
 	this.count = 0;

	this.addEvents({load:true, done:true});
	
	this.on('load', this.onLoad, this);	
}

Ext.extend(ScriptLoader, Ext.util.Observable,{

 	scripts : null,
 	count : 0,
 	 
	load : function(){
	 	if (this.scripts.length > 0) this.loadScript(this.scripts[0]);
	},
	
	loadScript : function(script){
		Ext.Ajax.request({method: script.method || 'GET', scope:this, url:script.url, success: function(response){
			eval(response.responseText);
			this.fireEvent('load');
		}});
	},
	
	onLoad : function(){
		this.count++;
		if (this.count == this.scripts.length) this.fireEvent('done');
		else {
			this.loadScript(this.scripts[this.count]);
		}		
	}

});
