/*	aloader - async crossdomain javascript loader written by Artico Bandurini [artico@overdesign.net]
	usage: aloader.load(path_to_js_file, callback_function);
	callback_function will be called in the window scope with no arguments
*/
aloader = {
	queue: [],
	queueCallback: null,
	load: function(src, callback){
		if(src instanceof Array){
			if(!src.length){
				return false;
			}
			else if(src.length == 1){
				src = src[0];
			}
			else{
				this.queue = src;
				this.queueCallback = callback;
				callback = null;
				src = this.queue[0];
			}
		}
		if(!src){
			return false;
		}
		var tag = document.createElement('script');
		var holder = document.getElementsByTagName('head')[0] || document.body;
		tag.src = src;
		holder.appendChild(tag);
		var receive = function(){
			if(aloader.queue.length && src == aloader.queue[0]){
				aloader.queue.shift();
				if(aloader.queue.length){
					aloader.load(aloader.queue[0]);
				}
				else{
					callback = aloader.queueCallback;
				}
			}
			if(callback){
				callback.call(tag);
			}
			tag.parentNode.removeChild(tag);
		};
		if(navigator.userAgent.indexOf('MSIE') >= 0){
			tag.onreadystatechange = function(){
				if(this.readyState == 'loaded' || this.readyState == 'complete'){
					receive();
				}
			}
		}
		else{
			tag.onload = receive;
		}
	}
};