jQuery.fn.colourPicker=function(conf)
{function niceColour(hex)
{var r=hex.substr(0,2),g=hex.substr(2,2),b=hex.substr(4,2);return'ffffff';}
var config={ico:'ico.gif',title:'Choisissez une couleur',inputBG:true,aniSpeed:500,chem:'non'};config=$.extend(config,conf);if(!$('#colour-picker').length)
{$('<div id="colour-picker"></div>').appendTo('body').hide();}
return this.each(function(i)
{var select=jQuery(this);if(config.chem!='non'){var cpCarre='<table cellspacing=0 cellpadding=0 border=0 style="display:inline;"><tr><td width=10 bgcolor="'+select.attr('def')+'" >&nbsp;</td><td width=10>&nbsp;</td></tr></table>';}
else{var cpCarre='_';}
var cpInput='<input type="text" name="'+select.attr('name')+'" id="'+select.attr('name')+'" class="colour-picker-input" size="15" maxlength="15" value="'+select.attr('title')+'" readonly/>';var cpIco='<a href="#" class="colour-picker-open'+select.attr('name')+'"><img src="'+config.ico+'" alt="Choisir" style="border:none;"/></a>';var loc='';jQuery('option',select).each(function()
{var hex=jQuery(this).val(),title=jQuery(this).text();loc+='<li><a href="#" title="'+title+'" rel="'+hex+'" style="background: #'+hex+'; colour: '+niceColour(hex)+';">'+title+'</a></li>';});jQuery(cpIco).insertAfter(select);jQuery(cpInput).insertAfter(select);jQuery(cpCarre).insertAfter(select);select.remove();jQuery('a.colour-picker-open'+select.attr('name')).click(function()
{var input=jQuery(this).prev('input.colour-picker-input'),icoPos=jQuery(this).offset();jQuery('#colour-picker').html('<h2>'+config.title+'</h2><ul>'+loc+'</ul>').css({position:'absolute',left:icoPos.left+'px',top:icoPos.top+'px'}).show(config.aniSpeed);jQuery('#colour-picker a').click(function()
{var hex=jQuery(this).attr('title');var hex2=jQuery(this).attr('rel');input.val(hex);jQuery('#colour-picker').hide(config.aniSpeed);if(config.chem!='non'){window.location=config.chem+hex2;}
return false;});return false;});});};
