// -------------------------------------------------

var Conjuntos = new Array("Llegando", "Capilla", "Vistas", "Monasterio", "Comunidad", "Satelite")
var Cantidad = new Array(7, 9, 7, 7, 7, 5)
var NS = Conjuntos.length

// ==============================

var Nav

var Punteros = new Array()
var Imagenes = new Array()
var indice
var ultimo
var siguiente
var anterior
var s
var p = 0
var referencia
var leyenda
var TimerDescarga = false
var TimerMostrar = false
var ini

var n
var inicial
var actual
var minimo
var TimerSecuencia1 = false
var TimerSecuencia2 = false
var SecOn = false

// --------------------------------------------------------

if ( navigator.appName == "Microsoft Internet Explorer" ) { 
	Nav = "isIE" 
}

for ( i = 0 ; i < NS ; i++ ) {
	Punteros[i] = new Array(); 
	Imagenes[i] = new Array();
	for ( j = 0 ; j < Cantidad[i] ; j++ ) { 
		Punteros[i][j] = "img/"+((i+1)*100+j)+".jpg"; 
		Imagenes[i][j] = new Image();
	} 
}

// ---------------------------------------------

function RandomInteger(i) { 
	rn = Math.floor( Math.random() * i );
	return rn
}

function Ini() { 
	ini = true;
	s = RandomInteger( NS - 1 ); 
	ultimo = Punteros[s].length - 1; 
	indice = 0;
	MenuSet();
	p = s;
	Imagenes[s][indice].src = Punteros[s][indice];
	siguiente = indice + 1;
	if ( siguiente > ultimo ) { siguiente = 0 };
	Imagenes[s][siguiente].src = Punteros[s][siguiente];
	MostrarImagen();
}

function Conjunto(i) { 
	s = i - 1; 
	if ( s != p ) {	
		ini = true;
		DetenerTimer();
		DetenerSecuencia(); 
		indice = 0; 
		ultimo = Punteros[s].length - 1; 
		MenuSet();
		p = s;
		Imagenes[s][indice].src = Punteros[s][indice];
		siguiente = indice + 1;
		if ( siguiente > ultimo ) { siguiente = 0 };
		Imagenes[s][siguiente].src = Punteros[s][siguiente];
		MostrarImagen();
	}
}

function CambiarImagen() { 
	ini = true;
	DetenerTimer();
	DetenerSecuencia(); 
	do { s = RandomInteger( NS - 1 ) } while (s == p); 
	indice = RandomInteger( Punteros[s].length ); 
	ultimo = Punteros[s].length - 1; 
	MenuSet();
	p = s;
	Imagenes[s][indice].src = Punteros[s][indice];
	MostrarImagen();
}

function Anterior() { 
	DetenerTimer();
	DetenerSecuencia();  
	indice--; 
	if ( indice < 0 ) { indice = ultimo }; 
	Imagenes[s][indice].src = Punteros[s][indice];
	if ( Nav == "isIE" ) { 
		if ( Conjuntos[s] == "Satelite" ) { 
			document.getElementById("divfot").style.filter = "progid:DXImageTransform.Microsoft.Iris(irisstyle=CIRCLE,motion=in);" 
		} else { 
			document.getElementById("divfot").style.filter = "revealTrans(Transition=7, Duration=3)"; 
		}
	}
	anterior = indice - 1;
	if ( anterior < 0 ) { anterior = ultimo };
	Imagenes[s][anterior].src = Punteros[s][anterior];
	MostrarImagen();
}
	
function Siguiente() { 
	DetenerTimer();
	DetenerSecuencia(); 
	indice++; 
	if ( indice > ultimo ) { indice = 0}; 
	Imagenes[s][indice].src = Punteros[s][indice];
	if ( Nav == "isIE" ) { 
		if ( Conjuntos[s] == "Satelite" ) { 
			document.getElementById("divfot").style.filter = "progid:DXImageTransform.Microsoft.Iris(irisstyle=CIRCLE,motion=out);" 
		} else { 
			document.getElementById("divfot").style.filter = "revealTrans(Transition=6, Duration=3);"; 
		}
	};
	siguiente = indice + 1;
	if ( siguiente > ultimo ) { siguiente = 0 };
	Imagenes[s][siguiente].src = Punteros[s][siguiente];
	MostrarImagen()
}

function MostrarImagen() {
	if ( Imagenes[s][indice].complete ) {
		document.getElementById("spinner").style.display = "none";
		if ( ini == true ) {
			document.images['Foto'].src = Imagenes[s][indice].src;
			ini = false
		} else if ( Nav == "isIE" ){			
			document.getElementById("divfot").filters[0].apply();
			document.images["Foto"].src = Punteros[s][indice];
			document.getElementById("divfot").filters[0].play()
		} else {
			document.images["Foto"].src = "photo_pb.gif";
			TimerMostrar = setTimeout( "document.images['Foto'].src = Imagenes[s][indice].src;", 200);
		}
		MostrarLeyendas()
	} else {
		document.getElementById("spinner").style.display = "block";
		TimerDescarga = setTimeout( "MostrarImagen()", 100 ) 		
	}
}

