var iId = null
var sr, sg, sb
var er, eg, eb
var interval = 1
var step
var steps = 16
var colorstart, colorend
var daEl
var timerRunning = false
var hexa = new Array()
for (var i = 0; i < 16; i++) {
	hexa[i] = i.toString(16)
}
function hex(i) {
	if (i < 0)	  return "00";
	else if (i > 255) return "ff";
	return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}
function hextodec(daHex) {
	return parseInt('0x' + daHex)
}
function setColor(r,g,b) {
	var hr = hex(r); var hg = hex(g); var hb = hex(b);
	var daColor = "#"+hr+hg+hb
	daEl.style.backgroundColor = daColor
	if (daColor == colorend.toLowerCase()) {
		clearInterval(iId)
		iId = null
		timerRunning = false
	}
}
function fade() {
	step++
	setColor(
		Math.floor(sr * ((steps-step)/steps) + er * (step/steps)),
		Math.floor(sg * ((steps-step)/steps) + eg * (step/steps)),
		Math.floor(sb * ((steps-step)/steps) + eb * (step/steps))
		);
}
function myfade(el,cs,ce,iv,st) {
	daEl = el
	colorstart = cs
	colorend = ce
	interval = iv
	steps = st
	step = 0
	if (timerRunning) {
		clearInterval(iId)
		iId = null
	}
	var myRe = /#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i
	if (colorstart.match(myRe)) {
		sr = hextodec(RegExp.$1)
		sg = hextodec(RegExp.$2)
		sb = hextodec(RegExp.$3)
	}
	if (colorend.match(myRe)) {
		er = hextodec(RegExp.$1)
		eg = hextodec(RegExp.$2)
		eb = hextodec(RegExp.$3)
	}
	timerRunning = false;
	iId = setInterval("fade()",interval)
	timerRunning = true;
}
function cellover(table_cell) {
	// play around with these values
	// element, from_color, to_color, interval(milliseconds), transition steps
	// make sure to change the end color in cellout()
	myfade(table_cell,'#E8E8E8','#D2D2D2',10,30)
}
function cellout(table_cell) {
	if (timerRunning) {
		clearInterval(iId)
		iId = null;
	}
table_cell.style.backgroundColor = '#E8E8E8';
}
