var visorVisible=false;
var videoactivo=false;
var correcto=true;
var ready=true;
var numFoto=0;
var i=0;
var numero=0;
var vx_actual=0;
var vy_actual=0;


function buffer() {
	  document.getElementById('progreso').value="Almacenando en buffer... "+document.getElementById("MediaPlayer").Network.bufferingProgress+"% completado";
	  timer = setTimeout('buffer()',1000);
}
	
function Play(){
	document.getElementById('progreso').value="Reproduciendo";
	if (correcto) document.getElementById("MediaPlayer").controls.play();
}
	
function Stop() {
	  document.getElementById('progreso').value="Detenido";
	  if (correcto) document.getElementById("MediaPlayer").controls.stop();
}
	
function Pause() {
	  document.getElementById('progreso').value="En pausa";
	  if (correcto) document.getElementById("MediaPlayer").controls.pause();
}
	
function fullScreen() {
	if (correcto) {
	  	alert("Pulsa ESC para salir de pantalla completa");
	  	document.getElementById("MediaPlayer").fullScreen=true;
	}
}

function volumenUp() {
	 if (correcto) {
	    volumen=document.getElementById("MediaPlayer").settings.volume;
	    volumen=volumen+10;
	    document.getElementById("MediaPlayer").settings.volume=volumen;
	 }
}
	
function volumenDown() {
	  if (correcto) {
	    volumen=document.getElementById("MediaPlayer").settings.volume;
	    volumen=volumen-10;
	    document.getElementById("MediaPlayer").settings.volume=volumen;
	  }
	}

function setReady() 
{
	ready=false;
}

function testear() {
	if (ready) correcto = (parseInt(document.getElementById("MediaPlayer").versionInfo) >= 9);
}

function recolocarVisor(vx,vy)
{	
	vx_numerico=parseInt(vx);
	vy_numerico=parseInt(vy);
	
	posx=vx_numerico-1.5;
	posy=vy_numerico-1.5;

	ventana_ancho=document.body.clientWidth;
	ventana_alto=document.body.clientHeight;



	if (visorVisible==true)
	{
		if ((ventana_ancho<920) || (ventana_alto<690)) 
		{
			if (ventana_ancho>920)
			{
				posicion_x = Math.round(((document.body.clientWidth/2)-460)+posx);
			}	
			else
			{
				posicion_x = Math.round(posx);
			}
		
			if (ventana_alto>690)
			{
				posicion_y = Math.round(((document.body.clientHeight/2)-345)+posy+9);
			}
			else{ 
				posicion_y = Math.round(posy);}
				
			
			document.getElementById('visor360').style.left=posicion_x+"px";
			document.getElementById('visor360').style.top=posicion_y+"px";
		}
		else 
		{
			posicion_x = Math.round(((document.body.clientWidth/2)-460)+posx);
			posicion_y = Math.round(((document.body.clientHeight/2)-345)+posy+15);
			document.getElementById('visor360').style.left=posicion_x+"px";
			document.getElementById('visor360').style.top=posicion_y+"px";
		}
	
	}
	else ocultarVisor();

}

function recolocarvideo(vx,vy)
{

	vx_numerico=parseInt(vx);
	vy_numerico=parseInt(vy);
	posx=vx_numerico-1.5;
	posy=vy_numerico-1.5;

	ventana_ancho=document.body.clientWidth;
	ventana_alto=document.body.clientHeight;

	document.getElementById('video').style.visibility="visible";
   	
   if (videoactivo==true)
   {
		if((ventana_ancho<920)||(ventana_alto<690))
		{

			if (ventana_ancho>920)
			{
				posicion_x = Math.round(((document.body.clientWidth/2)-460)+posx);
			}
			else
			{
				posicion_x = Math.round(posx);
			}
			if (ventana_alto>690)
			{
				
				posicion_y = Math.round(((document.body.clientHeight/2)-345)+posy+90);
			}
			else
			{
				posicion_y = Math.round(posy+90);
			}
			document.getElementById('video').style.left=posicion_x+"px";
			document.getElementById('video').style.top=posicion_y+"px";
		}
		
		else
		{
			posicion_x = Math.round(((document.body.clientWidth/2)-460)+posx);
			posicion_y = Math.round(((document.body.clientHeight/2)-345)+posy+90+15);
			document.getElementById('video').style.left=posicion_x+"px";
			document.getElementById('video').style.top=posicion_y+"px";
	
		}
	  
	}
	document.getElementById('video').style.visibility="visible";	
}



function recolocar(vx,vy) {
recolocarVisor(vx,vy); 
recolocarvideo(vx,vy);
}

function mostrarImagen(imagen) {
	document.getElementById("ptviewer").newPanoFromList(imagen);
}


function ocultarhs() {
	document.getElementById("ptviewer.ToggleHSImage(0)");
}

