<!-- Begin
// -------------------------------------------------------------------
// 	Desarrollada por: Diego Piñon Conde
// 	email: pinondie@ufasta.edu.ar
// -------------------------------------------------------------------
// 	Esta libreria permite mostrar una imagen en un pop-up que se ajuste
// 	al tamaño de la misma, pasando como unico parametro requerido, el
//	nombre de la imagen (path completo, soporta espacios en los nombres).
//
//	La imagen se muestra en un documento creado on-the-fly, por lo que
//
//	Opcionalmente, se pueden utilizar:
//		2º parametro: Titulo de la ventana
//		3º parametro: Texto alternativo de la imagen
//		4º y 5º parametro: Ubicación de la ventana x/y (default Centrada)
// -------------------------------------------------------------------

// Begin Common
var NS = (document.layers) ? 1 : 0;  
// End Commnon

function ViewImage(ifile){
// Funcion principal
  foto1= new Image();
  foto1.src=(ifile);
  var args = ViewImage.arguments
  //tomar los argumentos opcionales
  ititle = (args.length >= 2)? args[1]:'';
  ialt = (args.length >= 3)? args[2]:'';
  iposx = (args.length >= 4)? args[3]:'';
  iposy = (args.length >= 5)? args[4]:'';
  Check(ifile);
}

function View360(ifile,iwidth,iheight){
  //tomar los argumentos opcionales
  var args = View360.arguments
  ititle = (args.length >= 4)? args[3]:'';  
  iposx = (args.length >= 5)? args[4]:'';
  iposy = (args.length >= 6)? args[5]:'';
  show(ifile,iwidth,iheight);  
}

function Check(img){
// Chequea que se termine de transferir la imagen
// luego llama a viewFoto para abrir el pop-up
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewFoto(img);
  }
  else{
    funcion="Check('"+img+"')";
    intervalo=setTimeout(funcion,20);
  }
}

function centerWin(width,height){
// Calcula la posición que debe ocupar el pop-up 
// para quedar centrado

	if(NS)
	{// Navigator coordinates
		screenY = screen.height;
		screenX = screen.width;
	}
	else
	{ 
		screenY = document.body.offsetHeight
		screenX = window.screen.availWidth
	}

	leftvar = (screenX - width) / 2
	rightvar = (screenY - height) / 2
		
	if(NS)
	{// Netscape
		iposx = (leftvar - pageXOffset)
		iposy = (rightvar - pageYOffset)
	}
	else
	{ 
		iposx = leftvar
		iposy = rightvar
	}
	
	//verificar que la esquina sup-izq no este fuera de la ventana
	iposx = (iposx < 0)?0:iposx
	iposy = (iposy < 0)?0:iposy
}

function viewFoto(ifile){
// Abre el pop-up segun las especificaciones del tamaño de la img
// y la posición elegida

  //toma el ancho y alto de la imagen para crear la ventana
  ix=foto1.width;
  iy=foto1.height;

  //si no se especifico posición calcular centrado
  if (iposx == '')
  	centerWin(ix,iy);

  win = window.open("","imageviewer","width="+ix+",height="+iy+",menubar=no,toolbar=no,left="+iposx+",top="+iposy);
  
  //verificar que la ventana que se abrio cumpla los requisitos
  if (NS) {
	sWidth = win.innerWidth;
	sHeight = win.innerHeight;
	} else {
	sWidth = win.document.body.clientWidth;
	sHeight = win.document.body.clientHeight;
	}
  if(sWidth!=ix || sHeight!=iy) {
	win.close();
	setTimeout("ViewImage('"+ifile+"',"+ix+","+iy+",'"+ititle+"')", 250);
	return;
	}
	

  win.document.open();
  win.document.write("<html> ");
  win.document.write(" <SCRIPT language=javascript> function click() { if (event.button==2) {alert('Propiedad Infomarcial - Prohibida su reproducción.') }} document.onmousedown=click </SCRIPT>");
  win.document.write("<head><title>"+ititle+"</title>");
  win.document.write("</head>");
  win.document.write("<body bottommargin='0' topmargin='0' leftmargin='0' rightmargin='0'>");
  win.document.write("<img src="+escape(ifile)+" class=drag GALLERYIMG=no  alt=\""+ialt+"\"></body></html>");
  win.document.close();


}

function show(ifile,iwidth,iheight){
// Abre el pop-up segun las especificaciones del tamaño de la img
// y la posición elegida

  //si no se especifico posición calcular centrado
  if (iposx == '')
  	centerWin(iwidth,iheight);

  win = window.open("","360viewer","width="+iwidth+",height="+iheight+",menubar=no,toolbar=no,left="+iposx+",top="+iposy);

  //verificar que la ventana que se abrio cumpla los requisitos
  if (NS) {
	sWidth = win.innerWidth;
	sHeight = win.innerHeight;
	} else {
	sWidth = win.document.body.clientWidth;
	sHeight = win.document.body.clientHeight;
	}
  if(sWidth!=iwidth || sHeight!=iheight) {
	win.close();
	setTimeout("View360('"+ifile+"',"+iwidth+","+iheight+",'"+ititle+"')", 250);
	return;
	}

  win.document.open();
  win.document.write("<html>\n<head>\n<title>"+ititle+"</title>\n");
  win.document.write("</head>\n<body topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0>\n");

  win.document.write("<applet name=Template1 code=uPixScreen.class archive=uPixScreen.jar width="+iwidth+" height="+iheight+"\n>")  
  win.document.write("<PARAM NAME=title VALUE=>\n")
  win.document.write("<PARAM NAME=titlePos VALUE=0>\n")
  win.document.write("<PARAM NAME=viewType VALUE=1>\n")  
  win.document.write("<PARAM NAME=HQ VALUE=1>\n")
  win.document.write("<PARAM NAME=autoPan VALUE=yes>\n")
  win.document.write("<PARAM NAME=autoPanSpeed VALUE=10>\n")
  win.document.write("<PARAM NAME=startYaw VALUE=100>\n")  
  win.document.write("<PARAM NAME=startPitch VALUE=0>\n")
  win.document.write("<PARAM NAME=startFOV VALUE=65>\n")
  win.document.write("<PARAM NAME=partialStitch VALUE=no>\n")  
  win.document.write("<PARAM NAME=horFov VALUE=360>\n")
  win.document.write("<PARAM NAME=url VALUE="+escape(ifile)+">\n")
  win.document.write("</applet>\n")
  win.document.close();
}



//  End -->
