(function($){$.fn.extend({colorPicker:function(callback,colors){if(!colors){var colors=[],i=0;for(red=0;red<16;red+=3){for(green=0;green<16;green+=3){for(blue=0;blue<16;blue+=3){colors[i]=red.toString(16)+red.toString(16)+green.toString(16)+green.toString(16)+blue.toString(16)+blue.toString(16);i+=1}}}}else{i=colors.length}for(gray=0;gray<16;gray+=3){var hex=gray.toString(16);colors[i]=hex+hex+hex+hex+hex+hex;i+=1}return this.each(function(){$(this).click(function(ev){$('div.colorPicker').hide();if($.browser.msie&&$.browser.version<7){$('select:visible').addClass('ColorPicker-hide').hide()}var currentElement=this;var mouseX=ev.pageX-$.getBodyMarginLeft()-60,mouseY=ev.pageY-40;var cpObject=$(this).data('colorPicker');if(typeof cpObject=='undefined'){var cpObject=$('<div />');cpObject.addClass('colorPicker').css({width:'236px',height:'172px',border:'1px solid #ccc','background-color':'#e8e8e8',position:'absolute',left:mouseX,top:mouseY,'z-index':9999,display:'none'});$.each(colors,function(index,value){var swatch=$('<div />');swatch.addClass('swatch').css({float:'left',width:'12px',height:'12px',margin:'1px 0px 0px 1px',cursor:'pointer','background-color':'#'+value}).mouseover(function(){$('div.colorPicker div.preview').css('background-color','#'+value)});swatch.click(function(){$('div.colorPicker').hide();if($.browser.msie&&$.browser.version<7){$('select.ColorPicker-hide').removeClass('ColorPicker-hide').show()}if(typeof callback=='function'){callback('#'+value,currentElement)}});swatch.appendTo(cpObject)});$('<div />').addClass('preview').css({float:'left',width:'150px',height:'12px',margin:'1px 0px 0px 1px',border:'1px solid #000','background-color':'#fff'}).appendTo(cpObject);cpObject.appendTo('body');$(this).data('colorPicker',cpObject)}cpObject.css({left:mouseX,top:mouseY}).show()})})}})})(jQuery);