drawCircle "+(+(new Date())-j)+"ms")};e.drawMask=function(){var p=+(new Date());var s=e.square*2,h=e.square;function g(D,B,t){var w=1/D,v=1/B;for(var A=0;A<=B;++A){var u=1-A*v;for(var E=0;E<=D;++E){var F=1-E*w;var C=1-2*Math.min(u*F,(1-u)*F);var z=(C>0)?((2*u-1+C)*0.5/C):0;t(E,A,z,C)}}}if(e.ctxMask.getImageData){var m=Math.floor(s/2);var k=document.createElement("canvas");k.width=k.height=m+1;var q=k.getContext("2d");var j=q.getImageData(0,0,m+1,m+1);var l=0;g(m,m,function(t,w,v,u){j.data[l++]=j.data[l++]=j.data[l++]=v*255;j.data[l++]=u*255});q.putImageData(j,0,0);e.ctxMask.drawImage(k,0,0,m+1,m+1,-h,-h,h*2,h*2)}else{if(!b.browser.msie){var m=Math.floor(s/2);g(m,m,function(t,w,v,u){v=Math.round(v*255);e.ctxMask.fillStyle="rgba("+v+", "+v+", "+v+", "+u+")";e.ctxMask.fillRect(t*2-h-1,w*2-h-1,2,2)})}else{var r,f,o=6;var n=Math.floor(s/o);g(n,6,function(B,w,u,A){if(B==0){r=f;f=[]}u=Math.round(u*255);A=Math.round(A*255);if(w>0){var E=r[B][0],t=r[B][1],D=e.packDX(E,t),C=e.packDX(u,A),z=Math.round(e.mid+((w-1)*0.333-1)*h),v=Math.round(e.mid+(w*0.333-1)*h);b("
").css({position:"absolute",filter:"progid:DXImageTransform.Microsoft.Gradient(StartColorStr="+D+", EndColorStr="+C+", GradientType=0)",top:z,height:v-z,left:e.mid+(B*o-h-1),width:o-(B==n?Math.round(o/2):0)}).appendTo(e.cnvMask)}f.push([u,A])})}}a&&b("body").append("
drawMask "+(+(new Date())-p)+"ms")};e.drawMarkers=function(){var p=d.width,j=Math.ceil(e.markerSize/4),f=e.markerSize-j+1;var k=e.hsl[0]*6.28,h=Math.sin(k)*e.radius,s=-Math.cos(k)*e.radius,g=2*e.square*(0.5-e.hsl[1]),q=2*e.square*(0.5-e.hsl[2]),m=e.invert?"#fff":"#000",l=e.invert?"#000":"#fff";var n=[{x:h,y:s,r:f,c:"#000",lw:j+1},{x:h,y:s,r:e.markerSize,c:"#fff",lw:j},{x:g,y:q,r:f,c:l,lw:j+1},{x:g,y:q,r:e.markerSize,c:m,lw:j},];e.ctxOverlay.clearRect(-e.mid,-e.mid,p,p);for(i in n){var o=n[i];e.ctxOverlay.lineWidth=o.lw;e.ctxOverlay.strokeStyle=o.c;e.ctxOverlay.beginPath();e.ctxOverlay.arc(o.x,o.y,o.r,0,Math.PI*2,true);e.ctxOverlay.stroke()}};e.updateDisplay=function(){e.invert=(e.rgb[0]*0.3+e.rgb[1]*0.59+e.rgb[2]*0.11)<=0.6;e.solidFill.css("backgroundColor",e.pack(e.HSLToRGB([e.hsl[0],1,0.5])));e.drawMarkers();if(typeof e.callback=="object"){b(e.callback).css({backgroundColor:e.color,color:e.invert?"#fff":"#000"});b(e.callback).each(function(){if((typeof this.value=="string")&&this.value!=e.color){this.value=e.color}})}else{if(typeof e.callback=="function"){e.callback.call(e,e.color)}}};e.widgetCoords=function(f){return{x:f.pageX-e.offset.left-e.mid,y:f.pageY-e.offset.top-e.mid}};e.mousedown=function(f){if(!b._farbtastic.dragging){b(document).bind("mousemove",e.mousemove).bind("mouseup",e.mouseup);b._farbtastic.dragging=true}e.offset=b(c).offset();var g=e.widgetCoords(f);e.circleDrag=Math.max(Math.abs(g.x),Math.abs(g.y))>(e.square+2);e.mousemove(f);return false};e.mousemove=function(j){var k=e.widgetCoords(j);if(e.circleDrag){var h=Math.atan2(k.x,-k.y)/6.28;e.setHSL([(h+1)%1,e.hsl[1],e.hsl[2]])}else{var g=Math.max(0,Math.min(1,-(k.x/e.square/2)+0.5));var f=Math.max(0,Math.min(1,-(k.y/e.square/2)+0.5));e.setHSL([e.hsl[0],g,f])}return false};e.mouseup=function(){b(document).unbind("mousemove",e.mousemove);b(document).unbind("mouseup",e.mouseup);b._farbtastic.dragging=false};e.dec2hex=function(f){return(f<16?"0":"")+f.toString(16)};e.packDX=function(g,f){return"#"+e.dec2hex(f)+e.dec2hex(g)+e.dec2hex(g)+e.dec2hex(g)};e.pack=function(h){var k=Math.round(h[0]*255);var j=Math.round(h[1]*255);var f=Math.round(h[2]*255);return"#"+e.dec2hex(k)+e.dec2hex(j)+e.dec2hex(f)};e.unpack=function(g){if(g.length==7){function f(h){return parseInt(g.substring(h,h+2),16)/255}return[f(1),f(3),f(5)]}else{if(g.length==4){function f(h){return parseInt(g.substring(h,h+1),16)/15}return[f(1),f(2),f(3)]}}};e.HSLToRGB=function(o){var q,p,f,m,n;var k=o[0],t=o[1],j=o[2];p=(j<=0.5)?j*(t+1):j+t-j*t;q=j*2-p;return[this.hueToRGB(q,p,k+0.33333),this.hueToRGB(q,p,k),this.hueToRGB(q,p,k-0.33333)]};e.hueToRGB=function(g,f,j){j=(j+1)%1;if(j*6<1){return g+(f-g)*j*6}if(j*2<1){return f}if(j*3<2){return g+(f-g)*(0.66666-j)*6}return g};e.RGBToHSL=function(o){var f=o[0],n=o[1],p=o[2],k=Math.min(f,n,p),q=Math.max(f,n,p),t=q-k,m=0,u=0,j=(k+q)/2;if(j>0&&j<1){u=t/(j<0.5?(2*j):(2-2*j))}if(t>0){if(q==f&&q!=n){m+=(n-p)/t}if(q==n&&q!=p){m+=(2+(p-f)/t)}if(q==p&&q!=f){m+=(4+(f-n)/t)}m/=6}return[m,u,j]};if(!d.callback){d={callback:d}}d=b.extend({width:300,wheelWidth:(d.width||300)/10,callback:null,color:"#808080"},d);e.initWidget();b("canvas.farbtastic-overlay",c).mousedown(e.mousedown);if(d.callback){e.linkTo(d.callback)}e.setColor("#808080");e.setColor(d.color)}})(jQuery);