function ColorChanger(elemId, property, currColor) {
	this.elemId = elemId;
	this.property = property;
	this.currColor = currColor;
}

ColorChanger.prototype.elemId = null;
ColorChanger.prototype.property = null;
ColorChanger.prototype.currColor = null;
ColorChanger.prototype.currChange = null;

ColorChanger.prototype.ChangeColor = function(newColor, frames, frameDelay) { 
	clearTimeout(this.currChange);
	var stepsR = this.CreateSteps(this.ConvertHexToBinary(this.currColor.substr(0,2)), this.ConvertHexToBinary(newColor.substr(0,2)), frames);
	var stepsG = this.CreateSteps(this.ConvertHexToBinary(this.currColor.substr(2,2)), this.ConvertHexToBinary(newColor.substr(2,2)), frames);
	var stepsB = this.CreateSteps(this.ConvertHexToBinary(this.currColor.substr(4,2)), this.ConvertHexToBinary(newColor.substr(4,2)), frames);
	this.ChangeColorStep(newColor, frames, frameDelay, stepsR, stepsG, stepsB);
}

ColorChanger.prototype.ChangeColorStep = function(newColor, frames, frameDelay, stepsR, stepsG, stepsB) { 
	this.currColor = (frames == 1) ? newColor : stepsR[frames-1] + stepsG[frames-1] + stepsB[frames-1];
	eval("document.getElementById('" + this.elemId + "').style." + this.property + "='#" + this.currColor + "';");
	if (frames > 1) { 
		var closureThis = this;
		this.currChange = setTimeout(function(){closureThis.ChangeColorStep(newColor, frames-1, frameDelay, stepsR, stepsG, stepsB); closureThis = null;}, frameDelay);
	}
}

ColorChanger.prototype.CreateSteps = function(startVal, endVal, frames) { 
	var ret = new Array();
	for (var f=frames-1; f >= 0; f--)
		ret[f] = this.ConvertBinaryToHex(Math.ceil(startVal + (((endVal - startVal) / frames)) * (frames - f - 1)), 2);
	return ret;
}

// based on this: http://snipplr.com/view/139/base-conversion/
ColorChanger.prototype.ConvertBinaryToHex = function(dec, padding) { 
	var base = "0123456789ABCDEF";
	var len = base.length;
	var ret = '';
	while(dec > 0) {
		ret = base.charAt(dec % len) + ret;
		dec = Math.floor(dec / len);
	}
	while(ret.length < padding) ret = "0" + ret;
	return ret;
}

ColorChanger.prototype.ConvertHexToBinary = function(num) { 
	var base = "0123456789ABCDEF";
	var len = base.length;
	var ret = 0;
	for(var x=1; num.length > 0; x *= len) {
		ret += base.indexOf(num.charAt(num.length - 1)) * x;
		num = num.substr(0,num.length - 1);
	}
	return ret;
}