// Valores iniciales del parámetro tiempo:
inicio = 0;		// valor inicial de tiempo
fin = 26;		// valor final de tiempo
df1=0;
df2=0;
mueve = false;	// la acción está parada al iniciarse el programa
espera = 50;	// milisegundos de intervalo del reloj (la acción se ejecuta cada 50 milisegundos, o sea, 20 "fotogramas" por segundo)
paso = 0.099;	// incremento del tiempo en cada ejecución 

// Nota importante: para evitar "singularidades" (errores de Java)
// NO PONER PASO = 0.1 PUES 0.1 EN BINARIO NO ES EXACTO: 0.1 (decimal) = .0001100011000111000111… (binario)
			
// Programa
tiempo = inicio;    // Comenzamos: el tiempo toma su valor inicial por defecto	
reloj = null;		// Se crea un reloj virtual


function reinicio() {	
	applet = document.Localizacion;
	setTimeout("clearInterval(reloj)", 0);
	mueve = false;
	tiempo = inicio;
	applet.evalCommand("tiempo=" + tiempo);
	invisible();
}

function retrocede() {	
	if (!mueve){
		mueve = true; 
		reloj = setInterval("atras()", espera);
	}
}

function avanza() {	
	if (!mueve){
		mueve = true; 
		reloj = setInterval("adelante()", espera);
	}
}

function pausa() {
	if (mueve){
		mueve = false; 
		setTimeout("clearInterval(reloj)", 0);	
	}
}

function adelante() {
	applet = document.Localizacion;	
	tiempo = applet.getValue("tiempo");
	max = applet.getValue("max");
	a1 = applet.getValue("a'");
	a2 = applet.getValue("a");
	b1 = applet.getValue("b'");
	b2 = applet.getValue("b");
	if(tiempo < max+2) {
		if (tiempo >= a1){
			applet.setVisible("T7",true);
			applet.setVisible("T13",true);
		}
		if (tiempo >= a2){
			applet.setVisible("T8",true);
			applet.setVisible("T13",true);
		}
		if (tiempo >= b1){
			applet.setVisible("T9",true);
			applet.setVisible("T14",true);
		}
		if (tiempo >= b2){
			applet.setVisible("T10",true);
			applet.setVisible("T14",true);
		}
		tiempo = tiempo + paso;
		applet.evalCommand("tiempo=" + tiempo);
	} else{
		/*setTimeout("clearInterval(reloj)", 0);
		mueve = false;
		fin = max+2;
		tiempo = fin;
		applet.evalCommand("tiempo=" + tiempo);*/
		reinicio();
		avanza();
	}
}

function atras() {	
	applet = document.Localizacion;	
	tiempo = applet.getValue("tiempo");
	max = applet.getValue("max");
	a1 = applet.getValue("a'");
	a2 = applet.getValue("a");
	b1 = applet.getValue("b'");
	b2 = applet.getValue("b");
	if(tiempo > inicio) {
		if (tiempo < a1){
			applet.setVisible("T7",false);
		}
		if (tiempo < a2){
			applet.setVisible("T8",false);
		}
		if (tiempo < b1){
			applet.setVisible("T9",false);
		}
		if (tiempo < b2){
			applet.setVisible("T10",false);
		}
		tiempo = tiempo - paso; 
		if (tiempo < 0.1){
			tiempo = 0;
		}
		applet.evalCommand("tiempo=" + tiempo);
	} else{
		reinicio();
	}
}

function invisible(){
	applet = document.Localizacion;
	applet.setVisible("T13",false);
	applet.setVisible("T14",false);
	applet.setVisible("T7",false);
	applet.setVisible("T8",false);
	applet.setVisible("T9",false);
	applet.setVisible("T10",false);
}