// JavaScript Document
//Insertado para mantener UTF-8 en Dreamweaver: æø



function __detectarCompatibilidad(){
	
	if(document.getElementById('reproductorSuperChido')){
		
		contu	=	document.getElementById('reproductorSuperChido');
		flaOb	=	document.createElement('object');
		
		if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && flaOb){
			
			flaOb.id		=	'grita';
			flaOb.name		=	'grita';
			flaOb.data		=	'media/play/mini-movil.swf';
			flaOb.width		=	'364';
			flaOb.height	=	'188';
			flaOb.type		=	'application/x-shockwave-flash';
			
			flaOb.innerHTML	=	'<param name="quality" value="high" />' +
								'<param name="movie" value="media/play/mini-movil.swf" />' +
								'<param name="src" value="media/play/mini-movil.swf" />' +
								'<param name="bgcolor" value="#ffffff" />' +
								'<param name="wmode" value="transparent" />' +
								'<param name="allowfullscreen" value="true" />' +
								'<param name="allowscriptaccess" value="samedomain" />' +
								'<param name="type" value="application/x-shockwave-flash" />' +
								'<param name="flashvars" value="sessionUid=0" />' +
								'<param name="codebase" value="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" />' +
								'<param name="pluginurl" value="http://www.adobe.com/go/getflashplayer" />' +          
        						'¡Úps! tu explorador no soporta Flash, que es requerido para sintonizar RadioAlternativa.com. Tal vez quieras <a href="http://www.macromedia.com/go/getflashplayer">descargar flash</a> o <a href="http://www.radioalternativa.com/movil">intenter con la versión móvil de RA.</a>';

			
			contu.innerHTML	=	'';
			contu.appendChild(flaOb);

			


			
		} else {
			
			reproductor	=	document.createElement('audio');
			tabla		=	document.createElement('table');
			if(typeof(reproductor.canPlayType) == "function" && reproductor.canPlayType("audio/mpeg") !== '' && tabla){
				
				
				tabla.className	=	'mpt';
				
				cuerpo		=	document.createElement('tbody');
				tr1			=	document.createElement('tr');
				
				td_1_1		=	document.createElement('td');
				td_1_2		=	document.createElement('td');
				
				td_1_1.innerHTML	=	'Escucha';
				td_1_1.className	=	'header';
				
				td_1_2.innerHTML	=	'RadioAlternativa';
				td_1_2.className	=	'header';

				
				
				
				tr1.appendChild(td_1_1);
				tr1.appendChild(td_1_2);

				
				cuerpo.appendChild(tr1);
				tabla.appendChild(cuerpo);

				for(i=1;i<estaciones.length;i++){
					
					curEstacion	=	estaciones[i].split(',');
					
					nuevoTr	=	document.createElement('tr');
					td1		=	document.createElement('td');
					td2		=	document.createElement('td');
					
					td1.style.fontWeight	=	'bold';
					td2.style.textAlign		=	'center';
					
					td1.innerHTML			=	curEstacion[0];
					enlace					=	document.createElement('a');
					enlace.innerHTML		=	'Sintonizar';
					enlace.href				=	"javascript:_sintonizar('"+curEstacion[2]+"');";
					td2.appendChild(enlace);
					
					
					nuevoTr.appendChild(td1);
					nuevoTr.appendChild(td2);
					cuerpo.appendChild(nuevoTr);
					
					
				}
				


				
				contu.innerHTML	=	'';
				contu.appendChild(tabla);
				__gtl('f','mrj');
				
			} 
			
		}
		
	}
	
}



function _sintonizar(ia){

	reproductor	=	document.createElement('audio');

	if(typeof(reproductor.canPlayType) == "function" && reproductor.canPlayType("audio/mpeg") !== '' && document.getElementById('superReproductor')){

			
			contenedor	=	document.getElementById('superReproductor');
			racu		=	estaciones[ia].split(',');
			
			if(racu[3].length === 4){
				
				contenedor.innerHTML	=	'';
				
			
				direccion	=	'http://' + strAddre +  ':666/proxy/' + racu[3] + '/listen.mp3';
			
				reproductor.setAttribute('controls','controls');
				reproductor.setAttribute('preload','none');
				reproductor.setAttribute('autoplay','autoplay');
				reproductor.setAttribute('id','raHtml5Audio');
				reproductor.setAttribute('loop','true');
				reproductor.setAttribute('type','audio/mpeg');
				reproductor.setAttribute('src', direccion);
				
				contenedor.appendChild(reproductor);
				
				reproductor.onerror	=	function(){
					_reiniciarRepro(ia);
				}
				
				_obtenerInfo(ia);
				//setTimeout("_detectarFinal("+ia+")",500);
				
			} else {
				
				alert('Desconocido');
				
			}

		
	}
	
	
}



function _reiniciarRepro(efefe){
	
	if(document.getElementById('raHtml5Audio')){
		
		re	=	document.getElementById('raHtml5Audio');
		if(re.error != null){
			
			_sintonizar(efefe);
			
		}
		
	}
	
	
}

