!function(t){"use strict";var e={},i=Math.max,n=Math.min;e.c={},e.c.d=t(document),e.c.t=function(t){return t.originalEvent.touches.length-1},e.o=function(){var i=this;this.o=null,this.$=null,this.i=null,this.g=null,this.v=null,this.cv=null,this.x=0,this.y=0,this.w=0,this.h=0,this.$c=null,this.c=null,this.t=0,this.isInit=!1,this.fgColor=null,this.pColor=null,this.dH=null,this.cH=null,this.eH=null,this.rH=null,this.scale=1,this.relative=!1,this.relativeWidth=!1,this.relativeHeight=!1,this.$div=null,this.run=function(){var e=function(t,e){var n;for(n in e)i.o[n]=e[n];i.init(),i._configure()._draw()};if(!this.$.data("kontroled"))return this.$.data("kontroled",!0),this.extend(),this.o=t.extend({min:this.$.data("min")||0,max:this.$.data("max")||100,stopper:!0,readOnly:this.$.data("readonly")||"readonly"==this.$.attr("readonly"),cursor:this.$.data("cursor")===!0&&30||this.$.data("cursor")||0,thickness:this.$.data("thickness")&&Math.max(Math.min(this.$.data("thickness"),1),.01)||.35,lineCap:this.$.data("linecap")||"butt",width:this.$.data("width")||200,height:this.$.data("height")||200,displayInput:null==this.$.data("displayinput")||this.$.data("displayinput"),displayPrevious:this.$.data("displayprevious"),fgColor:this.$.data("fgcolor")||"#87CEEB",inputColor:this.$.data("inputcolor"),font:this.$.data("font")||"Arial",fontWeight:this.$.data("font-weight")||"bold",inline:!1,step:this.$.data("step")||1,draw:null,change:null,cancel:null,release:null,error:null},this.o),this.o.inputColor||(this.o.inputColor=this.o.fgColor),this.$.is("fieldset")?(this.v={},this.i=this.$.find("input"),this.i.each(function(e){var n=t(this);i.i[e]=n,i.v[e]=n.val(),n.bind("change",function(){var t={};t[e]=n.val(),i.val(t)})}),this.$.find("legend").remove()):(this.i=this.$,this.v=this.$.val(),""==this.v&&(this.v=this.o.min),this.$.bind("change",function(){i.val(i._validate(i.$.val()))})),!this.o.displayInput&&this.$.hide(),this.$c=t(document.createElement("canvas")),"undefined"!=typeof G_vmlCanvasManager&&G_vmlCanvasManager.initElement(this.$c[0]),this.c=this.$c[0].getContext?this.$c[0].getContext("2d"):null,this.c?(this.scale=(window.devicePixelRatio||1)/(this.c.webkitBackingStorePixelRatio||this.c.mozBackingStorePixelRatio||this.c.msBackingStorePixelRatio||this.c.oBackingStorePixelRatio||this.c.backingStorePixelRatio||1),this.relativeWidth=0!==this.o.width%1&&this.o.width.indexOf("%"),this.relativeHeight=0!==this.o.height%1&&this.o.height.indexOf("%"),this.relative=this.relativeWidth||this.relativeHeight,this.$div=t('<div style="'+(this.o.inline?"display:inline;":"")+'"></div>'),this.$.wrap(this.$div).before(this.$c),this.$div=this.$.parent(),this._carve(),this.v instanceof Object?(this.cv={},this.copy(this.v,this.cv)):this.cv=this.v,this.$.bind("configure",e).parent().bind("configure",e),this._listen()._configure()._xy().init(),this.isInit=!0,this._draw(),this):(this.o.error&&this.o.error(),void 0)},this._carve=function(){if(this.relative){var t=this.relativeWidth?this.$div.parent().width()*parseInt(this.o.width)/100:this.$div.parent().width(),e=this.relativeHeight?this.$div.parent().height()*parseInt(this.o.height)/100:this.$div.parent().height();this.w=this.h=Math.min(t,e)}else this.w=this.o.width,this.h=this.o.height;return this.$div.css({width:this.w+"px",height:this.h+"px"}),this.$c.attr({width:this.w,height:this.h}),1!==this.scale&&(this.$c[0].width=this.$c[0].width*this.scale,this.$c[0].height=this.$c[0].height*this.scale,this.$c.width(this.w),this.$c.height(this.h)),this},this._draw=function(){var t=!0;i.g=i.c,i.clear(),i.dH&&(t=i.dH()),t!==!1&&i.draw()},this._touch=function(t){var n=function(t){var e=i.xy2val(t.originalEvent.touches[i.t].pageX,t.originalEvent.touches[i.t].pageY);e!=i.cv&&(i.cH&&i.cH(e)===!1||(i.change(i._validate(e)),i._draw()))};return this.t=e.c.t(t),n(t),e.c.d.bind("touchmove.k",n).bind("touchend.k",function(){e.c.d.unbind("touchmove.k touchend.k"),i.rH&&i.rH(i.cv)===!1||i.val(i.cv)}),this},this._mouse=function(t){var n=function(t){var e=i.xy2val(t.pageX,t.pageY);e!=i.cv&&(i.cH&&i.cH(e)===!1||(i.change(i._validate(e)),i._draw()))};return n(t),e.c.d.bind("mousemove.k",n).bind("keyup.k",function(t){if(27===t.keyCode){if(e.c.d.unbind("mouseup.k mousemove.k keyup.k"),i.eH&&i.eH()===!1)return;i.cancel()}}).bind("mouseup.k",function(){e.c.d.unbind("mousemove.k mouseup.k keyup.k"),i.rH&&i.rH(i.cv)===!1||i.val(i.cv)}),this},this._xy=function(){var t=this.$c.offset();return this.x=t.left,this.y=t.top,this},this._listen=function(){return this.o.readOnly?this.$.attr("readonly","readonly"):(this.$c.bind("mousedown",function(t){t.preventDefault(),i._xy()._mouse(t)}).bind("touchstart",function(t){t.preventDefault(),i._xy()._touch(t)}),this.relative&&t(window).resize(function(){i._carve().init(),i._draw()}),this.listen()),this},this._configure=function(){return this.o.draw&&(this.dH=this.o.draw),this.o.change&&(this.cH=this.o.change),this.o.cancel&&(this.eH=this.o.cancel),this.o.release&&(this.rH=this.o.release),this.o.displayPrevious?(this.pColor=this.h2rgba(this.o.fgColor,"0.4"),this.fgColor=this.h2rgba(this.o.fgColor,"0.6")):this.fgColor=this.o.fgColor,this},this._clear=function(){this.$c[0].width=this.$c[0].width},this._validate=function(t){return~~((0>t?-.5:.5)+t/this.o.step)*this.o.step},this.listen=function(){},this.extend=function(){},this.init=function(){},this.change=function(){},this.val=function(){},this.xy2val=function(){},this.draw=function(){},this.clear=function(){this._clear()},this.h2rgba=function(t,e){var i;return t=t.substring(1,7),i=[parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16)],"rgba("+i[0]+","+i[1]+","+i[2]+","+e+")"},this.copy=function(t,e){for(var i in t)e[i]=t[i]}},e.Dial=function(){e.o.call(this),this.startAngle=null,this.xy=null,this.radius=null,this.lineWidth=null,this.cursorExt=null,this.w2=null,this.PI2=2*Math.PI,this.extend=function(){this.o=t.extend({bgColor:this.$.data("bgcolor")||"#EEEEEE",angleOffset:this.$.data("angleoffset")||0,angleArc:this.$.data("anglearc")||360,inline:!0},this.o)},this.val=function(t){return null==t?this.v:(this.cv=this.o.stopper?i(n(t,this.o.max),this.o.min):t,this.v=this.cv,this.$.val(this.v),this._draw(),void 0)},this.xy2val=function(t,e){var r,o;return r=Math.atan2(t-(this.x+this.w2),-(e-this.y-this.w2))-this.angleOffset,this.angleArc!=this.PI2&&0>r&&r>-.5?r=0:0>r&&(r+=this.PI2),o=~~(.5+r*(this.o.max-this.o.min)/this.angleArc)+this.o.min,this.o.stopper&&(o=i(n(o,this.o.max),this.o.min)),o},this.listen=function(){var e,r,o=this,a=function(t){t.preventDefault();var e=t.originalEvent,i=e.detail||e.wheelDeltaX,n=e.detail||e.wheelDeltaY,r=parseInt(o.$.val())+(i>0||n>0?o.o.step:0>i||0>n?-o.o.step:0);o.cH&&o.cH(r)===!1||o.val(r)},s=1,l={37:-o.o.step,38:o.o.step,39:o.o.step,40:-o.o.step};this.$.bind("keydown",function(a){var h=a.keyCode;if(h>=96&&105>=h&&(h=a.keyCode=h-48),e=parseInt(String.fromCharCode(h)),isNaN(e)&&(13!==h&&8!==h&&9!==h&&189!==h&&a.preventDefault(),t.inArray(h,[37,38,39,40])>-1)){a.preventDefault();var c=parseInt(o.$.val())+l[h]*s;o.o.stopper&&(c=i(n(c,o.o.max),o.o.min)),o.change(c),o._draw(),r=window.setTimeout(function(){s*=2},30)}}).bind("keyup",function(){isNaN(e)?r&&(window.clearTimeout(r),r=null,s=1,o.val(o.$.val())):o.$.val()>o.o.max&&o.$.val(o.o.max)||o.$.val()<o.o.min&&o.$.val(o.o.min)}),this.$c.bind("mousewheel DOMMouseScroll",a),this.$.bind("mousewheel DOMMouseScroll",a)},this.init=function(){(this.v<this.o.min||this.v>this.o.max)&&(this.v=this.o.min),this.$.val(this.v),this.w2=this.w/2,this.cursorExt=this.o.cursor/100,this.xy=this.w2*this.scale,this.lineWidth=this.xy*this.o.thickness,this.lineCap=this.o.lineCap,this.radius=this.xy-this.lineWidth/2,this.o.angleOffset&&(this.o.angleOffset=isNaN(this.o.angleOffset)?0:this.o.angleOffset),this.o.angleArc&&(this.o.angleArc=isNaN(this.o.angleArc)?this.PI2:this.o.angleArc),this.angleOffset=this.o.angleOffset*Math.PI/180,this.angleArc=this.o.angleArc*Math.PI/180,this.startAngle=1.5*Math.PI+this.angleOffset,this.endAngle=1.5*Math.PI+this.angleOffset+this.angleArc;var t=i(String(Math.abs(this.o.max)).length,String(Math.abs(this.o.min)).length,2)+2;this.o.displayInput&&this.i.css({width:(this.w/2+4>>0)+"px",height:(this.w/3>>0)+"px",position:"absolute","vertical-align":"middle","margin-top":(this.w/3>>0)+"px","margin-left":"-"+(3*this.w/4+2>>0)+"px",border:0,background:"none",font:this.o.fontWeight+" "+(this.w/t>>0)+"px "+this.o.font,"text-align":"center",color:this.o.inputColor||this.o.fgColor,padding:"0px","-webkit-appearance":"none"})||this.i.css({width:"0px",visibility:"hidden"})},this.change=function(t){this.cv=t,this.$.val(t)},this.angle=function(t){return(t-this.o.min)*this.angleArc/(this.o.max-this.o.min)},this.draw=function(){var t,e,i=this.g,n=this.angle(this.cv),r=this.startAngle,o=r+n,a=1;i.lineWidth=this.lineWidth,i.lineCap=this.lineCap,this.o.cursor&&(r=o-this.cursorExt)&&(o+=this.cursorExt),i.beginPath(),i.strokeStyle=this.o.bgColor,i.arc(this.xy,this.xy,this.radius,this.endAngle,this.startAngle,!0),i.stroke(),this.o.displayPrevious&&(e=this.startAngle+this.angle(this.v),t=this.startAngle,this.o.cursor&&(t=e-this.cursorExt)&&(e+=this.cursorExt),i.beginPath(),i.strokeStyle=this.pColor,i.arc(this.xy,this.xy,this.radius,t,e,!1),i.stroke(),a=this.cv==this.v),i.beginPath(),i.strokeStyle=a?this.o.fgColor:this.fgColor,i.arc(this.xy,this.xy,this.radius,r,o,!1),i.stroke()},this.cancel=function(){this.val(this.v)}},t.fn.dial=t.fn.knob=function(i){return this.each(function(){var n=new e.Dial;n.o=i,n.$=t(this),n.run()}).parent()}}(jQuery);