// Valores iniciales del parámetro tiempo:
inicio = 94.5;		// valor inicial de tiempo
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.029;	// 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);
}

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");
	tiempo = tiempo + paso;
	applet.evalCommand("tiempo=" + tiempo);
}

function atras() {	
	applet = document.Localizacion;	
	tiempo = applet.getValue("tiempo");
	if(tiempo > inicio) {
		tiempo = tiempo - paso; 
		if (tiempo < 0.1){
			tiempo = 0;
		}
		applet.evalCommand("tiempo=" + tiempo);
	} else{
		reinicio();
	}
}
