/*	|=======================================================| **
**	| Project         : JeaBsy Web							| **
**	| Created By      : Jeffrey Benistant					| **
**	| Date            : May 2011							| **
**	| Email           : Jeffrey@24design.nl					| **
**	|=======================================================| */

/****************************************************************************************************/

function ColorButton( id, c )
{
	if( !c ) { c = "#FFE862"; }

	var original = $( '#' + id ).css('background-color');
	var ChangeTo = 'rgb(' + hex2r( c ) + ',' +  hex2g( c ) + ',' + hex2b( c ) + ')';

	$('#'+id).hover(
		function() {
    	    $(this).stop().animate({backgroundColor: ChangeTo }, 500);
        },
		function () {
        	$(this).stop().animate({backgroundColor: original }, 200);
    	}
	);
}

function hex2r( hex ) { return parseInt( h( hex ).substring(0,2), 16 ); }
function hex2g( hex ) { return parseInt( h( hex ).substring(2,4), 16 ); }
function hex2b( hex ) { return parseInt( h( hex ).substring(4,6), 16 ); }
function h ( hex ) { return ( hex.charAt(0) == "#" ) ? hex.substring(1,7) : hex; }

function rgb2hex( rgb )
{
	rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	function hex(x) {
		return ("0" + parseInt(x).toString(16)).slice(-2);
	}
	return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
