Raphael.colorwheel=function(G,H,I){function v(){return{input:J,onchange:K,ondrag:L,color:M}}function J(a){r=null;m=a;$(a).keyup(function(){this.value.match(/^#([0-9A-F]){3}$|^#([0-9A-F]){6}$/img)&&(w(this.value),p(!0),s())});w(a.value);p(!0);return v()}function K(a){r=a;p(!1);return v()}function L(a,b){x=[a||function(){},b||function(){}];return v()}function y(a){var b;a.preventDefault();b=a.originalEvent.touches?a.originalEvent.touches[0]:a;a=b.pageX-(u.offset().left+e);b=b.pageY-(u.offset().top+
e);if(z==h)return A(a,b),p(),s(),!0;if(z==g)return B(a,b),p(),s(),!0}function C(a,b){a.preventDefault();$(document).on("mouseup touchend",D);$(document).on("mousemove touchmove",y);z=b;y(a);x[0](k)}function D(a){a.preventDefault();$(document).off("mouseup touchend",D);$(document).off("mousemove touchmove",y);x[1](k);s()}function N(){$([h.event.node,h.cursor[0].node]).on("mousedown touchstart",function(a){C(a,h)});$([g.b.node,g.cursor[0].node]).on("mousedown touchstart",function(a){C(a,g)})}function E(a){a=
d.set().push(d.circle(0,0,a).attr({"stroke-width":4,stroke:"#333"}),d.circle(0,0,a+2).attr({"stroke-width":1,stroke:"#FFF",opacity:0.5}));a[0].node.style.cursor="crosshair";return a}function B(a,b){a+=e;b+=e;a<c.x&&(a=c.x);a>c.x+c.l&&(a=c.x+c.l);b<c.y&&(b=c.y);b>c.y+c.l&&(b=c.y+c.l);g.cursor.attr({cx:a,cy:b}).transform("t0,0")}function M(a){a=w(a);p(!1);return a}function w(a){if(void 0===a)return k;a=d.rect(1,1,1,1).attr({fill:a});var b=d.raphael.rgb2hsb(a.attr("fill"));B(0-c.l/2+c.l*b.s,c.l/2-c.l*
b.b);A(360*b.h-90);a.remove();return v()}function p(a){var b=g.cursor.items[0].attr("cx"),d=1-(g.cursor.items[0].attr("cy")-c.y)/c.l,b=(b-c.x)/c.l,e=Raphael.rgb2hsb(g.h.attr("fill")).h;k=Raphael.hsb2rgb(e,b,d);m&&(b=k.hex,!0!==a&&(m.value=b),0.5>d?$(m).css("color","#FFF"):$(m).css("color","#000"),m.style.background=b)}function A(a){var b;2==arguments.length?(b=arguments[0],b=(0<b?0:180)+180*Math.atan((0-arguments[1])/(0-b))/Math.PI):b=arguments[0];var c=Math.cos(b*(Math.PI/180))*(e-f-q),d=Math.sin(b*
(Math.PI/180))*(e-f-q);h.cursor.attr({cx:c+e,cy:d+e}).transform("t0,0");b=Raphael.getRGB("hsb("+(b+90)/360+",1,1)").hex;g.h.attr("fill",b)}function s(){({}).toString.call(r).match(/function/i)&&r(k)}var d,k,l,F=I||60,g={},h={},f,z,m,e,u,r,x=[function(){},function(){}],q=2,c;return function(a,b){l=b;f=l/20;e=l/2;u=$(a);d=Raphael(u[0],l,l);d.safari();if(!c){var t=l-4*f;c={x:t/6+2*f+q,y:t/6+2*f+q,l:2*t/3-2*q}}box=[c.x,c.y,c.l,c.l];g.h=d.rect.apply(d,box).attr({stroke:"#EEE",gradient:"0-#FFF-#000",opacity:1});
g.s=d.rect.apply(d,box).attr({stroke:null,gradient:"0-#FFF-#FFF",opacity:0});g.b=d.rect.apply(d,box).attr({stroke:null,gradient:"90-#000-#FFF",opacity:0});g.b.node.style.cursor="crosshair";t="M -@W 0 L @W 0 L @W @H L -@W @H z".replace(/@H/img,2*f).replace(/@W/img,f);t=d.path(t).attr({stroke:"rgba(0,0,0,0)"}).transform("t"+l/2+","+q);h.hues=d.set();for(n=0;n<F;n++){var m=n,p=F,k=t.clone(),r=l/2,s=f;k.transform("t"+r+","+(r-s)+"r"+360/p*m+"t0,-"+(r-s-q)+"");k.attr({"stroke-width":0,fill:"hsb("+m*(1/
p)+", 1, 0.85)"});h.hues.push(k)}h.event=d.circle(e,e,e-f-q).attr({"stroke-width":2*f,opacity:0.01});h.outline=d.circle(e,e,e-f-q).attr({stroke:"#000","stroke-width":2*f+3,opacity:0.1});h.outline.toBack();h.event.node.style.cursor="crosshair";h.cursor=E(f);g.cursor=E(0.5*f);N();u.css({height:l+"px",width:l+"px"});$(u).css({unselectable:"on","-moz-user-select":"none","-webkit-user-select":"none"});return v()}(G,H)};