// Valores iniciales del parámetro t:
inicio = 0;		// valor inicial de t
fin = 26;		// valor final de t
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
t = inicio;    // Comenzamos: el tiempo toma su valor inicial por defecto	
reloj = null;		// Se crea un reloj virtual


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

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.Huygens;	
	t = applet.getValue("t");
	if(t < 6) {
		t = t + paso;
		applet.evalCommand("t=" + t);
	} else{
		pausa();
	}
}

function atras() {	
	applet = document.Huygens;	
	t = applet.getValue("t");
	if(t > 0.05) {
		t = t - paso;
		applet.evalCommand("t=" + t);
	} else{
		pausa();
	}
}

