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

//ANADIDO PARA CHECAR LAS COSAS DEL AUDIO


/***
	DETECTAMOS SI RECIBIMOS EL FRAGMENTO PARA AUTO SINTONIZAR
	Y SI ES ASI, LO PASAMOS DIRECTAMENTE A FLASH A VER SI SI ES
	UNA ESTACION VALIDA
	LO HICIMOS COMO FUNCION PARA PRIVATIZAR LA VARIABLE
***/

var estacionesAlternas	=	new Array();
estacionesAlternas[1]	=	['Radio Alicia','alicia','9000']
estacionesAlternas[2]	=	['Radio Guadalupe','guadalupe','9002']
estacionesAlternas[3]	=	['Hidrógeno Radio','hidrogeno','9004']
estacionesAlternas[4]	=	['Shock The Radio','shock','9006']
estacionesAlternas[5]	=	['Solaris Radio','solaris','9008']

var estadoReproductor	=	'stop';
var curEstacionId		=	null;
var trackId				=	null;
var reproductor			=	null;
var checandoProxy		=	false;
var checandoDatos		=	false;





function checarFragmento(){
	if(window.location.hash.length >= 4){
		
		if(navigator.userAgent.toLowerCase().indexOf('msie')){
			try{
				var ca = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
				if(ca){
					var ieHasFlash	=	true;
				} else {
					var	ieHasFlash	=	false;
				}
			}catch(e){
				var ieHasFlash	=	false;
			}
		}

		if(document.getElementById('grita') && navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] || ieHasFlash){
					

			//FLASH ESTA HABILITADO


			var objetoParam = 	document.getElementById('grita').getElementsByTagName('param')[8];
			
			if(objetoParam.getAttribute('name') == 'flashvars'){
				var atributoOriginal = objetoParam.getAttribute('value');
				objetoParam.setAttribute('value',atributoOriginal + '&autoSin=' + window.location.hash.split('#')[1]);
				
				var fOriginal	=	document.getElementById('grita').getAttribute('data');
				document.getElementById('grita').setAttribute('data','');
				document.getElementById('grita').setAttribute('data',fOriginal);
				
				//ANADIDO PARA EL SRC Y MOVIE

				objetoParam.parentNode.getElementsByTagName('param')[1].setAttribute('value','');
				objetoParam.parentNode.getElementsByTagName('param')[2].setAttribute('value','');

				objetoParam.parentNode.getElementsByTagName('param')[1].setAttribute('value',fOriginal);
				objetoParam.parentNode.getElementsByTagName('param')[2].setAttribute('value',fOriginal);
				
				
				//SI ES INTERNET EXPLORER DE PLANO RECARGAMOS TODO
				if(navigator.userAgent.toLowerCase().indexOf('msie')){
					var crearObjetoFlashIe	=	objetoParam.parentNode.cloneNode(true);
					objetoParam.parentNode.parentNode.removeChild(objetoParam.parentNode);
					document.getElementById('reproductorAlterno').appendChild(crearObjetoFlashIe);
				}				
			
				
			}

			
		} else if(document.getElementById('genReproAudio')){

			reproductor	=	document.getElementById('genReproAudio');

			if(reproductor && reproductor.canPlayType('audio/mpeg')){
				
				for(var i=0;i<estacionesAlternas.length;i++){

					if(estacionesAlternas[i][1] == window.location.hash.split('#')[1]){
						sintonizar(i);
						break;
					}
					
				}
				
			}
		}
		

	}
}


