/*	aloader - sync/async crossdomain javascript loader written by Artico Bandurini [artico.bandurini@gmail.com]
	usage: aloader.load(path_to_js_file, callback_function);
	callback_function will be called in the window scope with 1 argument - HTMLElement of loaded script
*/
aloader = {
	queue: [],
	queueCallback: null,
	load: function(src, callback, async, holder){
		if(src instanceof Array){
			if(!src.length){
				return false;
			}
			else if(src.length == 1){
				src = src[0];
			}
			else{
				aloader.queue = src;
				aloader.queueCallback = callback;
				callback = null;
				src = aloader.queue[0];
			}
		}
		if(!src){
			return false;
		}
		var tag = document.createElement('script'),
		self = this;
		if (!holder) {
			holder = document.getElementsByTagName('head')[0] || document.body;
		}
		tag.async = async ? true : false;
		tag.src = src;
		holder.appendChild(tag);
		var receive = function(tag){
			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(typeof callback == 'function'){
				callback.call(self, tag);
			}
			if (tag && tag.parentNode) {
				tag.parentNode.removeChild(tag);
			}
		};
		if(navigator.userAgent.indexOf('MSIE') >= 0){
			tag.onreadystatechange = function(){
				if(this.readyState == 'loaded' || this.readyState == 'complete'){
					receive(this);
				}
			};
		}
		else{
			tag.onload = function(){
				receive(this);
			};
		}
	}
};


var radiollaButtonId = 'radiollaButton_' + Math.ceil(Math.random()*100000000);

document.writeln('<a target="_blank" href="' + (document.location.protocol == 'https:' ? 'https' : 'http') + '://radiolla.com/" style="border:none;text-decoration:none;position:relative;display:block;width:120px;height:60px;">');
document.writeln('<img src="' + (document.location.protocol == 'https:' ? 'https' : 'http') + '://radiolla.com/style/img/button/logo_white.gif" style="border:none;" alt="Radiolla" title="Radiolla - Easy listening internet radio" />');
document.writeln('<span style="position:absolute;top:12px;left:91px;display:block;width:19px;height:19px;cursor:pointer;background-repeat:no-repeat;background-position:top;background-image:url(' + (document.location.protocol == 'https:' ? 'https' : 'http') + '://radiolla.com/style/img/button/button_play.gif);visibility:hidden;" title="Play / Stop" id="'+radiollaButtonId+'"></span></a>');

aloader.load((document.location.protocol == 'https:' ? 'https' : 'http') + '://radiolla.com/play/uniplayer/flash-windowsmedia-vlc.js', function(){
	
	var uniplayer = new Uniplayer({
		src: 'http://air.radiolla.com/radiolla.128k.mp3',
		mimetype: 'audio/mpeg',
		volume: .7,
		autoload: true,
		autoplay: false,
		showSupply: false,
		showControls: false,
		background: '#FFFFFF',
		hideStartLogo: true
	});
	
	// modules
	uniplayer.addModule(new UniplayerFlashJWPlayer({swf: (document.location.protocol == 'https:' ? 'https' : 'http') + '://radiolla.com/play/jwplayer.swf'}));
	if(navigator.userAgent.indexOf('MSIE')>=0){
		uniplayer.addModule(new UniplayerWindowsMedia);
	}
	uniplayer.addModule(new UniplayerVLC);
	uniplayer.write();
	
	// connect button
	var button = document.getElementById(radiollaButtonId);
	button.onmouseover = function(){
		this.style.backgroundPosition = 'bottom';
	};
	button.onmouseout = function(){
		this.style.backgroundPosition = 'top';
	};
	button.onclick = function(){
		if(uniplayer.current.state == uniplayer.states.stopped){
			uniplayer.play();
			this.style.backgroundImage = 'url(' + (document.location.protocol == 'https:' ? 'https' : 'http') + '://radiolla.com/style/img/button/button_stop.gif)';
		}
		else{
			uniplayer.stop();
			this.style.backgroundImage = 'url(' + (document.location.protocol == 'https:' ? 'https' : 'http') + '://radiolla.com/style/img/button/button_play.gif)';
		}
		//button.parentNode.blur();
		return false;
	};
	button.style.visibility = 'visible';
});

