!function(a){function b(a){var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);if(!b)return"#FFF";var c=parseInt(b[1],16),d=parseInt(b[2],16),e=parseInt(b[3],16),f=.5>.213*c/255+.715*d/255+.072*e/255;return f?"#FFF":"#000"}var c=function(a,c,d){var e=d.colorCodeColor||b(c);a.data("color",c).css({color:e,textAlign:d.colorCodeAlign,backgroundColor:c}),d.displayColorCode===!0&&a.text(c)};a.fn.simpleColor=function(b){function d(){b=a.simpleColorOptions;var d=a("<div class='simpleColorContainer' />");d.css("position","relative");var f=this.value&&""!=this.value?this.value:b.defaultColor,g=a("<div class='simpleColorDisplay' />");g.css(b.displayCSS),c(g,f,b),d.append(g);var h=function(d){if(a("html").bind("click.simpleColorDisplay",function(f){a("html").unbind("click.simpleColorDisplay"),a(".simpleColorChooser").hide();var h=a(f.target);(h.is(".simpleColorCell")===!1||a.contains(a(d.target).closest(".simpleColorContainer")[0],h[0])===!1)&&c(g,g.data("color"),b),b.onClose&&b.onClose(e)}),d.data.container.chooser)d.data.container.chooser.toggle();else{var f=a("<div class='simpleColorChooser'/>");f.css(b.chooserCSS),d.data.container.chooser=f,d.data.container.append(f);for(var h=0;h<b.colors.length;h++){var i=a("<div class='simpleColorCell' id='"+b.colors[h]+"'/>");i.css({width:b.cellWidth+"px",height:b.cellHeight+"px",margin:b.cellMargin+"px",cursor:"pointer",lineHeight:b.cellHeight+"px",fontSize:"1px","float":"left","background-color":"#"+b.colors[h]}),f.append(i),(b.onCellEnter||b.livePreview)&&i.bind("mouseenter",function(){b.onCellEnter&&b.onCellEnter(this.id,e),b.livePreview&&c(g,"#"+this.id,b)}),i.bind("click",{input:d.data.input,chooser:f,displayBox:g},function(d){var f="#"+this.id;d.data.input.value=f,a(d.data.input).change(),c(g,f,b),d.data.chooser.hide(),b.displayColorCode&&d.data.displayBox.text(f),b.onSelect&&b.onSelect(this.id,e)})}}},i={input:this,container:d,displayBox:g};g.bind("click",i,h),a(this).after(d),a(this).data("container",d)}var e=this,f=["990033","ff3366","cc0033","ff0033","ff9999","cc3366","ffccff","cc6699","993366","660033","cc3399","ff99cc","ff66cc","ff99ff","ff6699","cc0066","ff0066","ff3399","ff0099","ff33cc","ff00cc","ff66ff","ff33ff","ff00ff","cc0099","990066","cc66cc","cc33cc","cc99ff","cc66ff","cc33ff","993399","cc00cc","cc00ff","9900cc","990099","cc99cc","996699","663366","660099","9933cc","660066","9900ff","9933ff","9966cc","330033","663399","6633cc","6600cc","9966ff","330066","6600ff","6633ff","ccccff","9999ff","9999cc","6666cc","6666ff","666699","333366","333399","330099","3300cc","3300ff","3333ff","3333cc","0066ff","0033ff","3366ff","3366cc","000066","000033","0000ff","000099","0033cc","0000cc","336699","0066cc","99ccff","6699ff","003366","6699cc","006699","3399cc","0099cc","66ccff","3399ff","003399","0099ff","33ccff","00ccff","99ffff","66ffff","33ffff","00ffff","00cccc","009999","669999","99cccc","ccffff","33cccc","66cccc","339999","336666","006666","003333","00ffcc","33ffcc","33cc99","00cc99","66ffcc","99ffcc","00ff99","339966","006633","336633","669966","66cc66","99ff99","66ff66","339933","99cc99","66ff99","33ff99","33cc66","00cc66","66cc99","009966","009933","33ff66","00ff66","ccffcc","ccff99","99ff66","99ff33","00ff33","33ff33","00cc33","33cc33","66ff33","00ff00","66cc33","006600","003300","009900","33ff00","66ff00","99ff00","66cc00","00cc00","33cc00","339900","99cc66","669933","99cc33","336600","669900","99cc00","ccff66","ccff33","ccff00","999900","cccc00","cccc33","333300","666600","999933","cccc66","666633","999966","cccc99","ffffcc","ffff99","ffff66","ffff33","ffff00","ffcc00","ffcc66","ffcc33","cc9933","996600","cc9900","ff9900","cc6600","993300","cc6633","663300","ff9966","ff6633","ff9933","ff6600","cc3300","996633","330000","663333","996666","cc9999","993333","cc6666","ffcccc","ff3333","cc3333","ff6666","660000","990000","cc0000","ff0000","ff3300","cc9966","ffcc99","ffffff","cccccc","999999","666666","333333","000000","000000","000000","000000","000000","000000","000000","000000","000000"];return b=a.extend({defaultColor:this.attr("defaultColor")||"#FFF",cellWidth:this.attr("cellWidth")||10,cellHeight:this.attr("cellHeight")||10,cellMargin:this.attr("cellMargin")||1,boxWidth:this.attr("boxWidth")||"115px",boxHeight:this.attr("boxHeight")||"20px",columns:this.attr("columns")||16,insert:this.attr("insert")||"after",colors:this.attr("colors")||f,displayColorCode:this.attr("displayColorCode")||!1,colorCodeAlign:this.attr("colorCodeAlign")||"center",colorCodeColor:this.attr("colorCodeColor")||!1,hideInput:this.attr("hideInput")||!0,onSelect:null,onCellEnter:null,onClose:null,livePreview:!1},b||{}),b.totalWidth=b.columns*(b.cellWidth+2*b.cellMargin),b.chooserCSS=a.extend({border:"1px solid #000",margin:"0 0 0 5px",width:b.totalWidth,height:b.totalHeight,top:0,left:b.boxWidth,position:"absolute","background-color":"#fff"},b.chooserCSS||{}),b.displayCSS=a.extend({"background-color":b.defaultColor,border:"1px solid #000",width:b.boxWidth,height:b.boxHeight,"line-height":b.boxHeight+"px",cursor:"pointer"},b.displayCSS||{}),b.inputCSS=a.extend({},b.inputCSS||{}),b.hideInput?this.hide():this.css(b.inputCSS),-1!=navigator.userAgent.indexOf("MSIE")&&(b.totalWidth+=2),b.totalHeight=Math.ceil(b.colors.length/b.columns)*(b.cellHeight+2*b.cellMargin),a.simpleColorOptions=b,this.each(d),a(".simpleColorDisplay").each(function(){a(this).click(function(a){a.stopPropagation()})}),this},a.fn.closeChooser=function(){return this.each(function(){a(this).data("container").find(".simpleColorChooser").hide()}),this},a.fn.setColor=function(b){return this.each(function(){var d=a(this).data("container").find(".simpleColorDisplay");c(d,b,options)}),this}}(jQuery);