Ext.ux.OnDemandLoadByAjax = function() {
	var count;
	var components;
	var callback;
	loadComponent = function() {
		if (count == components.length && typeof callback == "function") {
			callback.defer(150);
		};
		if(count < components.length && components[count]) {
			var scriptUrl = components[count];
			var fileName = scriptUrl;
			var scriptTag = document.getElementById(fileName);
			
			handleSuccess = function(response, options) {
//				var headTag = document.getElementsByTagName('head')[0];
				var headTag = document.getElementById('script-load');
				var type = scriptUrl.substring(scriptUrl.lastIndexOf('.') + 1);

				switch(type) {
					case 'js':
						scriptTag = document.createElement('script');
						scriptTag.setAttribute('type','text/javascript');
						scriptTag.setAttribute('src',scriptUrl);
						scriptTag.setAttribute('id',fileName);
		//				scriptTag.innerHTML = response.responseText;
						headTag.appendChild(scriptTag);
		//				eval(response.responseText);
						break;
					case 'css':
						cssTag = document.createElement('link');
						cssTag.setAttribute('rel','stylesheet');
						cssTag.setAttribute('type','text/css');
						cssTag.setAttribute('href',scriptUrl);
						cssTag.setAttribute('id',fileName);
						headTag.appendChild(cssTag);
						break;
				};
				count++;
				loadComponent();
			};
	
			handleFailure = function(response, options) {
				alert('Dynamic load script: [' + components[count] + '] failed!');
			};
	
			if(!scriptTag) {
//			if(true) {
				Ext.Ajax.request( {
					url : components[count],
					method : 'GET',
					success : handleSuccess,
					failure : handleFailure,
					disableCaching : false
				});
			}
			else {
				count++;
				loadComponent();
			}
		}
	};

	return {
		load: function(comps, call) {
			count = 0;
			components = comps;
			callback = call;
			loadComponent();
		}
	};
}();
