// JavaScript Document
//-----------------------------------
var tiempo = 0;
var tempor = null;
var anho = 0;
var img_aleatoria = 0;

function aleatoria()
{
	//nota: las imágenes han de tener números consecutivos
	
	anho = (Math.round(Math.random()*7)) + 2002; // calcula el año aleatoriamente, sumarle uno a lo que multiplica por año añadido
	var num_imagenes;
	switch (anho)
	{
		case 2002: num_imagenes = 36; break;
		case 2003: num_imagenes = 32; break;
		case 2004: num_imagenes = 44; break;
		case 2005: num_imagenes = 44; break;
		case 2006: num_imagenes = 42; break;
		case 2007: num_imagenes = 30; break;
		case 2008: num_imagenes = 27; break;
		case 2009: num_imagenes = 33; break;
	} 
	img_aleatoria = (Math.round(Math.random()*(num_imagenes-1))) + 1;
	
	if (img_aleatoria < 10)
	{
		img_aleatoria = '0'+img_aleatoria;
	}
	img_aleatoria = img_aleatoria + '.jpg';
	var ruta = 'imagenes/' + anho + '/150x150/' + img_aleatoria; 
	/*
	Solo para IE
	var fso = new ActiveXObject("Scripting.FileSystemObject"); 
	var fso = new Object("Scripting.FileSystemObject"); 
	if (fso.FileExists(ruta))
	if (FileExists(ruta))
	if (isFile(ruta))
		return (ruta);
	else
		aleatoria();*/
	return (ruta);
}


function automat(seg)
{
	tiempo = parseInt(seg);
	if (isNaN(tiempo) || tiempo <= 0)
		alert("Error en el tiempo")
	else
	tempor = setTimeout("pasar()", tiempo);
}

function parar()
{
	clearTimeout(tempor);
}

function pasar()
{
	document.images.centro.src = aleatoria();
	document.getElementById('enlace').href="javascript:parar();mostrarimagen('imagenes/"+anho+"/800x800/"+img_aleatoria+"', '"+anho+"', '"+img_aleatoria+"')";		
	document.getElementById('annio').innerHTML="Catálogo "+anho;
	tempor = setTimeout("pasar()", tiempo);		
}

//-------------------------------------------
var miventana;

    function mostrarimagen(url, anho2, fichero) {
		//alto = 870;
		alto = 910;
		ancho = 840;			
		miventana = window.open("abririmagen.php?anho="+anho2+"&fichero="+fichero+"","ventana","status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width="+ancho+",height="+alto+",left=10,top=10");
		miventana.resizeTo(ancho, alto);
		miventana.focus();
	}		
