// for better coding:
//		http://www.axentric.com/posts/default/7
//

	//------- color fading management routines
	
	// prepare the element with start/end values for interpolation.
	// we have to separate out the RGB components into 3 integers
	//
	function setupStartEndColors( elt, startColor, endColor) {
		if ( startColor.charAt(0) == '#') startColor = startColor.substring(1);
		if ( endColor.charAt(0) == '#') endColor = endColor.substring(1);
		
		elt.startRed	= parseInt( '0X' + startColor.substr(0,2));
		elt.endRed		= parseInt( '0X' + endColor.substr(0,2));
		elt.startGreen	= parseInt( '0X' + startColor.substr(2,2));
		elt.endGreen	= parseInt( '0X' + endColor.substr(2,2));
		elt.startBlue	= parseInt( '0X' + startColor.substr(4,2));
		elt.endBlue		= parseInt( '0X' + endColor.substr(4,2));
	}
	// convert an integer into a 2-digit hex string
	//function toFF(val) { return (Math.floor(val/16).toString(16) + Math.floor(val%16).toString(16)).toUpperCase(); }
	function toFF(val) { var x=Math.floor(val).toString(16); if(x.length==1) x='0'+x; return x.toUpperCase(); }
	// linear interpolation to get the current hex color
	function buildColor( elt, pct ) {
		return '#' + toFF( elt.startRed + pct*(elt.endRed - elt.startRed)) +
					toFF( elt.startGreen + pct*(elt.endGreen - elt.startGreen)) +
					toFF( elt.startBlue + pct*(elt.endBlue - elt.startBlue));
	}
	
	//-------

// first argument is required; the rest are optional
function fadingHilight(id,stepCount,stepDelay,startColor,endColor){
	var elt = document.getElementById(id);
	if ( elt) {
		elt.curStep = 0;
		elt.stepCount = stepCount || 8;
		elt.stepDelay = stepDelay || 50;
		if ( !startColor) startColor = "#ffff33";
		if ( !endColor) endColor = "#ffffff";
		elt.endColor = endColor;
		elt.style.backgroundColor = startColor;
		setupStartEndColors( elt, startColor, endColor);
		
		// initialize the timer
		elt.timerID = 0;
		SetHilightTimer(id);
	}
}

function SetHilightTimer(id) {
	elt = document.getElementById(id);
	if ( elt.curStep == elt.stepCount) {
		clearTimeout( elt.timerID);
		
		// we're done -- if we need to do any cleanup or display a final
		// message, here's where we do it!
		//
		elt.style.backgroundColor = elt.endColor;
		return true;
	}
	else {
		elt.timerID = setTimeout("SetHilightTimer('"+id+"')", elt.stepDelay);
		elt.style.backgroundColor = buildColor( elt, elt.curStep / elt.stepCount);
		++elt.curStep;
	}
}