jQuery.fn.hexcolor = function() 
{
	// Generates the hex-digits for a colour.
    function hex(x) 
    {
            hexDigits = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
            return isNaN(x) ? '00' : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
    };
    
	var color = $(this[0]).css('background-color');
	
	var regex = /rgb\((\d+),\s?(\d+),\s?(\d+)\);?/gi;
	
	var match = regex.exec(color);

	if(match != null)
	{
		color = hex(match[1]) + hex(match[2]) + hex(match[3]);
	} 
	else // It's already hex
	{
		if(color.indexOf('#') == 0)
			color = color.substring(1);
	}

	return color;
};