var scrawl=function(e){e&&this.initOptions(e)};!function(){var m=$G("J_brushBoard"),g=m.getContext("2d"),a=[],f=0;scrawl.prototype={isScrawl:!1,brushWidth:-1,brushColor:"",initOptions:function(e){var t=this;t.originalState(e),t._buildToolbarColor(e.colorList),t._addBoardListener(e.saveNum),t._addOPerateListener(e.saveNum),t._addColorBarListener(),t._addBrushBarListener(),t._addEraserBarListener(),t._addAddImgListener(),t._addRemoveImgListenter(),t._addScalePicListenter(),t._addClearSelectionListenter(),t._originalColorSelect(e.drawBrushColor),t._originalBrushSelect(e.drawBrushSize),t._clearSelection()},originalState:function(e){var t=this;t.brushWidth=e.drawBrushSize,t.brushColor=e.drawBrushColor,g.lineWidth=t.brushWidth,g.strokeStyle=t.brushColor,g.fillStyle="transparent",g.lineCap="round",g.fill()},_buildToolbarColor:function(e){var t=null,a=[];a.push("");for(var i,r=0;i=e[r++];)(r-1)%5==0&&(1!=r&&a.push(""),a.push("")),t="#"+i,a.push("");a.push("
"),$G("J_colorBar").innerHTML=a.join("")},_addBoardListener:function(i){var r,o,s=this,n=-1,l=-1,c=!1,d=!1,h=!1,u=0,p="";r=parseInt(domUtils.getComputedStyle($G("J_wrap"),"margin-left")),a.push(g.getImageData(0,0,g.canvas.width,g.canvas.height)),f+=1,domUtils.on(m,["mousedown","mousemove","mouseup","mouseout"],function(e){switch(o=browser.webkit?e.which:u,e.type){case"mousedown":p=u=1,d=h=!(c=!0),s.isScrawl=!0,n=e.clientX-r,l=e.clientY-r,g.beginPath();break;case"mousemove":if(!p&&0==o)return;if(!p&&o&&(n=e.clientX-r,l=e.clientY-r,g.beginPath(),p=1),h||!c)return;var t=e.clientX-r,a=e.clientY-r;g.moveTo(n,l),g.lineTo(t,a),g.stroke(),n=t,l=a,d=!0;break;case"mouseup":if(u=0,!c)return;d||(g.arc(n,l,g.lineWidth,0,2*Math.PI,!1),g.fillStyle=g.strokeStyle,g.fill()),g.closePath(),s._saveOPerate(i),h=!(d=c=!1),l=n=-1;break;case"mouseout":if(p="",u=0,1==o)return;g.closePath()}})},_addOPerateListener:function(e){var t=this;domUtils.on($G("J_previousStep"),"click",function(){1")}!function(){var o=[[1,1,-1,-1],[0,1,0,-1],[0,1,1,-1],[1,0,-1,0],[0,0,1,0],[1,0,-1,1],[0,0,0,1],[0,0,1,1]];ScaleBoy.prototype={init:function(){!function(){var e=document,t=e.getElementsByTagName("head")[0],a=e.createElement("style"),i=".scale{visibility:hidden;cursor:move;position:absolute;left:0;top:0;width:100px;height:50px;background-color:#fff;font-size:0;line-height:0;opacity:.4;filter:Alpha(opacity=40);}.scale span{position:absolute;left:0;top:0;width:6px;height:6px;background-color:#006DAE;}.scale .hand0, .scale .hand7{cursor:nw-resize;}.scale .hand1, .scale .hand6{left:50%;margin-left:-3px;cursor:n-resize;}.scale .hand2, .scale .hand4, .scale .hand7{left:100%;margin-left:-6px;}.scale .hand3, .scale .hand4{top:50%;margin-top:-3px;cursor:w-resize;}.scale .hand5, .scale .hand6, .scale .hand7{margin-top:-6px;top:100%;}.scale .hand2, .scale .hand5{cursor:ne-resize;}";a.type="text/css";try{a.appendChild(e.createTextNode(i))}catch(e){a.styleSheet.cssText=i}t.appendChild(a)}();var a=this,t=a.dom=function(){var e=[],t=document.createElement("div");t.id="J_scaleCon",t.className="scale";for(var a=0;a<8;a++)e.push("");return t.innerHTML=e.join(""),t}();return a.scaleMousemove.fp=a,domUtils.on(t,"mousedown",function(e){var t=e.target||e.srcElement;a.start={x:e.clientX,y:e.clientY},-1!=t.className.indexOf("hand")&&(a.dir=t.className.replace("hand","")),domUtils.on(document.body,"mousemove",a.scaleMousemove),e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}),domUtils.on(document.body,"mouseup",function(e){a.start&&(domUtils.un(document.body,"mousemove",a.scaleMousemove),a.moved&&a.updateScaledElement({position:{x:t.style.left,y:t.style.top},size:{w:t.style.width,h:t.style.height}}),delete a.start,delete a.moved,delete a.dir)}),t},startScale:function(e){this.dom.style.cssText="visibility:visible;top:"+e.style.top+";left:"+e.style.left+";width:"+e.offsetWidth+"px;height:"+e.offsetHeight+"px;",this.scalingElement=e},updateScaledElement:function(e){var t=this.scalingElement,a=e.position,i=e.size;a&&(void 0!==a.x&&(t.style.left=a.x),void 0!==a.y&&(t.style.top=a.y)),i&&(i.w&&(t.style.width=i.w),i.h&&(t.style.height=i.h))},updateStyleByDir:function(e,t){var a,i=this,r=i.dom;o.def=[1,1,0,0],0!=o[e][0]&&(a=parseInt(r.style.left)+t.x,r.style.left=i._validScaledProp("left",a)+"px"),0!=o[e][1]&&(a=parseInt(r.style.top)+t.y,r.style.top=i._validScaledProp("top",a)+"px"),0!=o[e][2]&&(a=r.clientWidth+o[e][2]*t.x,r.style.width=i._validScaledProp("width",a)+"px"),0!=o[e][3]&&(a=r.clientHeight+o[e][3]*t.y,r.style.height=i._validScaledProp("height",a)+"px"),"def"===e&&i.updateScaledElement({position:{x:r.style.left,y:r.style.top}})},scaleMousemove:function(e){var t=arguments.callee.fp,a=t.start,i=t.dir||"def",r={x:e.clientX-a.x,y:e.clientY-a.y};t.updateStyleByDir(i,r),arguments.callee.fp.start={x:e.clientX,y:e.clientY},arguments.callee.fp.moved=1},_validScaledProp:function(e,t){var a=this.dom,i=$G("J_picBoard");switch(t=isNaN(t)?0:t,e){case"left":return t<0?0:t+a.clientWidth>i.clientWidth?i.clientWidth-a.clientWidth:t;case"top":return t<0?0:t+a.clientHeight>i.clientHeight?i.clientHeight-a.clientHeight:t;case"width":return t<=0?1:t+a.offsetLeft>i.clientWidth?i.clientWidth-a.offsetLeft:t;case"height":return t<=0?1:t+a.offsetTop>i.clientHeight?i.clientHeight-a.offsetTop:t}}}}();