Solow123.TextFileLoader = XHR.extend({
	fileContent: '',
	onFileLoad : Class.empty,
	onSuccess : function() {
		this.doTest();
	},
	onFailure : function() {
		this.doTest();
	},
	doFileLoad : function (url) {
		this.send(url);	
	},
	doTest : function () {
		if ($defined(this.transport.responseText)) {
			this.fileContent = this.transport.responseText;
			this.fireEvent('onFileLoad');	
		}
		else {
			this.fileContent = 'Could not load';
			this.fireEvent('onFailure');
		}
	},
	evalScripts: function(){
		var scripts = [];
		var regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
		while ((script = regexp.exec(this.fileContent))) scripts.push(script[1]);
		scripts = scripts.join('\n');
		if (scripts) (window.execScript) ? window.execScript(scripts) : window.setTimeout(scripts, 0);
	},
	evalStyles: function () {
		var styles = [];
		var styregexp = /<style[^>]*>([\s\S]*?)<\/style>/gi;
		while ((style = styregexp.exec(this.fileContent))) styles.push(style[1]);
		styles = styles.join('\n');
		
		if (styles) {
			var snode = new Element('style', {'type': 'text/css'});
			snode.setHTML(styles);
			$$('body')[0].adopt(snode)
		}
	}
});
