// *****************************************************
// *****************************************************
// CONTROL DEL LECTOR AUDIO
// *****************************************************
// *****************************************************

var wimpy_launched = 0;
var zoplayer = null;
var wimpy_plist = '';


// *****************************************************
// INICIAR LECTOR (interno o externo) EN PAGINA DE BANDA

function ext_init(odest) {
	dest = odest.toLowerCase();
	wimpy_plist = '/MEDIA/'+dest.substr(0,1)+'/'+dest+'/playlist.xml';
	return;
	
	if (document.cookie.indexOf('ext_player=1') != -1) {
		document.getElementById('wimpyTarget').style.display = 'none';
		document.getElementById('pvacio').style.display = '';
		out = '<a href="javascript:void(null)" onclick="ext_stop()">[interno]</a>';
		document.getElementById('ext_ctl').innerHTML = out;
	}
	else {
		makeWimpyPlayer(wimpy_plist);
		wimpy_launched = 1;
		out = "<a href=\"javascript:void(null)\" onclick=\"ext_start('')\">[externo]</a>";
		document.getElementById('ext_ctl').innerHTML = out;
	}
}


// *****************************************************
// LANZAR LECTOR EXTERNO, OCULTAR INTERNO

function ext_start() {
	wimpy_stop();
	document.getElementById('wimpyTarget').style.display = 'none';
	document.getElementById('pvacio').style.display = '';
	zoplayer = window.open('/AUDIOS/extplayer.php?plist='+wimpy_plist, 'zoplayer', 'width=520,height=350,scrolling=no');
	out = '<a href="javascript:void(null)" onclick="ext_stop()">[interno]</a>';
	document.getElementById('ext_ctl').innerHTML = out;
}


// *****************************************************
// ENFOCAR (o reabrir) VENTANA LECTOR EXTERNO

function ext_focus() {
	if (zoplayer == null) 
		zoplayer = window.open('', 'zoplayer', 'width=520,height=350,scrolling=no');
	if (zoplayer == null || typeof(zoplayer.act_plist) == 'undefined') {
		zoplayer = window.open('/AUDIOS/extplayer.php?plist=wimpy_plist', 'zoplayer', 'width=520,height=350,scrolling=no');
		setTimeout('zoplayer.focus()', 1000);
		return;
	}
	zoplayer.focus();
}


// *****************************************************
// CERRAR LECTOR EXTERNO, LANZAR INTERNO

function ext_stop() {
	zoplayer = window.open('/AUDIOS/extplayer.php?action=stop', 'zoplayer', 'width=520,height=350,scrolling=no');
	zoplayer = null;
	document.getElementById('pvacio').style.display = 'none';
	document.getElementById('wimpyTarget').style.display = '';
	if (!wimpy_launched) {
		makeWimpyPlayer(wimpy_plist);
		wimpy_launched = 1;
	}
	out = '<a href="javascript:void(null)" onclick="ext_start()">[externo]</a>';
	document.getElementById('ext_ctl').innerHTML = out;
}


// *****************************************************
// LEER CANCION (en externo o interno)

var zoplayer = null;

function ext_play(odest,n) {
 	dest = odest.toLowerCase();
	wimpy_plist = '/MEDIA/'+dest.charAt(0)+'/'+dest+'/playlist.xml';

  if (zoplayer == null)
	 zoplayer = window.open('', 'zoplayer', 'width=520,height=350,scrolling=no');

  try { zoplayer.changePlist('') } catch(err) {
//	if (zoplayer == null || typeof(zoplayer.act_plist) == 'undefined') {
		zoplayer = window.open('/lector.php?plist='+odest+'&n='+n, 'zoplayer', 'width=520,height=350,scrolling=no');
    return;
  }

  if (zoplayer.shuffle == 1) {
    zoplayer.location = '/lector.php?plist='+odest+'&n='+n;
    return;
   }

	if (zoplayer.act_plist != wimpy_plist) {
		esp = zoplayer.changePlist(wimpy_plist);
		setTimeout('zoplayer.lectura('+n+')', 1000);
		return;
	}

	zoplayer.lectura(n);
}





