var num=0;
var namegal = ""
var ancho=700;
var alto=630;
thisPic = 0;
myPix= new Array();
function getNum() { return num; }
function setNum(nfot) { num = nfot; }
function getNamegal() { return namegal; }

function Carga(){
	//myPix = new Array(num);
	myPix.splice(0,myPix.length); //resetea el vector (borra todos sus elementos)
	var calc = 0;
	for (i=0; i<getNum(); i++) {
		if (i <= 9) {
			nombre = getNamegal() + '0' +  i.toString() + ".jpg";
		}
		else if ((i>9) && (i<=19)){
			calc = i-10;
			nombre = getNamegal() + '1' +  calc.toString() + ".jpg";
		}
		else if ((i>19) && (i<=29)){
			calc = i-20;
			nombre = getNamegal() + '2' +  calc.toString() + ".jpg";
		}
		else if ((i>29) && (i<=39)){
			calc = i-30;
			nombre = getNamegal() + '3' +  calc.toString() + ".jpg";
		}
		else if ((i>39) && (i<=49)){
			calc = i-40;
			nombre = getNamegal() + '4' +  calc.toString() + ".jpg";
		}
		else if (i>49){
			alert("Error, no has preparado para mostrar más de 39 fotos");	
		}
		myPix[i]=nombre;
		//alert("He generado: " + nombre);
	}	
}

// Me queda: diseño más atractivo, evitar que se abran 2 ventanas Popup a la vez.

function VentanaNueva(titulo,num,ngal) {
	derecha=(screen.width-ancho)/2;
	arriba=(screen.height-alto)/2;
	opc="toolbar=0,scrollbars=0,title=Galeria,location=0,statusbar=0,menubar=0,resizable=0,width=" + ancho + ",height=" + alto + ",left=" + derecha + ",top=" + arriba;
	ventana=window.open("","",opc);
	//ventana.focus()   // onFocus y onblur metodos asociados  //ventana.blur()
	setNum(num);
	namegal = ngal;
	Carga();
	ventana.document.write('<HTML><HEAD><SCRIPT LANGUAGE="Javascript" SRC="gal_ventana.js">alert("Error con el fichero js");<\/SCRIPT><\/HEAD><BODY BGCOLOR=#C0DFFD><H1 ALIGN=CENTER>Fotos de la ruta<P><IMG SRC="" NAME="myPicture" WIDTH=640 HEIGHT=480 /><P><A HREF="javascript:chgSlide(-1)"><< Anterior<\/A><script>prueba();<\/SCRIPT><A HREF="javascript:chgSlide(1)">&nbsp;&nbsp;&nbsp;Siguiente >><\/A><\/H1><\/BODY><\/HTML>');
	ventana.document.title = titulo;
	ventana.document.myPicture.src=myPix[0];
	ventana.document.close();
}

// Esta función fuerza a que se cargue la imágen inicial en navegadores FireFox
function prueba(){
	document.myPicture.src=opener.myPix[0]
}

function chgSlide(direction) {
	imgCt = opener.myPix.length - 1
	if (document.images) {
		thisPic = thisPic + direction
		if (thisPic > imgCt) {
			thisPic = 0
		}
		if (thisPic < 0) {
			thisPic = imgCt
		}
		document.myPicture.src=opener.myPix[thisPic]
	}
}