function _obtenerInfo(ei){
	
	if(document.getElementById('raHtml5Audio') && document.getElementById('superInformacion')){
	
		er				=	estaciones[ei].split(',');
		repro			=	document.getElementById('raHtml5Audio');
		
				
		if(er[3].length === 4){
		
			conexion		=	new __invokeGuruAjax();
			conexion.url	=	_siteRoot + 'etc/ajax/ti.do?s=' + ei;
			
			conexion.onComplete	=	function(){
				
				if(conexion.fResponse[0] && conexion.fResponse[1].length >= 10){
					
					document.getElementById('superInformacion').style.display	=	'block';
					document.getElementById('superInformacion').getElementsByTagName('table')[0].style.width		=	(repro.scrollWidth || repro.clientWidth) + 'px';
					clo				=	document.getElementById('superInformacion').getElementsByTagName('tr')[0];
					
					
					if(window.DOMParser){
						datosXML	=	(new DOMParser()).parseFromString(conexion.fResponse[1], 'text/xml');
					} else {
						datosXML		=	new ActiveXObject("Microsoft.XMLDOM");
						datosXML.async	=	"false";
						datosXML.loadXML(conexion.fResponse[1]);
					}
					
					contenido	=	datosXML.getElementsByTagName('rola')[0];
					
					trackId		=	contenido.getAttribute('tid');
					titulo		=	contenido.getAttribute('tit');
					album		=	contenido.getAttribute('alb');
					cover		=	contenido.getAttribute('alc');
					nombre		=	contenido.getAttribute('bdn');
					bUrl		=	contenido.getAttribute('bur');
					bDir		=	contenido.getAttribute('dir');
					
					iCover		=	clo.getElementsByTagName('td')[0];
					iArtista	=	clo.getElementsByTagName('td')[1].getElementsByTagName('a')[0];
					iTitulo		=	clo.getElementsByTagName('td')[1].getElementsByTagName('span')[0];
					iAlbum		=	clo.getElementsByTagName('td')[1].getElementsByTagName('span')[1];
					
					iCover.innerHTML	=	'';
					iArtista.innerHTML	=	'';
					iArtista.href		=	'';
					iTitulo.innerHTML	=	'';
					iAlbum.innerHTML	=	'';
					
					iArtista.innerHTML	=	nombre;
					iArtista.href		=	_siteRoot + bUrl;
					
					iTitulo.innerHTML	=	titulo;
					iAlbum.innerHTML	=	'del álbum &quot;' + album + '&quot;';
					
					if(cover.length > 4){
						
						nuevoCover		=	new Image(70,70);
						nuevoCover.src	=	_siteRoot + 'var/_profiles/' + bDir + '/p_' + cover + '.jpg';
						nuevoCover.className	=	'cover';
						iCover.appendChild(nuevoCover);
						
					}
					


					setTimeout("_obtenerInfo('"+ei+"')", 6000);	
					
				}
				
			}
			
			conexion.callRequest();
			
			
		}
		
		
	}
		
	
}

function __invokeGuruAjax(){
	
	var __callConnect;
	
	if(window.XMLHttpRequest){
		__callConnect		= new XMLHttpRequest();
	} else if(window.ActiveXObject){
		try{
			__callConnect	= new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			__callConnect	= new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else {
		__callConnect = false;
	}
	if(__callConnect){
		this.method		= 'GET';
		this.url		= null;
		this.postData	= null;
		this.onComplete	= function(){};
		this.fResponse	= null;
		var that		= this;
		
		this.callRequest = function(){
			if(this.url.length >= 1){
				try{
					__callConnect.onreadystatechange = function(){
						if(__callConnect.readyState == 4){
							if(__callConnect.status == 200){
								that.fResponse	= [true,__callConnect.responseText];
								that.onComplete();	

							} else {
								
								that.fResponse	= [false,'bad_response'];
								that.onComplete();
							}
						}
					}
					switch(this.method){
						case 'GET':
							__callConnect.open("GET",this.url,true);
							__callConnect.send(null);							
						break;
						case 'POST':
							__callConnect.open("POST",this.url,true);
							__callConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
							__callConnect.send(this.postData);
						break;
						default:
							alert('Error interno de programa / Internal program error: method_unknown')
							that.fResponse	= [false,'method_unknown'];
							that.onComplete();
						break;
					}

				} catch (e){
					alert('Error interno del explorador / Internal browser error\r\n\r\n' + e)
					that.fResponse	= [false,'browser_error'];
					that.onComplete();
				}
			} else {
				alert('Error interno de programa / Internal program error: empty_url')
				that.fResponse	= [false,'empty_url'];
				that.onComplete();
			}
		}
		
	} else {
		alert('ERROR:\r\n\r\nTu explorador no soporta XmlHttpRequest, que es requerido para este sitio.\nYour browser does not support XmlHttpRequest, which is required for this website.')
		return false;
	}
}
