﻿/*$(document).ready(function(){
	$("#pruebaAppendRemove").click(function(){
		IpTv_EndVideo();
	});											
});*/

/****************************************************************
/ Nombre: IpTv_LoadTvProgramming
/ Implentacion: 
/ Revision: 301106
/ Descripcion: Carga la lista de programación
'***************************************************************/
function IpTv_LoadTvProgramming(number){
	
	var params = ""
	url ="includes/tvIp/onAir_tvprogramming_ajax.asp";
	//Recogemos el valor orden del ultimo video seleccionado
	var orderList = document.getElementById("lastOrderListValue").value
	params += "orderList=" + orderList;
	
	if(number != 0){
		params += "&number=" + number;
	}
	
	//Si existen canales
	var category = $("#category").attr("value");
	if(category > 0) {
		params += "&category=" + category
	}
    
	http.open("POST", url , true);
	
	http.onreadystatechange = function() {
	    if (http.readyState==4)
	    {
            if(http.status==200)
            {
                $("#tvprogramming #lastOrderListEdit").remove();
                $("#tvprogramming").append(http.responseText);
                document.getElementById("lastOrderListValue").value = $("#lastOrderListEdit").attr("value");

                /*$('#tvprogramming LI').click(function(){
                    var videoName = $(this).attr("title");
                    var length    = $(this).attr("rel");
                    
                    ShowVideo(videoName, length);
                });*/
                
                //Llamar a pintar video
                if(number==0)
                {
	                //Sacar el primer LI y extraer el nombre del video
	                var videoName = $("#tvprogramming LI:first-child").attr("title");
	                var length    = $("#tvprogramming LI:first-child").attr("rel");
	                var title     = $("#tvprogramming LI:first-child").attr("name");
	                var endDate   = $("#tvprogramming LI:first-child").attr("class");
	
	                ShowVideo(videoName, length, title, endDate);
                }
            }
            else 
            {
                if(http.status==404)
                {
	                $("#tvprogramming").append("La direccion no existe");
                }
                else
                {
	                $("#tvprogramming").append("Error: " + http.status);
                }
            }
	    }
	}
  	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send(params);
	
	return;
}


function ShowVideo(videoName, length, title, endDate)
{	
    var flash = "";
    var seek = new Date();
    var endDateType = new Date(endDate);
    
    endDateType.setDate(seek.getDate());
    endDateType.setMonth(seek.getMonth());
    endDateType.setFullYear(seek.getFullYear());
    
    seek = seek.getTime();
    
    if (endDateType.getTime() > seek)
    {
        seek = endDateType.getTime() - seek;
        
        if (seek < 0 || length == 0)
        {
            seek = 0;
        }
        else
        {
            seek = Math.round((length - seek) / 1000);
        }
    }
    else
    {
        seek = 0;
    }
    
    if (videoName != "")
        flashVars = "pagina=&lang=100&settings=38&videoName=" + videoName + "&initPlay=true&bitrate=0&tvIp=true&seek=" + seek;
    else
        flashVars = "pagina=&lang=100&settings=38&initPlay=true&bitrate=0&live=true&length=" + length + "&tvIp=true&seek=" + seek;
    
	
	if(document.getElementById("OnAir") == null){
	
    width  = "100%";
    height = "100%";
	//width  = "549";
    //height = "445";
    wmode  = "transparent";
	quality = "high";


   /* flash += "<object width=\"" + width + "\" height=\"" + height + "\" id=\"OnAir\">";
	    flash += "<param name=\"movie\" value=\"http://www.actualizerweb.net/tv/v1/player.swf\"></param>";
	    flash += "<param name=\"quality\" value=\"best\"></param>";
	    flash += "<param name=\"allowFullScreen\" value=\"true\"></param>";
	    flash += "<param name=\"allowscriptaccess\" value=\"always\"></param>";
	    flash += "<param name=\"wmode\" value=\"" + wmode + "\" />";
		flash += "<param name=\"quality\" value=\"" + quality + "\" />";
	    flash += "<param name=\"flashvars\" value=\"" + flashVars + "\" />";*/
	    flash += "<embed src=\"http://www.actualizerweb.net/tv/v1/playerTV.swf\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"" + width + "\" height=\"" + height + "\" align=\"middle\" flashvars=\"" + flashVars + "\" id=\"OnAir\" quality=\"" + quality + "\" />";
    //flash += "</object>";

    	$("#player").html(flash);
	}else{
		
		 var player = document.getElementById("OnAir");
		 alert(player)
		$("#OnAir").attr("flashvars", $("#OnAir").attr("flashvars").replace("jacks_500","Video-inauguracion-casino--puertas-abiertas-QUARTV_500"));
		
	}
    
	
    if (videoName != "")
        $("#playerTitle").html(title);
    else
        $("#playerTitle").html("LIVE");
}