function mostrarvideo(v) {
  if (!correcto) 
	alert ('Debe tener instalado Microsoft Windows Media Player 9 para poder ver correctamente el video');
  else {	
    document.getElementById("ptviewer").stopAutoPan();
    document.getElementById('video').style.visibility="visible";
    //document.getElementById('video').style.left=Math.round((document.body.clientWidth/2)-15);
    //document.getElementById('video').style.top=Math.round((document.body.clientHeight/2)-210);
    switch (v) {
    	case 1: document.getElementById("MediaPlayer").URL='mms://streaming.alisys.net/ree_cecoel1';
	        break;
    	case 2: document.getElementById("MediaPlayer").URL='mms://streaming.alisys.net/ree_cecoel2';
	        break;
		case 3: document.getElementById("MediaPlayer").URL='mms://streaming.alisys.net/ree_cecoel3';
                break;
	}    
    Play();	
    videoactivo=true;
  }
}

function ocultarVisor()
{
	document.getElementById('visor360').style.left=-500+"px";
	document.getElementById('visor360').style.top=-500+"px";
	visorVisible=false;
}

function ocultarVideo(){
  if (correcto) {
    Stop();
    document.getElementById('video').style.visibility="visible";
    document.getElementById('visor360').style.visibility="visible";
    document.getElementById('video').style.left=-1000+"px";
    document.getElementById('video').style.top=-1000+"px";
    videoactivo=false;
  }
}

function todo(p1,p2) {
	if(p1=="ocultar_visor"){
		ocultarVisor();
		}

	if(p1=="recolocar_visor"){
		visorVisible=true;
		var miArray = p2.split(",");
		vx_actual=miArray[1];
		vy_actual=miArray[2];
		recolocarVisor(miArray[1],miArray[2]); 
	}

	if(p1=="mostrar_imagen") {
		visorVisible=true;
		var miArray = p2.split(",");	
		vx_actual=miArray[1];	
		vy_actual=miArray[2];
	    recolocarVisor(vx_actual,vy_actual); 
		mostrarImagen(miArray[0]);		
	}

	if(p1=="ocultar_video") {
		ocultarVideo();
	}

	if(p1=="mostrar_video")	{
		videoactivo=true;
		var miArray = p2.split(",");
		vx_actual=miArray[1];
		vy_actual=miArray[2];
		recolocarvideo(miArray[1],miArray[2]); 
	    mivideo = parseInt(miArray[0]);	
		mostrarvideo(mivideo);		
	}

	if(p1=="recolocar_video") {
		videoactivo=true;
		var miArray = p2.split(",");
		vx_actual=miArray[1];
		vy_actual=miArray[2];
		recolocarvideo(miArray[1],miArray[2]);
	}



	//**************FUNCIONES MOVIMIENTO FOTOGRAFIA*****************

	if (p1=='dcha')	{
		document.getElementById("ptviewer").startAutoPan(0.5,0,1);
	}

	if (p1=='stop')	{
		document.getElementById("ptviewer").stopAutoPan();
	}

	if (p1=='zoomin') {
		pan=document.getElementById("ptviewer").pan();
		tilt=document.getElementById("ptviewer").tilt();
		fov=document.getElementById("ptviewer").fov();	
		document.getElementById("ptviewer").moveTo(pan,tilt,fov-15,10);
		
	}

	if (p1=='zoomout') {
		pan=document.getElementById("ptviewer").pan();
		tilt=document.getElementById("ptviewer").tilt();
		fov=document.getElementById("ptviewer").fov();	
		document.getElementById("ptviewer").moveTo(pan,tilt,fov+15,10);
	}

	//*****************FUNCIONES DE VIDEO****************


	if(p1=="buffer")
	{
		  document.getElementById('progreso').value="Almacenando en buffer... "+document.getElementById("MediaPlayer").Network.bufferingProgress+"% completado";
		  timer = setTimeout('buffer()',1000);
	}
		
	if(p1=="play")
	{
		document.getElementById('progreso').value="Reproduciendo";
		if (correcto) document.getElementById('MediaPlayer').controls.play();
	}
		
	if(p1=="stop")
	{
		document.getElementById('progreso').value="Detenido";
		if (correcto) document.getElementById('MediaPlayer').controls.stop();
	}
		
	if (p1=="pause")
	{
		document.getElementById('progreso').value="En pausa";
		if (correcto) document.getElementById('MediaPlayer').controls.pause();
	}
		
	if(p1=="fullScreen")
	{
		//alert("!!!");
		  if (correcto)
		  {
		  alert("Pulsa ESC para salir de pantalla completa");
	  	  document.getElementById('MediaPlayer').fullScreen=true;
		}
	}
		
	if(p1=="volumenUp")
	{
		if (correcto)
		{
		    volumen=document.getElementById('MediaPlayer').settings.volume;
		    volumen=volumen+10;
		    document.getElementById('MediaPlayer').settings.volume=volumen;
		}
	}
		
	if(p1=="volumenDown")
	{
		if (correcto) 
		{
		   volumen=document.getElementById("MediaPlayer").settings.volume;
		   volumen=volumen-10;
		   document.getElementById("MediaPlayer").settings.volume=volumen;
		}
	}
}
