var programasDelDia = null;

function showDescription(event, programa){
	programa.style.color = '#155585';
	programa.style.cursor = 'pointer';
	programa.style.cursor = 'hand';
	var coordinates = getCoordinates(event);
	if(programasDelDia == null){
		jQuery.ajax({
		   	type: "POST",
		   	url: "/wp-content/plugins/programacion/programacion.php",
		  	data: "dia="+programa.parentNode.id+"&hora="+programa.id,
		  	dataType: "xml",
		  	success: function(programacion){
		   		show(coordinates, programa, programacion);
		  	}
	 	});
	 }
	 else {
	 	show(coordinates, programa);
	 }
}
function show(coordinates, programa, programacion){
	var descriptioner = document.getElementById("program_description");
	if(descriptioner.style.display == "none"){
		var descripcion = "";
		descriptioner.style.display = "block";
		descriptioner.style.left = coordinates.x + "px";
		descriptioner.style.top = coordinates.y + "px";
		if(programasDelDia == null){
			programasDelDia = programacion;
		}
		var programas = programasDelDia.getElementsByTagName('programa');
		for(i = 0; i < programas.length; i++){
			if(programas.item(i).getAttribute('hora') == programa.id){
				var hora = (programas.item(i).getAttribute('hora').substring(0,1) == '0')? programas.item(i).getAttribute('hora').substring(1) : programas.item(i).getAttribute('hora');
				descripcion += '<p class="hora">' + hora + '</p>';
				descripcion += '<h4>' + programas.item(i).getAttribute('nombre') + '</h4>';
				if(programas.item(i).getElementsByTagName('imagen').length == 1){
					descripcion += '<img class="image" src="http://www.radiouas.org/wp-content/logos/' + programas.item(i).getElementsByTagName('imagen').item(0).firstChild.nodeValue + '"/>';
				}
				if(programas.item(i).getElementsByTagName('descripcion').length == 1){
					descripcion += '<p class="about">' + programas.item(i).getElementsByTagName('descripcion').item(0).firstChild.nodeValue + '</p>';
				}
				if(programas.item(i).getElementsByTagName('conductor').length == 1){
					descripcion += '<p class="conductor">';
					if(programas.item(i).getElementsByTagName('conductor').item(0).getAttribute('type') == null){
						descripcion += 'Con ';
					}
					descripcion += programas.item(i).getElementsByTagName('conductor').item(0).firstChild.nodeValue + '</p>';
				}
			}
		}
		descriptioner.innerHTML = descripcion;
	}
}
function hideDescription(programa){
	programa.style.fontWeight = 'normal';
	programa.style.color = '#7B7B7B';
	document.getElementById("program_description").style.display = "none";
}
function getCoordinates(event){
	if(navigator.appName.indexOf('Microsoft') == 0){
		return {x:(event.clientX+document.documentElement.scrollLeft),y:(event.clientY+document.documentElement.scrollTop)};
	} else {
		return {x:(event.clientX+window.scrollX),y:(event.clientY+window.scrollY)};
	}
}