(function(n){n.fn.wheelColorPicker=function(){var u=this,i,f,r;if(arguments.length>0)var e=[].shift,i=e.apply(arguments),f=typeof i=="string"?i.charAt(0).toUpperCase()+i.slice(1):i;else i=undefined,f=undefined;return r=arguments,this.each(function(){var e=n(this).data("jQWCP.instance"),s,o;if((e==undefined||e==null)&&(s={},typeof i=="object"&&(s=i),e=new t.ColorPicker(this,s),n(this).data("jQWCP.instance",e)),i!==undefined&&typeof i!="object")if(typeof e[i]=="function"){if(o=e[i].apply(e,r),o!==e)return u=o,!1}else if(typeof e["set"+f]=="function"&&r.length>0){if(o=e["set"+f].apply(e,r),o!==e)return u=o,!1}else if(typeof e["get"+f]=="function"){if(o=e["get"+f].apply(e,r),o!==e)return u=o,!1}else if(e.options[i]!==undefined&&r.length>0)e.options[i]=r[0];else{if(e.options[i]!==undefined)return u=e.options[i],!1;n.error("Method/option named "+i+" does not exist on jQuery.wheelColorPicker")}}),u};var t=n.fn.wheelColorPicker;t.defaults={format:"hex",preview:!1,live:!0,userinput:!0,validate:!1,autoResize:!0,preserveWheel:null,cssClass:"",layout:"popup",animDuration:200,quality:1,sliders:null,rounding:2,mobile:!0,mobileWidth:480,hideKeyboard:!1,htmlOptions:!0,snap:!1,snapTolerance:.05};t.BUG_RELATIVE_PAGE_ORIGIN=!1;t.ORIGIN={left:0,top:0};t.colorToStr=function(n,t){var i="",r,u,f;switch(t){case"css":i="#";case"hex":r=Math.round(n.r*255).toString(16);r.length==1&&(r="0"+r);u=Math.round(n.g*255).toString(16);u.length==1&&(u="0"+u);f=Math.round(n.b*255).toString(16);f.length==1&&(f="0"+f);i+=r+u+f;break;case"rgb":i="rgb("+Math.round(n.r*255)+","+Math.round(n.g*255)+","+Math.round(n.b*255)+")";break;case"rgb%":i="rgb("+n.r*100+"%,"+n.g*100+"%,"+n.b*100+"%)";break;case"rgba":i="rgba("+Math.round(n.r*255)+","+Math.round(n.g*255)+","+Math.round(n.b*255)+","+n.a+")";break;case"rgba%":i="rgba("+n.r*100+"%,"+n.g*100+"%,"+n.b*100+"%,"+n.a*100+"%)";break;case"hsv":i="hsv("+n.h*360+","+n.s+","+n.v+")";break;case"hsv%":i="hsv("+n.h*100+"%,"+n.s*100+"%,"+n.v*100+"%)";break;case"hsva":i="hsva("+n.h*360+","+n.s+","+n.v+","+n.a+")";break;case"hsva%":i="hsva("+n.h*100+"%,"+n.s*100+"%,"+n.v*100+"%,"+n.a*100+"%)";break;case"hsb":i="hsb("+n.h+","+n.s+","+n.v+")";break;case"hsb%":i="hsb("+n.h*100+"%,"+n.s*100+"%,"+n.v*100+"%)";break;case"hsba":i="hsba("+n.h+","+n.s+","+n.v+","+n.a+")";break;case"hsba%":i="hsba("+n.h*100+"%,"+n.s*100+"%,"+n.v*100+"%,"+n.a*100+"%)"}return i};t.strToColor=function(n){var i={a:1},t,r;if(n.match(/^#[0-9a-f]{6}$/i)!=null){if(isNaN(i.r=parseInt(n.substr(1,2),16)/255)||isNaN(i.g=parseInt(n.substr(3,2),16)/255)||isNaN(i.b=parseInt(n.substr(5,2),16)/255))return!1}else if(n.match(/^[0-9a-f]{6}$/i)!=null){if(isNaN(i.r=parseInt(n.substr(0,2),16)/255)||isNaN(i.g=parseInt(n.substr(2,2),16)/255)||isNaN(i.b=parseInt(n.substr(4,2),16)/255))return!1}else if(n.match(/^rgba\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)!=null||n.match(/^rgb\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)!=null){if(r=n.match(/a/i)!=null?!0:!1,t=n.substring(n.indexOf("(")+1,n.indexOf(",")),t.charAt(t.length-1)=="%"){if(isNaN(i.r=parseFloat(t)/100))return!1}else if(isNaN(i.r=parseInt(t)/255))return!1;if(t=n.substring(n.indexOf(",")+1,n.indexOf(",",n.indexOf(",")+1)),t.charAt(t.length-1)=="%"){if(isNaN(i.g=parseFloat(t)/100))return!1}else if(isNaN(i.g=parseInt(t)/255))return!1;if(t=r?n.substring(n.indexOf(",",n.indexOf(",")+1)+1,n.lastIndexOf(",")):n.substring(n.lastIndexOf(",")+1,n.lastIndexOf(")")),t.charAt(t.length-1)=="%"){if(isNaN(i.b=parseFloat(t)/100))return!1}else if(isNaN(i.b=parseInt(t)/255))return!1;if(r)if(t=n.substring(n.lastIndexOf(",")+1,n.lastIndexOf(")")),t.charAt(t.length-1)=="%"){if(isNaN(i.a=parseFloat(t)/100))return!1}else if(isNaN(i.a=parseFloat(t)))return!1}else if(n.match(/^hsva\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)!=null||n.match(/^hsv\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)!=null||n.match(/^hsba\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)!=null||n.match(/^hsb\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)!=null){if(r=n.match(/a/i)!=null?!0:!1,t=n.substring(n.indexOf("(")+1,n.indexOf(",")),t.charAt(t.length-1)=="%"){if(isNaN(i.h=parseFloat(t)/100))return!1}else if(isNaN(i.h=parseFloat(t)/360))return!1;if(t=n.substring(n.indexOf(",")+1,n.indexOf(",",n.indexOf(",")+1)),t.charAt(t.length-1)=="%"){if(isNaN(i.s=parseFloat(t)/100))return!1}else if(isNaN(i.s=parseFloat(t)))return!1;if(t=r?n.substring(n.indexOf(",",n.indexOf(",")+1)+1,n.lastIndexOf(",")):n.substring(n.lastIndexOf(",")+1,n.lastIndexOf(")")),t.charAt(t.length-1)=="%"){if(isNaN(i.v=parseFloat(t)/100))return!1}else if(isNaN(i.v=parseFloat(t)))return!1;if(r)if(t=n.substring(n.lastIndexOf(",")+1,n.lastIndexOf(")")),t.charAt(t.length-1)=="%"){if(isNaN(i.a=parseFloat(t)/100))return!1}else if(isNaN(i.a=parseFloat(t)))return!1}else return!1;return i};t.hsvToRgb=function(n,t,i){var r=n<=1/6||n>=5/6?1:n<1/3?1-(n-1/6)*6:n>4/6?(n-4/6)*6:0,u=n>=1/6&&n<=3/6?1:n<1/6?n*6:n<4/6?1-(n-3/6)*6:0,f=n>=3/6&&n<=5/6?1:n>2/6&&n<3/6?(n-2/6)*6:n>5/6?1-(n-5/6)*6:0,e=(r+(1-r)*(1-t))*i,o=(u+(1-u)*(1-t))*i,s=(f+(1-f)*(1-t))*i;return{r:e,g:o,b:s}};t.rgbToHsv=function(n,t,i){var f,e,o,r=Math.max(n,t,i),s=Math.min(n,t,i),u=r-s;return e=r!=0?u/r:0,f=u==0?0:n==r?(6+(t-i)/u)%6:t==r?2+(i-n)/u:i==r?4+(n-t)/u:0,f=f/6,o=r,{h:f,s:e,v:o}};t.ColorPicker=function(i,r){this.input=i;this.color={h:0,s:0,v:1,r:1,g:1,b:1,a:1};this.setValue(this.input.value);this.options=n.extend(!0,{},t.defaults);this.setOptions(r);this.options.sliders==null&&(this.options.sliders="wvp"+(this.options.format.indexOf("a")>=0?"a":""));this.init()};t.ColorPicker.widget=null;t.ColorPicker.overlay=null;t.ColorPicker.init=function(){var i,r;if(t.ColorPicker.init.hasInit!=!0){t.ColorPicker.init.hasInit=!0;i=n('<div class="jQWCP-overlay" style="display: none;"><\/div>');i.on("click",t.Handler.overlay_click);t.ColorPicker.overlay=i.get(0);n("body").append(i);r=t.ColorPicker.getWheelDataUrl(200);n("head").append('<style type="text/css">.jQWCP-wWheel {background: url('+r+") no-repeat center center;}<\/style>");n("html").on("mouseup.wheelColorPicker",t.Handler.html_mouseup);n("html").on("touchend.wheelColorPicker",t.Handler.html_mouseup);n("html").on("mousemove.wheelColorPicker",t.Handler.html_mousemove);n("html").on("touchmove.wheelColorPicker",t.Handler.html_mousemove);n(window).on("resize.wheelColorPicker",t.Handler.window_resize)}};t.ColorPicker.createWidget=function(){var i=n("<div class='jQWCP-wWidget'><div class='jQWCP-wWheel'><div class='jQWCP-wWheelOverlay'><\/div><span class='jQWCP-wWheelCursor'><\/span><\/div><div class='jQWCP-wHue jQWCP-slider-wrapper'><canvas class='jQWCP-wHueSlider jQWCP-slider' width='1' height='50' title='Hue'><\/canvas><span class='jQWCP-wHueCursor jQWCP-scursor'><\/span><\/div><div class='jQWCP-wSat jQWCP-slider-wrapper'><canvas class='jQWCP-wSatSlider jQWCP-slider' width='1' height='50' title='Saturation'><\/canvas><span class='jQWCP-wSatCursor jQWCP-scursor'><\/span><\/div><div class='jQWCP-wVal jQWCP-slider-wrapper'><canvas class='jQWCP-wValSlider jQWCP-slider' width='1' height='50' title='Value'><\/canvas><span class='jQWCP-wValCursor jQWCP-scursor'><\/span><\/div><div class='jQWCP-wRed jQWCP-slider-wrapper'><canvas class='jQWCP-wRedSlider jQWCP-slider' width='1' height='50' title='Red'><\/canvas><span class='jQWCP-wRedCursor jQWCP-scursor'><\/span><\/div><div class='jQWCP-wGreen jQWCP-slider-wrapper'><canvas class='jQWCP-wGreenSlider jQWCP-slider' width='1' height='50' title='Green'><\/canvas><span class='jQWCP-wGreenCursor jQWCP-scursor'><\/span><\/div><div class='jQWCP-wBlue jQWCP-slider-wrapper'><canvas class='jQWCP-wBlueSlider jQWCP-slider' width='1' height='50' title='Blue'><\/canvas><span class='jQWCP-wBlueCursor jQWCP-scursor'><\/span><\/div><div class='jQWCP-wAlpha jQWCP-slider-wrapper'><canvas class='jQWCP-wAlphaSlider jQWCP-slider' width='1' height='50' title='Alpha'><\/canvas><span class='jQWCP-wAlphaCursor jQWCP-scursor'><\/span><\/div><div class='jQWCP-wPreview'><canvas class='jQWCP-wPreviewBox' width='1' height='1' title='Selected Color'><\/canvas><\/div><\/div>");i.find(".jQWCP-wWheel, .jQWCP-slider-wrapper, .jQWCP-scursor, .jQWCP-slider").attr("unselectable","on").css("-moz-user-select","none").css("-webkit-user-select","none").css("user-select","none").css("-webkit-touch-callout","none");i.on("contextmenu.wheelColorPicker",function(){return!1});i.on("mousedown.wheelColorPicker",".jQWCP-wWheel",t.Handler.wheel_mousedown);i.on("touchstart.wheelColorPicker",".jQWCP-wWheel",t.Handler.wheel_mousedown);i.on("mousedown.wheelColorPicker",".jQWCP-wWheelCursor",t.Handler.wheelCursor_mousedown);i.on("touchstart.wheelColorPicker",".jQWCP-wWheelCursor",t.Handler.wheelCursor_mousedown);i.on("mousedown.wheelColorPicker",".jQWCP-slider",t.Handler.slider_mousedown);i.on("touchstart.wheelColorPicker",".jQWCP-slider",t.Handler.slider_mousedown);i.on("mousedown.wheelColorPicker",".jQWCP-scursor",t.Handler.sliderCursor_mousedown);i.on("touchstart.wheelColorPicker",".jQWCP-scursor",t.Handler.sliderCursor_mousedown);return i.get(0)};t.ColorPicker.getWheelDataUrl=function(n){var e=n/2,r=e,f=document.createElement("canvas"),o,u,i,s;for(f.width=n,f.height=n,o=f.getContext("2d"),u=0;u<n;u++)for(i=0;i<n;i++)if(s=Math.sqrt(Math.pow(i-r,2)+Math.pow(u-r,2)),!(s>e+2)){var t=((i-r==0?u<r?90:270:Math.atan((r-u)/(i-r))/Math.PI*180)+(i<r?180:0)+360)%360,h=s/e,c=(Math.abs(t+360)+60)%360<120?1:t>240?(120-Math.abs(t-360))/60:t<120?(120-t)/60:0,l=Math.abs(t-120)<60?1:Math.abs(t-120)<120?(120-Math.abs(t-120))/60:0,a=Math.abs(t-240)<60?1:Math.abs(t-240)<120?(120-Math.abs(t-240))/60:0,v=Math.round((c+(1-c)*(1-h))*255),y=Math.round((l+(1-l)*(1-h))*255),p=Math.round((a+(1-a)*(1-h))*255);o.fillStyle="rgb("+v+","+y+","+p+")";o.fillRect(i,u,1,1)}return f.toDataURL()};t.ColorPicker.prototype.options=null;t.ColorPicker.prototype.input=null;t.ColorPicker.prototype.widget=null;t.ColorPicker.prototype.color=null;t.ColorPicker.prototype.lastValue=null;t.ColorPicker.prototype.setOptions=function(i){var r,u;if(i=n.extend(!0,{},i),this.options.htmlOptions)for(r in t.defaults)this.input.hasAttribute("data-wcp-"+r)&&i[r]===undefined&&(i[r]=this.input.getAttribute("data-wcp-"+r),i[r]=="true"?i[r]=!0:i[r]=="false"&&(i[r]=!1));for(r in i)this.options[r]!==undefined&&(u=r.charAt(0).toUpperCase()+r.slice(1),typeof this["set"+u]=="function"?this["set"+u](i[r]):this.options[r]=i[r]);return this};t.ColorPicker.prototype.init=function(){if(t.ColorPicker.init(),this.hasInit!=!0){this.hasInit=!0;var u=this,r=n(this.input),i=null;if(this.options.layout=="block"){this.widget=t.ColorPicker.createWidget();i=n(this.widget);i.data("jQWCP.instance",this);i.insertAfter(this.input);r.css("display")=="inline"?i.css("display","inline-block"):i.css("display",r.css("display"));i.append(this.input);r.hide();r.attr("tabindex")!=undefined?i.attr("tabindex",r.attr("tabindex")):i.attr("tabindex",0);this.refreshWidget();this.redrawSliders(!0);this.updateSliders();i.on("focus.wheelColorPicker",t.Handler.widget_focus_block);i.on("blur.wheelColorPicker",t.Handler.widget_blur_block)}else{if(t.ColorPicker.widget==null){t.ColorPicker.widget=t.ColorPicker.createWidget();i=n(t.ColorPicker.widget);i.hide();n("body").append(i);i.on("mousedown.wheelColorPicker",t.Handler.widget_mousedown_popup)}this.widget=t.ColorPicker.widget;r.on("focus.wheelColorPicker",t.Handler.input_focus_popup);r.on("blur.wheelColorPicker",t.Handler.input_blur_popup)}r.on("keyup.wheelColorPicker",t.Handler.input_change);typeof this.options.color=="object"?(this.setColor(this.options.color),this.options.color=undefined):typeof this.options.color=="string"&&(this.setValue(this.options.color),this.options.color=undefined);this.options.userinput?r.removeAttr("readonly"):r.attr("readonly",!0)}};t.ColorPicker.prototype.destroy=function(){var i=n(this.widget),t=n(this.input);this.options.layout=="block"&&(i.before(this.input),i.remove(),t.show());t.off("focus.wheelColorPicker");t.off("blur.wheelColorPicker");t.off("keyup.wheelColorPicker");t.off("change.wheelColorPicker");t.data("jQWCP.instance",null);delete this};t.ColorPicker.prototype.refreshWidget=function(){var t=n(this.widget),r=this.options,s=!1,h,i,c,e,o,f,u,l,a;t.attr("class","jQWCP-wWidget");r.layout=="block"&&t.addClass("jQWCP-block");t.addClass(r.cssClass);window.innerWidth<=r.mobileWidth&&r.layout!="block"&&(s=!0,t.addClass("jQWCP-mobile"));t.find(".jQWCP-wWheel, .jQWCP-slider-wrapper, .jQWCP-wPreview").hide().addClass("hidden");for(h in r.sliders){i=null;switch(this.options.sliders[h]){case"w":i=t.find(".jQWCP-wWheel");break;case"h":i=t.find(".jQWCP-wHue");break;case"s":i=t.find(".jQWCP-wSat");break;case"v":i=t.find(".jQWCP-wVal");break;case"r":i=t.find(".jQWCP-wRed");break;case"g":i=t.find(".jQWCP-wGreen");break;case"b":i=t.find(".jQWCP-wBlue");break;case"a":i=t.find(".jQWCP-wAlpha");break;case"p":i=t.find(".jQWCP-wPreview")}i!=null&&(i.appendTo(this.widget),i.show().removeClass("hidden"))}return c=r.quality*50,t.find(".jQWCP-slider").attr("height",c),e=t.find(".jQWCP-wWheel, .jQWCP-slider-wrapper, .jQWCP-wPreview").not(".hidden"),r.autoResize&&!s?(o=0,e.css({width:"",height:""}),e.each(function(t,i){var r=n(i);o+=parseFloat(r.css("margin-left").replace("px",""))+parseFloat(r.css("margin-right").replace("px",""))+r.outerWidth()}),t.css({width:o+"px"})):(t.css({width:""}),f=t.find(".jQWCP-wWheel").not(".hidden"),u=t.find(".jQWCP-slider-wrapper, .jQWCP-wPreview").not(".hidden"),f.css({height:t.height()+"px",width:t.height()}),l=f.length>0?t.width()-f.outerWidth()-parseFloat(f.css("margin-left").replace("px",""))-parseFloat(f.css("margin-right").replace("px","")):t.width(),u.length>0&&(a=parseFloat(u.css("margin-left").replace("px",""))+parseFloat(u.css("margin-right").replace("px","")),u.css({height:t.height()+"px",width:(l-(u.length-1)*a)/u.length+"px"}))),this};t.ColorPicker.prototype.redrawSliders=function(t){var r,ot,y,st,v,p,ht,w,b,ct,k,d,lt,g,nt,at,tt,e,vt,u,it,rt,yt,f,ut,ft;if(this.widget==null||(r=n(this.widget),typeof arguments[0]=="string"&&(t=arguments[1]),this!=r.data("jQWCP.instance")))return this;var pt=this.options,l=this.color,o=1,i=pt.quality*50,wt=1,s=0,h=0,c=0,et=0,bt=0,a=1;return(pt.live&&(wt=l.a,s=Math.round(l.r*255),h=Math.round(l.g*255),c=Math.round(l.b*255),et=l.h,bt=l.s,a=l.v),ot=r.find(".jQWCP-wPreviewBox"),ot.hasClass("hidden")||(y=ot.get(0).getContext("2d"),y.fillStyle="rgba("+s+","+h+","+c+","+wt+")",y.clearRect(0,0,1,1),y.fillRect(0,0,1,1)),!this.options.live&&!t)?this:(st=r.find(".jQWCP-wAlphaSlider"),(!st.hasClass("hidden")||t)&&(v=st.get(0).getContext("2d"),p=v.createLinearGradient(0,0,0,i),p.addColorStop(0,"rgba("+s+","+h+","+c+",1)"),p.addColorStop(1,"rgba("+s+","+h+","+c+",0)"),v.fillStyle=p,v.clearRect(0,0,o,i),v.fillRect(0,0,o,i)),ht=r.find(".jQWCP-wRedSlider"),(!ht.hasClass("hidden")||t)&&(w=ht.get(0).getContext("2d"),b=w.createLinearGradient(0,0,0,i),b.addColorStop(0,"rgb(255,"+h+","+c+")"),b.addColorStop(1,"rgb(0,"+h+","+c+")"),w.fillStyle=b,w.fillRect(0,0,o,i)),ct=r.find(".jQWCP-wGreenSlider"),(!ct.hasClass("hidden")||t)&&(k=ct.get(0).getContext("2d"),d=k.createLinearGradient(0,0,0,i),d.addColorStop(0,"rgb("+s+",255,"+c+")"),d.addColorStop(1,"rgb("+s+",0,"+c+")"),k.fillStyle=d,k.fillRect(0,0,o,i)),lt=r.find(".jQWCP-wBlueSlider"),(!lt.hasClass("hidden")||t)&&(g=lt.get(0).getContext("2d"),nt=g.createLinearGradient(0,0,0,i),nt.addColorStop(0,"rgb("+s+","+h+",255)"),nt.addColorStop(1,"rgb("+s+","+h+",0)"),g.fillStyle=nt,g.fillRect(0,0,o,i)),at=r.find(".jQWCP-wHueSlider"),(!at.hasClass("hidden")||t)&&(tt=at.get(0).getContext("2d"),e=tt.createLinearGradient(0,0,0,i),e.addColorStop(0,"#f00"),e.addColorStop(.166666667,"#ff0"),e.addColorStop(.333333333,"#0f0"),e.addColorStop(.5,"#0ff"),e.addColorStop(.666666667,"#00f"),e.addColorStop(.833333333,"#f0f"),e.addColorStop(1,"#f00"),tt.fillStyle=e,tt.fillRect(0,0,o,i)),vt=r.find(".jQWCP-wSatSlider"),(!vt.hasClass("hidden")||t)&&(u=n.fn.wheelColorPicker.hsvToRgb(et,1,a),u.r=Math.round(u.r*255),u.g=Math.round(u.g*255),u.b=Math.round(u.b*255),it=vt.get(0).getContext("2d"),rt=it.createLinearGradient(0,0,0,i),rt.addColorStop(0,"rgb("+u.r+","+u.g+","+u.b+")"),rt.addColorStop(1,"rgb("+Math.round(a*255)+","+Math.round(a*255)+","+Math.round(a*255)+")"),it.fillStyle=rt,it.fillRect(0,0,o,i)),yt=r.find(".jQWCP-wValSlider"),(!yt.hasClass("hidden")||t)&&(f=n.fn.wheelColorPicker.hsvToRgb(et,bt,1),f.r=Math.round(f.r*255),f.g=Math.round(f.g*255),f.b=Math.round(f.b*255),ut=yt.get(0).getContext("2d"),ft=ut.createLinearGradient(0,0,0,i),ft.addColorStop(0,"rgb("+f.r+","+f.g+","+f.b+")"),ft.addColorStop(1,"#000"),ut.fillStyle=ft,ut.fillRect(0,0,o,i)),this)};t.ColorPicker.prototype.updateSliders=function(){var t,i,r,u,v,f,y,e,p,o,w,s,b,h,k,c,d;if(this.widget==null||(t=n(this.widget),i=this.color,this!=t.data("jQWCP.instance")))return this;if(r=t.find(".jQWCP-wWheel"),!r.hasClass("hidden")){var l=t.find(".jQWCP-wWheelCursor"),a=t.find(".jQWCP-wWheelOverlay"),g=Math.cos(2*Math.PI*i.h)*i.s,nt=Math.sin(2*Math.PI*i.h)*i.s,tt=r.width()/2,it=r.height()/2;l.css("left",tt+g*r.width()/2+"px");l.css("top",it-nt*r.height()/2+"px");this.options.preserveWheel==!0||this.options.preserveWheel==null&&this.options.live==!1?a.css("opacity",0):a.css("opacity",1-(i.v<.2?.2:i.v))}return u=t.find(".jQWCP-wHueSlider"),u.hasClass("hidden")||(v=t.find(".jQWCP-wHueCursor"),v.css("top",i.h*u.height()+"px")),f=t.find(".jQWCP-wSatSlider"),f.hasClass("hidden")||(y=t.find(".jQWCP-wSatCursor"),y.css("top",(1-i.s)*f.height()+"px")),e=t.find(".jQWCP-wValSlider"),e.hasClass("hidden")||(p=t.find(".jQWCP-wValCursor"),p.css("top",(1-i.v)*e.height()+"px")),o=t.find(".jQWCP-wRedSlider"),o.hasClass("hidden")||(w=t.find(".jQWCP-wRedCursor"),w.css("top",(1-i.r)*o.height()+"px")),s=t.find(".jQWCP-wGreenSlider"),s.hasClass("hidden")||(b=t.find(".jQWCP-wGreenCursor"),b.css("top",(1-i.g)*s.height()+"px")),h=t.find(".jQWCP-wBlueSlider"),h.hasClass("hidden")||(k=t.find(".jQWCP-wBlueCursor"),k.css("top",(1-i.b)*h.height()+"px")),c=t.find(".jQWCP-wAlphaSlider"),c.hasClass("hidden")||(d=t.find(".jQWCP-wAlphaCursor"),d.css("top",(1-i.a)*c.height()+"px")),this};t.ColorPicker.prototype.updateSelection=function(){return this.redrawSliders(),this.updateSliders(),this};t.ColorPicker.prototype.updateInput=function(){if(this.widget==null)return this;var i=n(this.input);this.input.value=this.getValue();this.options.preview&&(i.css("background",t.colorToStr(this.color,"rgba")),this.color.v>.5?i.css("color","black"):i.css("color","white"))};t.ColorPicker.prototype.updateActiveControl=function(i){var r=n(n("body").data("jQWCP.activeControl")),c,s,h,l,e,u;if(r.length!=0){var a=n(this.input),o=this.options,f=this.color;if(i.pageX==undefined&&i.originalEvent.touches.length>0&&(i.pageX=i.originalEvent.touches[0].pageX,i.pageY=i.originalEvent.touches[0].pageY),r.hasClass("jQWCP-wWheel")){var l=r.find(".jQWCP-wWheelCursor"),v=r.find(".jQWCP-wWheelOverlay"),c=(i.pageX-r.offset().left-r.width()/2)/(r.width()/2),e=-(i.pageY-r.offset().top-r.height()/2)/(r.height()/2);t.BUG_RELATIVE_PAGE_ORIGIN&&(c=(i.pageX-(r.get(0).getBoundingClientRect().left-t.ORIGIN.left)-r.width()/2)/(r.width()/2),e=-(i.pageY-(r.get(0).getBoundingClientRect().top-t.ORIGIN.top)-r.height()/2)/(r.height()/2));s=Math.sqrt(Math.pow(c,2)+Math.pow(e,2));s>1&&(s=1);o.snap&&s<o.snapTolerance&&(s=0);h=c==0&&e==0?0:Math.atan(e/c)/(2*Math.PI);h<0&&(h+=.5);e<0&&(h+=.5);this.setHsv(h,s,f.v)}else r.hasClass("jQWCP-slider-wrapper")&&(l=r.find(".jQWCP-scursor"),e=(i.pageY-r.offset().top)/r.height(),t.BUG_RELATIVE_PAGE_ORIGIN&&(e=(i.pageY-(r.get(0).getBoundingClientRect().top-t.ORIGIN.top))/r.height()),u=e<0?0:e>1?1:e,o.snap&&u<o.snapTolerance?u=0:o.snap&&u>1-o.snapTolerance&&(u=1),o.snap&&u>.5-o.snapTolerance&&u<.5+o.snapTolerance&&(u=.5),l.css("top",u*r.height()+"px"),r.hasClass("jQWCP-wRed")&&this.setRgb(1-u,f.g,f.b),r.hasClass("jQWCP-wGreen")&&this.setRgb(f.r,1-u,f.b),r.hasClass("jQWCP-wBlue")&&this.setRgb(f.r,f.g,1-u),r.hasClass("jQWCP-wHue")&&this.setHsv(u,f.s,f.v),r.hasClass("jQWCP-wSat")&&this.setHsv(f.h,1-u,f.v),r.hasClass("jQWCP-wVal")&&this.setHsv(f.h,f.s,1-u),r.hasClass("jQWCP-wAlpha")&&this.setAlpha(1-u))}};t.ColorPicker.prototype.getColor=function(){return this.color};t.ColorPicker.prototype.getValue=function(n){var i=this.options;return n==null&&(n=i.format),i.rounding>=0&&(this.color.a=Math.round(this.color.a*Math.pow(10,i.rounding))/Math.pow(10,i.rounding)),t.colorToStr(this.color,n)};t.ColorPicker.prototype.setValue=function(n){var i=t.strToColor(n);return i?this.setColor(i):this};t.ColorPicker.prototype.setColor=function(n){return typeof n=="string"?this.setValue(n):n.r!=null?this.setRgba(n.r,n.g,n.b,n.a):n.h!=null?this.setHsva(n.h,n.s,n.v,n.a):n.a!=null?this.setAlpha(n.a):this};t.ColorPicker.prototype.setRgba=function(n,i,r,u){var f=this.color,e;return f.r=n,f.g=i,f.b=r,u!=null&&(f.a=u),e=t.rgbToHsv(n,i,r),f.h=e.h,f.s=e.s,f.v=e.v,this.updateSliders(),this.redrawSliders(),this.updateInput(),this};t.ColorPicker.prototype.setRgb=function(n,t,i){return this.setRgba(n,t,i,null)};t.ColorPicker.prototype.setHsva=function(n,i,r,u){var f=this.color,e;return f.h=n,f.s=i,f.v=r,u!=null&&(f.a=u),e=t.hsvToRgb(n,i,r),f.r=e.r,f.g=e.g,f.b=e.b,this.updateSliders(),this.redrawSliders(),this.updateInput(),this};t.ColorPicker.prototype.setHsv=function(n,t,i){return this.setHsva(n,t,i,null)};t.ColorPicker.prototype.setAlpha=function(n){return this.color.a=n,this.updateSliders(),this.redrawSliders(),this.updateInput(),this};t.ColorPicker.prototype.show=function(){var r=this.input,f=n(r),i=n(this.widget),e=this.options,o,u;e.layout=="popup"&&(i.data("jQWCP.instance",this),i.stop(!0,!0),i.css({top:r.getBoundingClientRect().top-t.ORIGIN.top+f.outerHeight()+"px",left:r.getBoundingClientRect().left-t.ORIGIN.left+"px"}),this.refreshWidget(),this.redrawSliders(),this.updateSliders(),this.lastValue=r.value,i.fadeIn(e.animDuration),e.hideKeyboard&&(f.blur(),n(t.ColorPicker.overlay).show()),i.hasClass("jQWCP-mobile")&&(o=n("html").scrollTop(),u=r.getBoundingClientRect().top-t.ORIGIN.top,u<o?n("html").animate({scrollTop:u}):u+f.outerHeight()>o+window.innerHeight-i.outerHeight()&&n("html").animate({scrollTop:u+f.outerHeight()-window.innerHeight+i.outerHeight()})))};t.ColorPicker.prototype.hide=function(){var i=n(this.widget);this==i.data("jQWCP.instance")&&(i.fadeOut(this.options.animDuration),n(t.ColorPicker.overlay).hide())};t.Handler={};t.Handler.input_focus_popup=function(){var t=n(this).data("jQWCP.instance");t.show()};t.Handler.input_blur_popup=function(){var t=n(this).data("jQWCP.instance");t.options.hideKeyboard||(t.hide(),t.lastValue!=this.value&&n(this).trigger("change"))};t.Handler.input_change=function(){var r=n(this).data("jQWCP.instance"),i=t.strToColor(this.value);i&&r.setColor(i)};t.Handler.widget_focus_block=function(){var t=n(this).data("jQWCP.instance"),i=n(t.input);t.lastValue=t.input.value;i.triggerHandler("focus")};t.Handler.widget_mousedown_popup=function(){var f=n(this).data("jQWCP.instance"),t=n(f.input),i,u,r;if(t.off("focus.wheelColorPicker"),t.off("blur.wheelColorPicker"),i=t.data("events")!=undefined?t.data("events").blur:undefined,u={blur:[]},i!=undefined)for(r=0;r<i.length;r++)u.blur.push(i[r]);t.data("jQWCP.suspendedEvents",u)};t.Handler.widget_blur_block=function(){var t=n(this).data("jQWCP.instance"),i=n(t.input);t.lastValue!=t.input.value&&i.trigger("change");i.triggerHandler("blur")};t.Handler.wheelCursor_mousedown=function(){var t=n(this),i=t.closest(".jQWCP-wWidget"),r=i.data("jQWCP.instance"),u=n(r.input);n("body").data("jQWCP.activeControl",t.parent().get(0));u.trigger("sliderdown")};t.Handler.wheel_mousedown=function(){var t=n(this),i=t.closest(".jQWCP-wWidget"),r=i.data("jQWCP.instance"),u=n(r.input);n("body").data("jQWCP.activeControl",t.get(0));u.trigger("sliderdown")};t.Handler.slider_mousedown=function(){var t=n(this),i=t.closest(".jQWCP-wWidget"),r=i.data("jQWCP.instance"),u=n(r.input);n("body").data("jQWCP.activeControl",t.parent().get(0));u.trigger("sliderdown")};t.Handler.sliderCursor_mousedown=function(){var t=n(this),i=t.closest(".jQWCP-wWidget"),r=i.data("jQWCP.instance"),u=n(r.input);n("body").data("jQWCP.activeControl",t.parent().get(0));u.trigger("sliderdown")};t.Handler.html_mouseup=function(i){var o=n(n("body").data("jQWCP.activeControl")),s,f,u;if(o.length!=0){var h=o.closest(".jQWCP-wWidget"),e=h.data("jQWCP.instance"),r=n(e.input);if(e.options.layout=="popup"){e.options.hideKeyboard||r.trigger("focus.jQWCP_DONT_TRIGGER_EVENTS");r.on("focus.wheelColorPicker",t.Handler.input_focus_popup);r.on("blur.wheelColorPicker",t.Handler.input_blur_popup);if(s=r.data("jQWCP.suspendedEvents"),s!=undefined)for(f=s.blur,u=0;u<f.length;u++)r.on("blur"+(f[u].namespace==""?"":"."+f[u].namespace),f[u].handler)}o.length!=0&&(i.pageX!=undefined&&e.updateActiveControl(i),n("body").data("jQWCP.activeControl",null),r.trigger("sliderup"))}};t.Handler.html_mousemove=function(t){var i=n(n("body").data("jQWCP.activeControl"));if(i.length!=0){t.preventDefault();var u=i.closest(".jQWCP-wWidget"),r=u.data("jQWCP.instance"),f=n(r.input);return r.updateActiveControl(t),f.trigger("slidermove"),!1}};t.Handler.window_resize=function(){var t=n("body .jQWCP-wWidget.jQWCP-block");t.each(function(){var t=n(this).data("jQWCP.instance");t.refreshWidget();t.redrawSliders()})};t.Handler.overlay_click=function(){var r,i,u;t.ColorPicker.widget!=null&&(r=n(t.ColorPicker.widget),i=r.data("jQWCP.instance"),i!=null&&(u=n(i.input),i.lastValue!=i.input.value&&u.trigger("change"),i.hide()))};n(document).ready(function(){n("[data-wheelcolorpicker]").wheelColorPicker({htmlOptions:!0})}),function(){n.browser!=undefined&&n.browser.mozilla&&(n.fn.wheelColorPicker.defaults.quality=.2);n(document).ready(function(){n("body").append('<div id="jQWCP-PageOrigin" style="position: absolute; top: 0; left: 0; height: 0; width: 0;"><\/div>');var i=document.getElementById("jQWCP-PageOrigin").getBoundingClientRect();t.ORIGIN=i;n(window).on("scroll.jQWCP_RelativePageOriginBugFix",function(){var n=document.getElementById("jQWCP-PageOrigin").getBoundingClientRect();t.ORIGIN=n;(n.left!=0||n.top!=0)&&(t.BUG_RELATIVE_PAGE_ORIGIN=!0)})})}()})(jQuery)