function hexCharToInt(cIn)
{
	var c = cIn.toUpperCase();
	
	if(c.charCodeAt(0) > 57)
		return (c.charCodeAt(0) - 55);
	else 
		return (c.charCodeAt(0) - 48);
}

function intToHexChar(i)
{
	if(i > 9)
		return String.fromCharCode(i + 55);
	else 
		return String.fromCharCode(i + 48);
}

function intToHexString(i)
{
	if(i == 0)
		return '0';

	var s = '';
	var temp = i;
	
	while(temp > 0)
	{
		s = intToHexChar(temp & 15) + s;
		temp = temp >> 4;
	}
	
	return s;
}

function hexStringToInt(hex)
{
	var intValue = 0;
	
	for(i = 0; i < hex.length; i++)
	{
		intValue += hexCharToInt(hex.charAt(i)) << (4 * (hex.length - i - 1));
	}
	
	return intValue;
}

function miColorTransformer(color1, color2)
{
	this.c1 = new Object()
	this.c2 = new Object()
	this.c1.hex = color1;
	this.c2.hex = color2;
	this.c1.r = hexStringToInt(color1.substr(1, 2));
	this.c1.g = hexStringToInt(color1.substr(3, 2));
	this.c1.b = hexStringToInt(color1.substr(5, 2));
	this.c2.r = hexStringToInt(color2.substr(1, 2));
	this.c2.g = hexStringToInt(color2.substr(3, 2));
	this.c2.b = hexStringToInt(color2.substr(5, 2));
	this.rDifference = this.c1.r - this.c2.r;
	this.gDifference = this.c1.g - this.c2.g;
	this.bDifference = this.c1.b - this.c2.b;
}

miColorTransformer.prototype.getColor=function(value)
{
	var r = intToHexString(this.c1.r - (this.rDifference * value));
	var g = intToHexString(this.c1.g - (this.gDifference * value));
	var b = intToHexString(this.c1.b - (this.bDifference * value));
	r = makeTwoDigit(r);
	g = makeTwoDigit(g);
	b = makeTwoDigit(b);
		
	return '#' + r + g + b;
}

function makeTwoDigit(s)
{
	if( s.length < 1 )
		return '00';
		
	if( s.length == 1 )
		return '0' + s;
		
	if( s.length == 2 )
		return s;
		
	if( s.length > 2 )
		return 'FF';
}