/****************************************************************
/ Nombre: PrintVideo
/ Implentacion: 
/ Revision: 301106
/ Descripcion: PrintVideo
'***************************************************************/
/*function PrintVideo(videoName, initPlay){
		ShowVideo(videoName);
}*/

/****************************************************************
/ Nombre: IpTv_EndVideo
/ Implentacion: 
/ Revision: 301106
/ Descripcion: Al finalizar el video
'***************************************************************/
function IpTv_EndVideo(){

	//Eliminar el first //Remove
	$("#tvprogramming LI:first-child").remove();
	IpTv_LoadTvProgramming(1);
	
	//Volver a captar el first y pillar el title, pasarselo a printvideo
	var videoName = $("#tvprogramming LI:first-child").attr("title");
	var length    = $("#tvprogramming LI:first-child").attr("rel");
	var title     = $("#tvprogramming LI:first-child").attr("name");
	var endDate   = $("#tvprogramming LI:first-child").attr("class");
	
	//ShowVideo(videoName, length, title, endDate);
	
}



function PlayVideo(){
 //   Reproduce el vídeo actualmente cargado/en cola.
}

function PauseVideo(){
//    Pausa el vídeo que actualmente en reproducción.
}


function StopVideo()
{
//    Detiene el vídeo actual. También cierra el objeto NetStream y cancela la carga del vídeo. Una vez que se haya ejecutado stopVideo(), un vídeo no se podrá reanudar //sin volver a cargar el reproductor o cargar un nuevo vídeo (sólo reproductores sin bordes). Al ejecutar stopVideo(), en primer lugar el reproductor emitirá un evento de finalización (0), seguido de un evento no iniciado (-1).
}

function ClearVideo()
{
	//Borra la visualización del vídeo. Resulta útil si deseas borrar el rastro de un vídeo después de ejecutar stopVideo().
}

function GetVideoBytesLoaded()
{    
	//Devuelve el número de bytes cargados para el vídeo actual.
}

function GetVideoBytesTotal(){
  // Devuelve el tamaño en bytes del vídeo en reproducción/cargado actualmente.
}

function GetVideoStartBytes(){
    //Devuelve el número de bytes desde el que comenzó la carga del archivo de vídeo. Caso de ejemplo: el usuario busca un punto que aún no se ha cargado, y el reproductor realiza una nueva solicitud de reproducción de un segmento del vídeo que aún no se ha cargado.
}

function Mute(){
   // Silencia el reproductor.
}

function UnMute(){
  //  Devuelve el sonido al reproductor.
}

function IsMuted(){
  //  Devuelve el valor true, si el productor está silenciado; false, si no lo está.
}

function SetVolume(volume){
 //   Establece el volumen. Acepta un número entero comprendido entre 0 y 100.
}

function GetVolume(volume){
//    Devuelve el volumen actual del reproductor, un número entero comprendido entre 0 y 100. Ten en cuenta que getVolume() devolverá el volumen aunque el reproductor esté silenciado.
}

function SeekTo(seconds, allowSeekAhead){
//    Busca el tiempo especificado del vídeo en segundos. allowSeekAhead determina si el reproductor va a realizar una nueva solicitud al servidor si seconds trasciende los datos de vídeo actualmente cargados. Ten en cuenta que seekTo() intentará buscar el fotograma clave más cercano a los segundos (seconds) especificados. Esto significa que a veces el comienzo de la reproducción puede buscar realmente justo antes o justo después del tiempo solicitado, normalmente no más de ~2 segundos.
}

function GetPlayerState(){
//    Devuelve el estado del reproductor. Los valores posibles son no iniciado (-1), finalizado (0), en reproducción (1), pausado (2), almacenamiento en búfer (3), en cola de vídeos (5). 
}

function GetCurrentTime()
{
   // Devuelve el tiempo actual en segundos del vídeo actual.
}

function GetDuration()
{
//    Devuelve la duración en segundos del vídeo actualmente en reproducción. Ten en cuenta que getDuration() devolverá 0 hasta que se hayan cargado los metadatos del vídeo, lo que normalmente se produce justo después de que comience la reproducción del vídeo.
}

//addEventListener(event, listener)
//{
 //   Añade una función de escucha para el evento especificado.
//}


function GetVideoUrl()
{
   // Devuelve la URL YouTube.com para el vídeo en reproducción o cargado actualmente.
}

function GetVideoEmbedCode()
{
    //Devuelve el código insertado para el vídeo en reproducción o cargado actualmente.
}





