function colorFader(elm,from,to,time,steps) {
	this.elm = elm;
	this.from = this.toRGB(from);
	this.to = this.toRGB(to);
	this.time = time;
	this.counter = 0;
	this.steps = steps
	this.active = false;
	this.now;
	this.start();
}

colorFader.prototype.start = function() {
	this.active = true;
	this.counter = 0;
	var scope = this
	this.val = window.setInterval(function(){ scope.increase()},this.time);
}

colorFader.prototype.stop = function() {
	this.active = false;
	window.clearInterval(this.val)
	this.counter = 0;
}


colorFader.prototype.toRGB = function (hexColor) {
	var rgb = new Object();
	rgb.r = parseInt(hexColor.substring(0,2),16);
	rgb.g = parseInt(hexColor.substring(2,4),16)
	rgb.b = parseInt(hexColor.substring(4,6),16)
	return rgb;
}

colorFader.prototype.compute = function (f,t,a,n) {
	var res = new Object();
	res.r = Math.round(f.r + ((t.r - f.r)/a * n));
	res.g = Math.round(f.g + ((t.g - f.g)/a * n));
	res.b = Math.round(f.b + ((t.b - f.b)/a * n));
	return res;
}

colorFader.prototype.increase = function() {
	this.counter++
	var res = this.compute(this.from,this.to,this.steps,this.counter);
	this.now = res;
	this.elm.style.backgroundColor = 'rgb('+res.r+','+res.g+','+res.b+')'
	if (this.counter == this.steps) {
		this.stop();
	}
}
