//
// Fade an element's opacity
// over the given amount of time.
//
var	fps = 60.0;			// frames per second.
var	mspf = 1000.0/fps;	// ms per frame.

function fadeInOpacity(id,start,stop) {
	var	nframes = Math.round(Math.max(0,stop-start)*fps);
	var	starttime = start*1000.0;
	var	fcall;

	for (var f=1; f < nframes; f++) {
		fcall = 'setOpacity(\'' + id + '\',' + (f/nframes) + ')';
		setTimeout(fcall, starttime + f*mspf);
	}
	fcall = 'setOpacity(\'' + id + '\',' + 1 + ')';
	setTimeout(fcall, stop*1000.0);
}

function fadeOutOpacity(id,start,stop) {
	var	nframes = Math.round(Math.max(0,stop-start)*fps);
	var	starttime = start*1000.0;
	var	fcall;

	for (var f=1; f < nframes; f++) {
		fcall = 'setOpacity(\'' + id + '\',' + (1 - f/nframes) + ')';
		setTimeout(fcall, starttime + f*mspf);
	}
	fcall = 'setOpacity(\'' + id + '\',' + 0 + ')';
	setTimeout(fcall, stop*1000.0);
}

//
// Sets opacity of elem.
//
function setOpacity(id,value) {
	var	elem_style = document.getElementById(id).style;

	elem_style.opacity = value;
	elem_style.filter = 'alpha(opacity=' + value*100 + ')';  /* for IE. opacity= or opacity: works */
} 

//
//	Sets color of elem.
//
function setColor(id,value) {
	var	elem_style = document.getElementById(id).style;
	var	c = Math.round(value);

	elem_style.color = "rgb(" + c + "," + c + "," + c + ")";
} 

//
//	Fade the text color over the given time period.
//
function fadeText(id,begincolor,endcolor,start,stop) {
	var	nframes = Math.round(Math.max(0,stop-start)*fps);
	var	starttime = start*1000.0;
	var	fcall;

	for (var f=1; f < nframes; f++) {
		fcall = 'setColor(\'' + id + '\',' + (begincolor + (endcolor-begincolor)*(f/nframes)) + ')';
		setTimeout(fcall, starttime + f*mspf);
	}
	fcall = 'setColor(\'' + id + '\',' + endcolor + ')';
	setTimeout(fcall, stop*1000.0);
}