function Parrilla(){

	/*******************************************
	Contoralador de la parrilla
	Etebar
	*********************************************/
	$("#enlaceParrilla A").mouseover(function(){
		var titulo = $(this).attr("title");
		var contTop = $(this).attr("id");
		var contLeft = $(this).attr("rev");
		var descripcion = $(this).attr("rel");
		$("#parrillaTitle").html(titulo);
		$("#parrillaDesc").html(descripcion);
		var top = contTop * 28;
		var left = 0;
		if(contLeft <= 15){
			left = 230 
		}else if(contLeft <= 31){
				left = 530
				}else{
				left = 	780
				}
		$("#parrillaInfo").css("top", top + "px");
		$("#parrillaInfo").css("left", left + "px");
		$("#parrillaInfo").css("display","block");
		
	});
	
	$("#enlaceParrilla A").mouseout(function(){
		$("#parrillaInfo").css("display","none");
		
	});
	
	
	$("#abrirParrilla").click(function(){
		$("#parrillaTv").css("display","block");
		$("#player").css("display","none");
	});
		
	$(".cerrarParrilla").click(function(){
		$("#parrillaTv").css("display","none");
		$("#player").css("display","block");
	});
	

	$("#showTomorrow").click(function(){
		showProgrammingTomorrow();							  

	});
	
}




function showProgrammingTomorrow(){
	var today = new Date();
	var aux = new Date(today.getTime() + 86400000); 
	day = aux.getDate();
	month = aux.getMonth();
	year = aux.getFullYear();
	
	var params = "";
	params += "day=" + day + "&month=" + month + "&year=" + year;  
	$.ajax({
		type: 'POST',
		data: params,
		url: './includes/tvIp/parrilla_tomorrow.asp',
		success: function(data){
			
			
			$("#parrillaTv").html(data); 
			$(".cerrarParrilla").click(function(){
									
				$("#parrillaTv").css("display","none");
				$("#player").css("display","block");
			});
			$("#showToday").css("background-color","#CD135C")
			$("#showToday").css("color","#FFF");
			$("#showTomorrow").css("background-color","#FFF")
			$("#showTomorrow").css("color","#000");
			$("#showToday").click(function(){
				showProgrammingToday();
			});
			$("#enlaceParrilla A").mouseover(function(){
				var titulo = $(this).attr("title");
				var contTop = $(this).attr("id");
				var contLeft = $(this).attr("rev");
				var descripcion = $(this).attr("rel");
				$("#parrillaTitle").html(titulo);
				$("#parrillaDesc").html(descripcion);
				var top = contTop * 28;
				var left = 0;
				if(contLeft <= 15){
					left = 230 
				}else if(contLeft <= 31){
						left = 530
						}else{
						left = 	780
						}
				$("#parrillaInfo").css("top", top + "px");
				$("#parrillaInfo").css("left", left + "px");
				$("#parrillaInfo").css("display","block");
				
			});
			$("#enlaceParrilla A").mouseout(function(){
				$("#parrillaInfo").css("display","none");
				
			});
			
		}//sucess
	});//ajax		
}




function showProgrammingToday(){
	
	$.ajax({
		type: 'POST',
		url: './includes/tvIp/parrilla.asp',
		success: function(data){
			
			
			$("#parrillaTv").html(data); 
			$(".cerrarParrilla").click(function(){
				$("#parrillaTv").css("display","none");
				$("#player").css("display","block");
			});
			$("#showToday").css("background-color","#FFF");
			$("#showToday").css("color","#000");
			$("#showTomorrow").css("background-color","#CD135C");
			$("#showTomorrow").css("color","#FFF");
			
			$("#showTomorrow").click(function(){
				showProgrammingTomorrow();
			});
			
			$("#enlaceParrilla A").mouseover(function(){
				var titulo = $(this).attr("title");
				var contTop = $(this).attr("id");
				var contLeft = $(this).attr("rev");
				var descripcion = $(this).attr("rel");
				$("#parrillaTitle").html(titulo);
				$("#parrillaDesc").html(descripcion);
				var top = contTop * 28;
				var left = 0;
				if(contLeft <= 15){
					left = 230 
				}else if(contLeft <= 31){
						left = 530
						}else{
						left = 	780
						}
				$("#parrillaInfo").css("top", top + "px");
				$("#parrillaInfo").css("left", left + "px");
				$("#parrillaInfo").css("display","block");
				
			});
			$("#enlaceParrilla A").mouseout(function(){
				$("#parrillaInfo").css("display","none");
				
			});
			
		}//sucess
	});//ajax
}


//FIN DE PARRILLA
/*******************************************************/
	