function sintonizar(idEst){
	
	reproductor	=	document.getElementById('genReproAudio');
	
	if(reproductor && reproductor.canPlayType('audio/mpeg') && __servidorStreaming.length >= 7){
		
		if(estacionesAlternas[idEst][0].length >= 4 && document.getElementById('reproAjaxInfo')){
			
			var construyeFuente			=	'http://'+__servidorStreaming+':666/proxy/'+estacionesAlternas[idEst][2]+'/listen.mp3';
			reproductor.style.visibility=	'visible';
			reproductor.src				=	'';
			reproductor.src				=	construyeFuente;
			reproductor.setAttribute('autoplay','autoplay');
			
			//
			document.getElementById('reproAjaxInfo').style.cssText	=	'';;
			curEstacionId				=	idEst;
			if(!checandoDatos) __rellenarInfoEstacAjax();
			if(!checandoProxy) __checarFinalDatosProxy();
			moverHashPlayer(estacionesAlternas[idEst][1]);
			
			if(document.getElementById('logoEstacionActual')){
				var LogoEstacion	=	document.getElementById('logoEstacionActual').getElementsByTagName('img')[0];
				LogoEstacion.src	=	_siteRoot + 'media/radio/estac/' + estacionesAlternas[idEst][1] + '.png';
				LogoEstacion.parentNode.style.visibility	=	'visible';
				
			}
			
			
			
		} else {
			
			var ventanaModal			=	new radioAlternativaModal();
			ventanaModal.nombre			=	'genPerfilModal';
			ventanaModal.crearVentana();
			
			var mensaje					=	crearEspacioMensaje('warning','No se puede reproducir la estación');
			ventanaModal.contenido		=	mensaje.innerHTML;
			ventanaModal.llenarVentana();
			
		}
		
	} else {
		var ventanaModal			=	new radioAlternativaModal();
		ventanaModal.nombre			=	'genPerfilModal';
		ventanaModal.crearVentana();
		
		var mensaje					=	crearEspacioMensaje('warning','¡Ùps! Tu equipo no puede reproducir el elemento Audio (HTML5). Tal vez quieras <a href="http://www.radioalternativa.com/movil">intentar con la versión para móvil</a>');
		ventanaModal.contenido		=	mensaje.innerHTML;
		ventanaModal.llenarVentana();
	}
	
}


function __rellenarInfoEstacAjax(){
	
	var conexion	=	new __invokeGuruAjax();
	conexion.url	=	_siteRoot + 'etc/ajax/ti.do?s=' + curEstacionId;
	
	conexion.onComplete	=	function(){
		
		if(conexion.fResponse[0] && conexion.fResponse[1].length >= 10){
			
			clo				=	document.getElementById('reproAjaxInfo').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];


			iCover		=	clo.getElementsByTagName('td')[1].getElementsByTagName('img')[0];
			iArtista	=	clo.getElementsByTagName('td')[0].getElementsByTagName('div')[0];
			iTitulo		=	clo.getElementsByTagName('td')[0].getElementsByTagName('div')[1];
			iAlbum		=	clo.getElementsByTagName('td')[0].getElementsByTagName('div')[2];
			iLike		=	clo.getElementsByTagName('td')[0].getElementsByTagName('a')[0];
			iInfo		=	clo.getElementsByTagName('td')[0].getElementsByTagName('a')[1];
			


			if(contenido.getAttribute('result') == '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');
				rLik		=	contenido.getAttribute('lik');
				tCom		=	contenido.getAttribute('com');
				
				iLike.style.visibility	=	'visible';
				iInfo.style.visibility	=	'visible';
				

				
			} else if(contenido.getAttribute('result') == '6'){
				
				trackId		=	0;
				titulo		=	'Transmisión en vivo';
				album		=	'Transmisión en vivo';
				cover		=	'';
				nombre		=	'RadioAlternativa.com';
				bUrl		=	'index.do';
				bDir		=	'';
				rLik		=	'';
				tCom		=	'';

				iLike.style.visibility	=	'hidden';
				iInfo.style.visibility	=	'hidden';
				
			} else {
				
				trackId		=	0;
				titulo		=	'Material desconocido';
				album		=	'Desconocido';
				cover		=	'';
				nombre		=	'Artísta desconocido';
				bUrl		=	'index.do';
				bDir		=	'';
				rLik		=	'';
				tCom		=	'';

				iLike.style.visibility	=	'hidden';
				iInfo.style.visibility	=	'hidden';
				
			}



			iArtista.innerHTML	=	'';
			iArtista.href		=	'';
			iTitulo.innerHTML	=	'';
			iAlbum.innerHTML	=	'';
			iLike.innerHTML		=	'';

			
			iArtista.innerHTML	=	nombre;
			iArtista.href		=	_siteRoot + bUrl;
			
			iTitulo.innerHTML	=	titulo;
			iAlbum.innerHTML	=	'del álbum &quot;' + album + '&quot;';
			
			iInfo.href			=	_siteRoot + bUrl + '?ref=player';
			
			if(cover.length > 4){
				
				iCover.src	=	_siteRoot + 'var/_profiles/' + bDir + '/p_' + cover + '.jpg';
				
			} else {
				
				iCover.src	=	_siteRoot + 'media/radio/at.jpg';
				
			}
			
			if(rLik == 'si'){
				iLike.innerHTML	=	'Te gusta';
				iLike.onclick	=	function(){ void(0) };
			} else if(rLik == 'no'){
				iLike.innerHTML	=	'Me gusta';
				iLike.onclick	=	function(){
					this.innerHTML	=	'Te gusta';
					this.onclick	=	function(){ void(0) };
					meGustaLaRola(trackId,'ra')
				}
			}
			
			if(tCom.length >= 2){
				iTitulo.setAttribute('originalTitlo',titulo);
				iTitulo.setAttribute('originalComentario',tCom);
				
				iTitulo.onmouseover =	function(){
					this.innerHTML	=	this.getAttribute('originalComentario');
				}
				iTitulo.onmouseout	=	function(){
					this.innerHTML	=	this.getAttribute('originalTitulo');
				}
				
			} else {
				
				iTitulo.removeAttribute('originalTitlo');
				iTitulo.removeAttribute('originalComentario');
				
				iTitulo.onmouseover =	function(){ void(0)}
				iTitulo.onmouseout	=	function(){ void(0)}
				
			}
			


			setTimeout("__rellenarInfoEstacAjax()", 6000);
			checandoDatos	=	true;
			
			
		}
		
	}
	
	conexion.callRequest();
	
}