function MostrarLeyendas() {
	referencia = ""+Conjuntos[s]+" > Imagenes : "+(indice+1)+" de "+Cantidad[s]+"";
	leyenda = "© Abadía de San Benito - Argentina";
	document.getElementById("divref").innerHTML = referencia;
	document.getElementById("divley").innerHTML = leyenda;
}

function DetenerTimer() {
	if ( TimerDescarga ) { clearTimeout( TimerDescarga); }
	if ( TimerMostrar ) { clearTimeout( TimerMostrar ); }
}

// --------------------------------------------------

function MenuOver(i) {
	if ( i != s ) { 
		document.getElementById("con"+(i+1)).style.background = "#D65332";
		document.getElementById("con"+(i+1)).style.border = "1px solid #FFFFFF";
	} else { 
		document.getElementById("con"+(i+1)).style.cursor = "default";
	}
	
}

function MenuOut(i) {
	if ( i != s ) { 
		document.getElementById("con"+(i+1)).style.background="#336699";
		document.getElementById("con"+(i+1)).style.border = "1px solid #75A8CA";
	} else { 
		document.getElementById("con"+(i+1)).style.cursor = "pointer";
	}

}

function MenuSet() {
	document.getElementById("con"+(p+1)).style.background="#336699";
	document.getElementById("con"+(p+1)).style.border = "1px solid #75A8CA";
	document.getElementById("con"+(p+1)).style.cursor = "pointer";
	document.getElementById("con"+(s+1)).style.background="#840000";
	document.getElementById("con"+(s+1)).style.border = "1px solid #FFFFFF";
	document.getElementById("con"+(s+1)).style.cursor = "default";
}

function ClickDown(img) {
	document.images[img].style.border = "1px solid white";
}

function ClickUp(img) {
	document.images[img].style.border = "1px solid #75A8CA"
}

// ------------------------------------------------------

function Secuencia() { 
	if ( SecOn == false ) {
		if ( Nav == "isIE" ) { document.getElementById("divfot").filters[0].stop() };
		DetenerTimer();
		AvanzarSecuencia();
	}
	else {
		DetenerSecuencia()
	}  
} 

function AvanzarSecuencia() { 
	inicial = new Date(); 
	inicial = inicial.getTime() 
	n = indice;
	n++; 
	if ( n > ultimo ) { n = 0 };
	Imagenes[s][n].src = Punteros[s][n]
	document.images[ "Sec" ].src = "pause.gif";
	document.getElementById("play").innerHTML = "Pausa";
	document.images[ "Sig" ].src = "next_ani02.gif";
	ClickDown('Sig');
	VerificarDescargaSiguiente() 
}

function DetenerSecuencia() { 
	if ( SecOn == true ) {
		document.getElementById("spinner").style.display = "none";
		if ( Nav == "isIE" ) { document.getElementById("divfot").filters[0].stop() };
		if ( TimerSecuencia1 ) { clearTimeout( TimerSecuencia1 ) }; 
		if ( TimerSecuencia2 ) { clearTimeout( TimerSecuencia2 ) };
		document.images[ "Sec" ].src = "play.gif";
		document.getElementById("play").innerHTML = "Secuencia";
		document.images[ "Sig" ].src = "next.gif";
		ClickUp('Sig');
		SecOn = false;
	} else {
		if ( Nav == "isIE" ) { document.getElementById("divfot").filters[0].stop(); }
	}
}

function VerificarDescargaSiguiente()  { 
	if (Imagenes[s][n].complete ) {
		document.getElementById("spinner").style.display = "none";
		actual = new Date();
		actual = actual.getTime(); 
		actual = actual - inicial;
		if ( SecOn == false ) { minimo = 3000; SecOn = true; } else { minimo = 6000 };
		var intervalo = minimo - actual;
		if ( intervalo <= 0 ) { intervalo = 1 };
		TimerSecuencia1 = setTimeout( "MostrarImagenSiguiente()", intervalo ) 
	}
	else {
		document.getElementById("spinner").style.display = "block";
		TimerSecuencia2 = setTimeout( "VerificarDescargaSiguiente()", 100 ) 
	} 
}

function MostrarImagenSiguiente() {
	indice = n;
	if ( Nav == "isIE" ) {
		document.getElementById("divfot").style.filter = "revealTrans(Transition=6, Duration=3);"; 
		document.getElementById("divfot").filters[0].apply();
		document.images["Foto"].src = Imagenes[s][indice].src;
		document.getElementById("divfot").filters[0].play();
	} else {
		document.images["Foto"].src = "photo_pb.gif";
		TimerMostrar = setTimeout( "document.images['Foto'].src = Imagenes[s][indice].src;", 50);
	}
	MostrarLeyendas();
	AvanzarSecuencia() 
} 

// -------------------------------------------