// *****************************************************
// *****************************************************
// ACCIONES EN EL LISTADO DE CANCIONES
// *****************************************************
// *****************************************************

var plusdone =0;
var actadd = -1;
var addplus = " <span style=\"font-size:8pt; line-height:10px; color:#800040; font-family:arial; cursor:pointer\"><b>[+]</b></span>";


// *****************************************************
// MOSTRAR [+] JUNTO AL TITULO DE LA CANCION

function add_show(elm) {
	if (plusdone == 1 || actadd != -1) return;
	pos = elm.innerHTML.toLowerCase().indexOf('<span');
	if (pos != -1) return;
	elm.innerHTML += addplus;
	plusdone = 1;
}


// *****************************************************
// OCULTAR [+] AL CAMBIAR DE LINEA

function add_hide(elm) {
	pos = elm.innerHTML.toLowerCase().indexOf('<span');
	if (pos != -1)
		elm.innerHTML = elm.innerHTML.substr(0, pos);
	plusdone = 0;
}


// *****************************************************
// MOSTRAR POSIBLES ACCIONES CUANDO PINCHA

function add_click(elm,dest,n,dl,pl,sid) {
	if (actadd != -1) {
		tgt = document.getElementById('sact'+actadd);
		tgt.innerHTML = '';
		tgt.style.display = 'none';
		if (actadd == n) {
			actadd = -1;
			return;
		}
	}
	
	add_hide(elm);
	tgt = document.getElementById('sact'+n);
	out =  "<a class=sact href=\"javascript:ext_play("+n+")\">escucha</a> &middot; ";
	if (dl == 1)
		out += "<a class=sact href=\"javascript:song_dload('"+dest+"',"+n+",'"+sid+"')\">descarga</a> &middot; ";
	else
		out += "descarga &middot; ";
	if (pl == 1)
		out += "<a class=sact href=\"javascript:song_tolist('"+dest+"',"+n+",'"+sid+"')\">aņade a tu lista</a>";
	else
		out += "aņade a tu lista";
	tgt.innerHTML = out;
	tgt.style.display = '';
	actadd = n;
}


// *****************************************************
// DESCARGAR CANCION
function song_dload(dest,n,sid) {
	dlframe.location='/AUDIOS/audios_descarga.php?dest='+dest+'&num='+n+sid;
}


// *****************************************************
// AŅADIR A PLAYLIST
function song_tolist(dest,n,sid) {
	StartPop(350,250, '/AUDIOS/audios_addlist.php?dest='+dest+'&num='+n+sid);
}



// *****************************************************
// MOSTRAR TRANSCRIPCION (Letras/Acordes)
function goACO(dest,num) {
	url = "/CANCIONES/canciones_fullscreen.php?nohead=1&dest="+dest+"&num="+num;
	framewin.location.replace(url);
}

var playerTXT = '';
var playerORIG = '';
var PTO = null;
function showSong(tit, w) {
  if (tit == playerORIG) return;
  if (zoplayer == null) zoplayer = w;
  if (PTO != null) clearInterval(PTO);
  playerORIG = tit;
  if (tit.length < 28) {
     document.getElementById('pdisplay').innerHTML = tit;
     return;
  }
  
  playerTXT = tit+' *** ';
  document.getElementById('pdisplay').innerHTML = playerTXT.substr(0,27);
  PTO = setInterval('playerScroll()', 500);
}

function playerScroll() {
  playerTXT = playerTXT.substr(1) + playerTXT.charAt(0);
  document.getElementById('pdisplay').innerHTML = playerTXT.substr(0,27);
}

function playerACT(a) {
  if (zoplayer == null) return;
  zoplayer.doACT(a);
}
        