!function(a){function b(b){var c=a(b.target),d=c.offset();return{x:Math.round(b.pageX-d.left),y:Math.round(b.pageY-d.top)}}function c(a,b,c){b.coords[a]||(b.coords[a]=[]);var d=(new Date).getTime();b.options.relTimestamps&&(0===b.strokes.length&&0===b.coords[a].length&&(b.timestamp=d),d-=b.timestamp),b.coords[a].push([c.x,c.y,d,+b.sketch.isDrawing])}function d(a){return a.originalEvent.touches?!1:void j(a)}function e(a){return a.originalEvent.touches?!1:void k(a)}function f(a){return a.originalEvent.touches?!1:void l(a)}function g(b){var c=a(b.target),d=c.data(m),e=d.options,f=b.originalEvent.changedTouches;if(e.multitouch)for(var g=0;g0&&g.sketch.fillCircle(i.x,i.y,h.graphics.firstPointSize),g.coords[e]||(g.coords[e]=[]),g.coords[e].length>0&&(g.strokes.push(g.coords[e]),g.coords[e]=[]),c(e,g,i),"function"==typeof h.events.mousedown&&h.events.mousedown(f,g,d)}function k(d){var e=d.identifier||0,f=a(d.target),g=f.data(m),h=g.options;if(h.mouseupMovements&&0!==g.strokes.length||g.sketch.isDrawing){var i=b(d);if(g.sketch.isDrawing){var j=g.coords[e][g.coords[e].length-1];g.sketch.beginPath().line(j[0],j[1],i.x,i.y).stroke().closePath()}c(e,g,i),"function"==typeof h.events.mousemove&&h.events.mousemove(f,g,d)}}function l(b){var c=b.identifier||0,d=a(b.target),e=d.data(m),f=e.options;e.sketch.isDrawing=!1,e.strokes.push(e.coords[c]),e.coords[c]=[],"function"==typeof f.events.mouseup&&f.events.mouseup(d,e,b)}var m="sketchable",n={init:function(b){var c=a.extend(!0,{},a.fn.sketchable.defaults,b||{});return this.each(function(){var b=a(this),j=b.data(m);j||c.interactive&&(b.bind("mousedown",d),b.bind("mousemove",e),b.bind("mouseup",f),b.bind("touchstart",g),b.bind("touchmove",h),b.bind("touchend",i),this.onselectstart=function(){return!1});var k=new jSketch(this,c.graphics);k.isDrawing=!1,b.data(m,{strokes:[],coords:{},timestamp:(new Date).getTime(),sketch:k,options:c}),"function"==typeof c.events.init&&c.events.init(b,b.data(m))})},config:function(b){return this.each(function(){var c=a(this),d=c.data(m);d.options=a.extend(!0,{},a.fn.sketchable.defaults,b||{})})},strokes:function(b){if(b)return this.each(function(){var c=a(this),d=c.data(m);d.strokes=b});var c=a(this).data(m);return c.strokes},handler:function(b){return this.each(function(){var c=a(this),d=c.data(m);b(c,d)})},clear:function(){return this.each(function(){var b=a(this),c=b.data(m)||{},d=c.options;c.sketch&&(c.sketch.clear(),c.strokes=[],c.coords={}),d&&"function"==typeof d.events.clear&&d.events.clear(b,c)})},reset:function(b){return this.each(function(){var c=a(this),d=c.data(m)||{},e=d.options;c.sketchable("destroy").sketchable(b),e&&"function"==typeof e.events.reset&&e.events.reset(c,d)})},destroy:function(){return this.each(function(){var b=a(this),c=b.data(m)||{},j=c.options;j.interactive&&(b.unbind("mouseup",f),b.unbind("mousemove",e),b.unbind("mousedown",d),b.unbind("touchstart",g),b.unbind("touchmove",h),b.unbind("touchend",i)),b.removeData(m),j&&"function"==typeof j.events.destroy&&j.events.destroy(b,c)})}};a.fn.sketchable=function(b){return"methods functions hooks".split(" ").indexOf(b)>-1?n:n[b]?n[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?(a.error("Method "+b+' does not exist. See jQuery.sketchable("methods").'),this):n.init.apply(this,arguments)},a.fn.sketchable.defaults={interactive:!0,mouseupMovements:!1,relTimestamps:!1,multitouch:!0,events:{},graphics:{firstPointSize:3,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F",lineCap:"round",lineJoin:"round",miterLimit:10}}}(jQuery);