// ---------------------------------------------------------------
// Coordenadas de la posición inicial de la nueva ventana abierta
// ---------------------------------------------------------------
var posX = -5;
var posY = -30;

// --------------------------------------------
// Parámetros para el movimiento de la ventana
// --------------------------------------------
var velocidad = 10;
var aceleracion = 1.5;
var TIEMPO_ESPERA = 50;		// Tiempo de espera en ms

var velocidad;
var altoPantalla;
var fin;

// ----------------------------------------------------
// Abrimos la ventan con los parámetros especificados
// ----------------------------------------------------
function Abrir_Ventana(theURL,nombre,w,h) { 
	
	var windowprops ="top="+((screen.height-h)/2)+",left="+((screen.width-w)/2)+",toolbar=no,location=no,status=no, menubar=no,scrollbars=no, resizable=no,width=" + w + ",height=" + h;

	// Si no hemos introducido ningún nombre de ventana, generamos uno aleatorio
	if (nombre != null) {nombreVent=nombre; }
	else {nombreVent="ventanaC3_"+Math.floor((Math.random()*100));}

//	alert("URL: "+theURL+"\nNOMBREVENT: "+nombreVent+"\nNOMBRE: "+nombre+"\nCADENA: "+windowprops);
	
	window.open(theURL,nombreVent,windowprops); 
} 

// ----------------------------------------------------
// Abrimos una ventana al tamaño máximo de la pantalla
// ----------------------------------------------------
function abrirVentanaMAX(pagina,nombreVentana) {
anchoPantalla = screen.width;
altoPantalla = screen.height;

// Si no hemos introducido ningún nombre de ventana, generamos uno aleatorio
if (nombreVentana==null) {nombreVentana="ventanaC3_"+Math.floor((Math.random()*100));}

miVentana = window.open(pagina,nombreVentana,'scrollbars=no,resizable=no,left=0,top=0,width='+anchoPantalla+',height='+altoPantalla+'');
miVentana.focus();
miVentana.moveTo(posX,posY);
}

// -------------------------------------------------------
// Cerramos la ventana con una animación de salida simple
// -------------------------------------------------------
function cierraVentana() {
	altoPantalla = screen.height;


	posY = posY + velocidad;
	window.parent.focus();
	window.parent.moveTo(posX,posY);
	velocidad = velocidad*aceleracion;
	
	setTimeout("cierraVentana()",TIEMPO_ESPERA);

	if (posY >= (altoPantalla+50)) {
		clearTimeout();
		window.parent.close();
		
		reinicializaVariables();
	}

}

// -----------------------------------------------------------
// Reinicializamos las variables modificadas en cierraVentana
// -----------------------------------------------------------
function reinicializaVariables() {	
	posX = -5;
	posY = -30;
	velocidad = 10;
}
