// Code for animating the thermometer

T_MAX = 32; // minimum clip value
T_MIN = 266; // maximum clip value
T_ANIM_TIME = 2000; // total ms to animate (for full animation)
T_ANIM_RATE = 20; // ms between frames
T_VAL_MAX = 25000;
/*
t_perc = t_val / T_VAL_MAX;
t_clip_val = 0;
if(t_val > T_VAL_MAX) {
	if(t_val < T_VAL_MAX+1000) {
		t_clip_val = T_MAX;
	}
} else {
	t_clip_val = (t_perc * (T_MAX-T_MIN)) + T_MIN;
}*/
t_adj_anim = ((T_ANIM_TIME-100) * t_perc) + 100;
t_current = T_MIN;
t_timer = 0;
function startTherm() {
	setTimeout(animateTherm, 1000);
}
function animateTherm() {
	therm = $("therm2");
	thermStyle = therm;
	if(therm.style) {
		thermStyle = therm.style;
	}
	thermStyle.clip = clipHeight(T_MIN);
	thermStyle.visibility = "visible";
	t_timer = new Date().getTime();
	setTimeout(animateThermTimer, T_ANIM_RATE);
}
function animateThermTimer() {
	var timeElapsed = new Date().getTime() - t_timer;
	if(timeElapsed > t_adj_anim) {
		timeElapsed = t_adj_anim;
	}
	var percChange = timeElapsed/t_adj_anim;
	var adjChange = Math.sin(percChange * 1.58);
	var h = Math.round(adjChange * (t_clip_val-T_MIN)) + T_MIN;
	thermStyle.clip = clipHeight(h);
	if(timeElapsed < T_ANIM_TIME) {
		setTimeout(animateThermTimer, T_ANIM_RATE);
	}
}
function clipHeight(h) {
	return "rect("+h+"px, auto, auto, auto)";
}

if(Event) {
	Event.observe(window, "load", startTherm);
}