﻿var inicio = limpiaTag(CapturaParametro('segundo'));
var SEEK=true;
var vStop=false;

if (inicio=="no existe el parametro"){
	inicio = 0;
}
var titulo = limpiaTag(CapturaParametro('titulo'))+"";
if (titulo=="no existe el parametro"){
	titulo = '';
} else {
	var objElemntoTitulo
	objElemntoTitulo=document.getElementById('flash_ondemande_texto')
	//alert(objElemntoTitulo)
	objElemntoTitulo.innerHTML=objElemntoTitulo.innerHTML + "<br />"+ unescape(titulo);
	 //objElemntoTitulo=document.getElementById('flash_ondemande_texto').innerHTML= document.getElementById('flash_ondemande_texto').innerHTML + "<br />"+ unescape(titulo);
}

var duracion = limpiaTag(CapturaParametro('duracion'));
if (duracion=="no existe el parametro"){
	duracion = 0;
}
var final= parseFloat(inicio)+parseFloat(duracion);

function playerReady(thePlayer) {
	
		player = document.getElementById(thePlayer.id);
if (duracion>0){
	//muestraVideos();
	addListeners();
}
}

function addListeners() {
	if (player) { 
		player.addModelListener("STATE", "stateListener");
		player.addModelListener("TIME", "stateTIMEListener");
		//alert(parseInt(inicio)+parseInt(duracion))
		} else {
		setTimeout("addListeners()",100);
	}
}

function stateTIMEListener(obj){
	//alert(obj.position+":"+inicio )
	if (obj.position>=(parseInt(inicio)+parseInt(duracion))){
		player.sendEvent('SEEK',inicio);
		player.sendEvent('STOP');
		//player.sendEvent('SEEK',inicio);
		//player.sendEvent('SEEK',0);
		vStop=true;
	}

}


function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 
	
	//var tmp2 = document.getElementById("CapaNum0_Objeto_2");
//	tmp2.innerHTML=tmp2.innerHTML +"<br>" +previousState+":"+currentState +"<br>" ;
	
	if (vStop==true && currentState == "PLAYING"){
		player.sendEvent('SEEK',inicio);
		vStop=false;
	}
//	if((previousState == "BUFFERING")&&(currentState == "PLAYING") && SEEK==true){
//				//alert(inicio)
//				//player.sendEvent('SEEK',inicio);
//				//alert(obj.position)
//				//SEEK=false;
//		}
	
	/*if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) {
		//Pasamos al siguiente video.
		NumvideoPlay=parseInt(NumvideoPlay)+1
		
		if (NumvideoPlay >= plst.length){
			NumvideoPlay=0
		}
		cargavideo()
		//Tenemos que marcar en el grid el video que vamos a reproducir.
		objVideoEnVisor=document.getElementById("VideoEnVisor")
		objVidelENVisorSiguiente=objVideoEnVisor.parentNode.nextSibling
		objVideoEnVisor.parentNode.innerHTML=objVideoEnVisor.firstChild.innerHTML
		objVidelENVisorSiguiente.innerHTML="<a id='VideoEnVisor' name='VideoEnVisor'><b>" + objVidelENVisorSiguiente.innerHTML +"</b></a>"
		tmp.innerHTML=plst[NumvideoPlay].title
	}*/
}

//function sendEvent(swf, typ, prm) {
//	thisMovie(swf).sendEvent(typ, prm); 
//}
//
//function getUpdate(typ, pr1, pr2, swf) {
//if(typ == 'state') {
//	//alert(typ+ '='+pr1+swf);
//}
//
//
//if(typ == 'time' && pr1>=final && duracion>0) { 
//		sendEvent(swf,'stop');
//}
//
//if(typ == 'time' && pr1<inicio) { 
//		player.sendEvent('SEEK', inicio);
//		//sendEvent(swf,'scrub',inicio);
//}
//}
//
//
//function thisMovie(swf) {
//	if (navigator.appName.indexOf("Microsoft") != -1) {
//		return window[swf];
//	} else {
//		return document[swf];
//	}
//}
// 
function limpiaTag(tiempo) {
	   if (tiempo!=''){
		 tiempo = tiempo.replace("<","");
		 tiempo = tiempo.replace(">","");
		 tiempo = tiempo.replace("iframe","");
		 tiempo = tiempo.replace("<script","");
		//alert(tiempo);
	   }
       return tiempo;
   }
   
   
   for (var i=0; i < rtmpUrl.length; i++) {
				var rtmptUrl = rtmpUrl[i].replace(/^rtmp:\/\//, "rtmpt://");
				rtmpUrl[i] = rtmptUrl;
			}
			$finalUrl = rtmpUrl[0];
			 if (DetectFlashVer(9, 0, 115)) {
					//alert(streamName)
			 		var $finalUrl = rtmpUrl[0];
					var flashvars = {
						streamer:$finalUrl,
						file:streamName, 
						autostart:"true",
						repeat:"false",
						start:inicio,
						skin:"frontcolor=ffffff&lightcolor=cc0000&skin=http://www.cervantestv.es/visor/cervantes.swf&backcolor=314252&controlbar=over&stretching=fill",
						type:"video"
					}
					var params = {
						allowfullscreen:"true", 
						wmode:"transparent",
						allowscriptaccess:"always",
						width: "640",
						height: "380",
						displayheight:"380",
						autostart:"true",
						wmode:"transparent",
						repeat:"false"						
					}
					var attributes = {
						id:"Prueba",  
						name:"Prueba"
					}

					swfobject.embedSWF("http://www.cervantestv.es/visor/mediaplayer4_2.swf", "player1", "540", "304", "9.0.115", false, flashvars, params, attributes);
			}else{
				//document.write("La versión está mal");
			   	var StrCadena ="Versión instalada actualmente de Flash:"
				var strPlayer="player1"
			     var texto="Necesita una nueva versión de Adobe Flash Player para visualizar este contenido (versión 9.0.115 o posterior requerida).<br/><br/>";
                     texto = texto + "<a href=http://www.macromedia.com/go/getflashplayer>Consiga la última versión del visor de Flash</a><br/><br/>" ;
                     texto = texto + " <scri" + "pt type=text/javascript>";
                     texto = texto + "  document.write(StrCadena+ GetSwfVer());";
                     texto = texto + "</"+"scr" +"ipt>";
					 document.getElementById(strPlayer).innerHTML=texto;
            }
			//]]>