function contrast_color(color)
{
	var r = 0, g = 0, b = 0;

	//parse RGB values from argument
	if(color.indexOf('rgb') !== -1)
	{
		//parse values from rgb(#, #, #) format
		var split  = color.split('(');
		var values = split[1].split(',');
		
		r = values[0].replace(' ', '').replace(')', '').replace('(', '');
		g = values[1].replace(' ', '').replace(')', '').replace('(', '');
		b = values[2].replace(' ', '').replace(')', '').replace('(', '');
	}
	else
	{
		//convert hex value to rgb
		color = (color.charAt(0)=="#") ? color.substring(1,7) : color;
		
		r = parseInt((color).substring(0,2), 16);
		g = parseInt((color).substring(2,4),16);
		b = parseInt((color).substring(4,6),16);
	}

    // Counting the perceptive luminance - human eye favors green color... 
    var luminance = 1 - ( (0.299 * r) + (0.587 * g) + (0.114 * b) ) / 255;

	//return white for dark colors, black for light colors
	return (luminance < 0.5) ? '000000' : 'ffffff';
}