function __checarFinalDatosProxy(){
	
	reproductor	=	document.getElementById('genReproAudio');
	
	if(reproductor && reproductor.canPlayType('audio/mpeg')){

		if(reproductor.error){
			
			var construyeFuente				=	'http://'+__servidorStreaming+':666/proxy/'+estacionesAlternas[curEstacionId][2]+'/listen.mp3';
			reproductor.style.visibility=	'visible';
			reproductor.src				=	'';
			reproductor.src				=	construyeFuente;
			reproductor.setAttribute('autoplay','autoplay');
			
			//
		
		}
		
		setTimeout("__checarFinalDatosProxy()",1000);
		checandoProxy	=	true;
		
		
	}
	
	
}








//SCADOS DE RADIOALTERNATIVA.JS


function __preparaLinksParaElPopup(){
	
	var todosLinks	=	document.getElementsByTagName('a');

	for(var i=0;i<todosLinks.length;i++){
		
		var curLink				=	todosLinks[i];
		if(curLink.getAttribute('miniplayer') != 'off'){
			curLink.onclick	=	function(){
				
				return(__confirmaAbrirMiniPlayer(this.href));
	
				
			}
		}
		
	}
	
	
}

function __realAbreMiniPlayer(){
	window.open(_siteRoot + 'mini.do#' + window.location.hash.substr(1), 'miniReproAlterno', 'width=380,height=200,status=0,menubar=0,resizable=0,location=0,toolbar=0');
}



function __confirmaAbrirMiniPlayer(enlace){
	
	switch(_inicioPlayerPop){
		
		case true:
			
			__realAbreMiniPlayer()
			return true;
			
		break;
		
		case false:
		
			return true;
		
		break;
		
		case null:
		
			__opnPrModWin('pPop',null,enlace);
			return false;
		
		break;
		
		default:
			return true;
		break;
		
	}
	
}


function __setMiniPlayer(cosa){
	
	contenedor				=	document.getElementById('genModalStatus');
	contenedor.innerHTML	=	mensajeCargando('Continuando...');
	
	if(cosa == 'si'){
		__realAbreMiniPlayer()
	}
	
	if(document.getElementById('ppp_recuerda').checked){
		
		conex		=	new __invokeGuruAjax();
		conex.url	=	_siteRoot + 'etc/ajax/radioPus.do?k=' + cosa;
		conex.onComplete	=	function(){
			window.location.href	=	document.getElementById('genPerfilModal').opt1;
		}
		conex.callRequest();
		
		
	} else {
		window.location.href	=	document.getElementById('genPerfilModal').opt1;
	}
}





