/**
   @license
   Copyright 2010 Hanov Solutions Inc. All Rights Reserved

   steve.hanov@gmail.com
 */
var r=true,u=null,z=false;function A(){return function(){}}function aa(a){return function(b){this[a]=b}}function ba(a){return function(){return this[a]}}function ca(a){return function(){return a}}function G(){this.I()}
G.prototype={I:function(){this.id=da++;this.rect=new J(0,0,1,1);this.u=new L;this.parent=u;this.children=[]},Sa:[],ka:ba("Sa"),dd:function(a){for(var b=this.ka(),c=0;c<b.length;c++){var d=a.S(b[c].name);d!==undefined&&this.setProperty(b[c].name,d)}},setProperty:function(a,b){this[a]=b},S:function(a){return this[a]},save:function(){var a={};a.type="Node";a.matrix=this.u.save();a.children=[];for(var b=0;b<this.children.length;b++)a.children.push(this.children[b].save());return a},load:function(a){var b=
a.matrix,c=new L;c.m11=b.m11;c.m12=b.m12;c.m21=b.m21;c.m22=b.m22;c.A=b.dx;c.w=b.dy;this.u=c;for(b=this.children.length=0;b<a.children.length;b++){c=N(a.children[b]);c.parent=this;this.children.push(c)}},wc:function(){return this.parent.parent!==u},duplicate:function(){return N(this.save())},ba:function(a,b){for(var c=0;c<this.children.length;c++){var d=this.children[c].ba(a,b);if(d)return d}return u},t:function(a){for(var b=0;b<this.children.length;b++){this.children[b].t(a);if(b===0)this.rect=ea(this.children[b].rect);
else this.rect.yb(this.children[b].rect)}},transform:function(a){this.u=a.multiply(this.u)},Hb:ba("u"),Da:aa("u"),e:function(a){for(var b=this.children.length-1;b>=0;b--)this.children[b].e(a)},pc:function(a){for(var b,c=0;c<this.children.length;c++){if(this.children[c]===a)return this;if(b=this.children[c].pc(a))return b}return u},J:function(a,b){b===-1?this.children.push(a):this.children.splice(b,0,a);a.parent=this},removeChild:function(a){for(var b=0;b<this.children.length;b++)if(this.children[b]===
a){this.children.splice(b,1);a.parent=u;return b}return-1},Za:ca(z),aa:A(),Pa:ca(u),Na:A(),da:A()};var da=1;window.BaseNode=G;var O=[],fa=u;function ga(){for(var a=[],b=0;b<O.length;b++)O[b].complete?O[b].lb(O[b],O[b].Va):a.push(O[b]);O=a;if(O.length)setTimeout(ga,250);else fa=z}function ha(a,b){var c=new Image;O.push(c);c.lb=b;c.src=a;c.Va=a;c.onload=function(){if(c.complete)for(var d=0;d<O.length;d++){if(O[d]===this){O.splice(d,1);b(c,c.Va);break}}else if(!fa){fa=r;setTimeout(ga,250)}};return c}function ja(){this.I.apply(this,arguments)}var ka={textFillStyle:"#000000",fontName:"FG Virgil",fontSize:20};
ja.prototype={I:function(a){this.F.I.apply(this);this.D=window.document?document.createElement("img"):{};this.textFillStyle=ka.textFillStyle;this.fontName=ka.fontName;this.fontSize=ka.fontSize;this.ta=100;this.sa=15;this.rect=new J(0,0,this.ta,this.sa);this.ze=0;this.Va=this.Sc="";this.complete=this.Mb=z;if(a!==undefined){this.text=a;this.rc()}},load:function(a){this.F.load.apply(this,[a]);this.textFillStyle=a.fillStyle;this.fontName=a.fontName;this.fontSize=a.fontSize;this.text=a.text},save:function(){var a=
this.F.save.apply(this);a.type="TextNode";a.fillStyle=this.textFillStyle;a.text=this.text;a.fontName=this.fontName;a.fontSize=this.fontSize;return a},Sa:[{name:"text",display:"Text",type:"text"},{name:"textFillStyle",display:"Text Colour",type:"colour"},{name:"fontSize",display:"Font Size",type:"select",b:[{name:"10",value:10},{name:"12",value:12},{name:"15",value:15},{name:"20",value:20},{name:"30",value:30},{name:"40",value:40},{name:"50",value:50},{name:"60",value:60}]},{name:"fontName",display:"Font",
type:"select",b:[{name:"FG Virgil",value:"FG Virgil"},{name:"Arial",value:"Arial"},{name:"Times New Roman",value:"Times New Roman"},{name:"Stinky Kitty",value:"Stinky Kitty"},{name:"FG Bunnigrrrl",value:"FG Bunnigrrrl's handwriting"},{name:"FG Amura",value:"FG Amura"}]}],setProperty:function(a,b){ka[a]=b;this[a]=b},ba:function(a,b){return a>=this.rect.x&&a<this.rect.x+this.rect.width&&b>=this.rect.y&&b<this.rect.y+this.rect.height?this:u},rc:function(){if(window.document){var a=this;this.Va="button.cgi?font="+
this.fontName+"&size="+this.fontSize+"&text="+encodeURIComponent(this.text)+"&fill="+encodeURIComponent(this.textFillStyle)+"&stroke="+encodeURIComponent(this.strokeStyle)+"&lineWidth="+this.lineWidth;if(this.Sc!==this.Va&&!this.Mb){this.Mb=r;ha(this.Va,function(b,c){a.Pd(b,c)});return z}}return r},Pd:function(a,b){this.Mb=z;this.Sc=b;this.D=a;this.complete=r;this.path!==undefined?this.path.t(this.a):this.t(this.a);la.gb();la.e()},t:function(a){this.a=a;if(window.document){if(this.rc()&&this.complete){this.ta=
this.D.width;this.sa=this.D.height}}else{a.font=""+this.fontSize+"px "+this.fontName+"";this.ta=a.measureText(this.text).width;this.sa=this.fontSize*1.5}a=this.u.apply(0,0);var b=this.u.apply(this.ta,0),c=this.u.apply(this.ta,this.sa),d=this.u.apply(0,this.sa);this.rect.x=a.x;this.rect.y=a.y;this.rect.width=0;this.rect.height=0;this.rect.db(b.x,b.y);this.rect.db(c.x,c.y);this.rect.db(d.x,d.y)},e:function(a){a.save();a.transform(this.u.m11,this.u.m21,this.u.m12,this.u.m22,this.u.A,this.u.w);if(window.document===
undefined){a.font=""+this.fontSize+"px "+this.fontName+"";a.fillStyle=this.textFillStyle;a.fillText(this.text,0,0)}else if(this.complete)try{a.drawImage(this.D,0,0)}catch(b){}else{a.strokeStyle="#008888";a.lineWidth=1;a.beginPath();a.moveTo(0,0);a.lineTo(this.ta,this.sa);a.moveTo(this.ta,0);a.lineTo(0,this.sa);a.rect(0,0,this.ta,this.sa);a.stroke()}a.restore()}};ja.prototype=$.extend({},G.prototype,ja.prototype);ja.prototype.F=G.prototype;window.TextNode=ja;function ma(a){this.I(a)}ma.prototype={I:function(){this.Ae=this.te?r:z}};function P(a,b){this.type=a;this.b=b;if(this.b.length<4)throw"Bad value";}var na,oa=0,pa=1,qa=2,ra=3;P.prototype={toString:function(){function a(c){c=Math.round(c*255);return c<16?"0"+c.toString(16):c.toString(16)}var b=this.Ma(oa);return b.b[3]===1?"#"+a(b.b[0])+a(b.b[1])+a(b.b[2]):"rgba("+Math.round(b.b[0]*255)+","+Math.round(b.b[1]*255)+","+Math.round(b.b[2]*255)+","+b.b[3]+")"},Ma:function(a){return na[this.type][a](this)}};
(function(){function a(k){var i=k.b[0],g=k.b[1],j=k.b[2];if(i<0)i+=360;var l=i/60-Math.floor(i/60),p=j*(1-g),v=j*(1-l*g);g=j*(1-(1-l)*g);var y,s,m;switch(Math.floor(i/60)%6){case 0:y=j;s=g;m=p;break;case 1:y=v;s=j;m=p;break;case 2:y=p;s=j;m=g;break;case 3:y=p;s=v;m=j;break;case 4:y=g;s=p;m=j;break;case 5:y=j;s=p;m=v}return new P(oa,[y,s,m,k.b[3]])}function b(k){var i,g=k.b[0],j=k.b[1],l=k.b[2],p=Math.max(g,j,l),v=Math.min(g,j,l);if(p===v)i=0;else if(p===g)i=(60*(j-l)/(p-v)+360)%360;else if(p===j)i=
60*(l-g)/(p-v)+120;else if(p===l)i=60*(g-j)/(p-v)+240;return new P(qa,[i,p===0?0:1-v/p,p,k.b[3]])}function c(k){function i(l){return l>6/29*(6/29)*(6/29)?Math.pow(l,1/3):1/3*29/6*(29/6)*l+4/29}var g={va:1/3,wa:1/3,Ka:1/3},j=i(k.b[1]/g.wa);return new P(ra,[116*j-16,500*(i(k.b[0]/g.va)-j),200*(j-i(k.b[2]/g.Ka)),k.b[3]])}function d(k){var i=(k.b[0]+16)/116,g=i+k.b[1]/500,j=i-k.b[2]/200,l={va:1/3,wa:1/3,Ka:1/3},p=6/29;return new P(P.se,[g>p?l.va*g*g*g:(g-16/116)*3*p*p*l.va,i>p?l.wa*i*i*i:(i-16/116)*3*
p*p*l.wa,j>p?l.Ka*j*j*j:(j-16/116)*3*p*p*l.Ce,k.b[3]])}function e(k){for(var i=[],g=0;g<3;g++)i[g]=k.b[g]<=0.04045?k.b[g]/12.92:Math.pow((k.b[g]+0.055)/1.055,2.4);return new P(pa,[0.4124*i[0]+0.3576*i[1]+0.1805*i[2],0.2126*i[0]+0.7152*i[1]+0.0722*i[2],0.0193*i[0]+0.1192*i[1]+0.9505*i[2],k.b[3]])}function f(k){var i=[],g=[];i[0]=3.241*k.va-1.5374*k.wa-0.4986*k.Ka;i[1]=-0.9692*k.va+1.876*k.wa+0.0416*k.Ka;i[2]=0.0556*k.va-0.204*k.wa+1.057*k.Ka;for(var j=0;j<3;j++)g[j]=i[j]<=0.0031308?12.92*i[j]:1.055*
Math.pow(i[j],1/2.4)-0.055;g[3]=k.b[3];return new P(oa,g)}function h(k){return new P(k.type,k.b.concat())}function n(k){return c(e(k))}function q(k){return b(f(k))}na=[[h,e,b,n],[f,h,q,c],[a,function(k){return e(a(k))},h,function(k){return n(a(k))}],[function(k){return f(d(k))},d,function(k){return q(d(k))},h]]})();
var ua={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",
darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",
gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",
lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",
orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",
snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function va(a){this.p=document.createElement("div");this.canvas=document.createElement("canvas");this.height=this.width=a;this.canvas.width=this.width;this.canvas.height=this.height;this.canvas.style.cursor="crosshair";this.a=this.canvas.getContext("2d");this.p.appendChild(this.canvas);var b=document.createElement("input");b.type="range";if("min"in b){this.p.appendChild(document.createElement("br"));this.p.appendChild(b);b.min=0;b.max=255;b.value=255;this.La=b}else this.La=u;this.B=this.height;this.pa=
this.height*0.8;if(va[a])this.data=va[a];else{b=this.a.getImageData(0,0,this.B,this.B);for(var c=this.B/2,d=this.pa/2,e,f=0;f<this.B;f++){var h=Math.sqrt(c*c-(f-c)*(f-c)),n=Math.floor(-h+c),q=Math.floor(h+c),k=d*d-(f-c)*(f-c);if(k>=0){h=Math.sqrt(k);k=Math.floor(-h+c);var i=Math.floor(h+c);h=f*this.B*4+n*4;for(n=n;n<=k;n++){e=Math.atan2(f-c,n-c);e=new P(qa,[e/Math.PI*180,1,1,1]);e=e.Ma(oa);b.data[h++]=e.b[0]*255;b.data[h++]=e.b[1]*255;b.data[h++]=e.b[2]*255;b.data[h++]=255}h=f*this.B*4+i*4;n=i}else{h=
f*this.B*4+n*4;n=n}for(;n<=q;n++){e=Math.atan2(f-c,n-c);e=new P(qa,[e/Math.PI*180,1,1,1]);e=e.Ma(oa);b.data[h++]=e.b[0]*255;b.data[h++]=e.b[1]*255;b.data[h++]=e.b[2]*255;b.data[h++]=255}}this.data=b;va[a]=b}this.K=new P(qa,[20,1,1,1]);this.update();this.e();var g=this;g.Cb=z;g.$a="";$(this.canvas).mousedown(function(j){var l=$(g.canvas).offset(),p=j.pageX-l.left;l=j.pageY-l.top;g.Cb=r;g.hc(p,l);j.stopPropagation();j.preventDefault()});$(this.canvas).mousemove(function(j){if(g.Cb){var l=$(g.canvas).offset();
g.hc(j.pageX-l.left,j.pageY-l.top)}j.stopPropagation();j.preventDefault()});$(window).mouseup(function(){g.Cb=z;g.$a=""});this.La!==u&&$(this.La).change(function(){g.K.b[3]=g.La.value/255;g.update();g.e()})}
va.prototype={fe:function(a){var b=a;if(b.toLowerCase()in ua)b=ua[b.toLowerCase()];var c=/rgba\( *([0-9]+) *, *([0-9]+) *, *([0-9]+) *, *([0-9\.]+) *\)/,d;a=/\#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i.exec(b);if(a!==u){b=parseInt(a[1],16)/255;c=parseInt(a[2],16)/255;d=parseInt(a[3],16)/255;a=1}else{a=c.exec(b);if(a!==u){b=parseFloat(a[1])/255;c=parseFloat(a[2])/255;d=parseFloat(a[3])/255;a=parseFloat(a[4])}else{b=1;c=0;a=d=1}}this.K=(new P(oa,[b,c,d,a])).Ma(qa);if(this.La!==u)this.La.value=
Math.round(this.K.b[3]*255);this.e();this.update()},update:function(){this.Jc&&this.Jc(this.K.toString())},e:function(){this.a.save();this.a.lineWidth=1;this.a.fillStyle="rgb(128, 128, 128)";this.a.fillRect(0,0,this.width,this.height);this.a.putImageData(this.data,0,0);var a=this.K.b[0]/180*Math.PI;this.a.beginPath();var b={x:Math.cos(a)*this.pa/2+this.B/2,y:Math.sin(a)*this.pa/2+this.B/2},c={x:Math.cos(a+2*Math.PI/3)*this.pa/2+this.B/2,y:Math.sin(a+2*Math.PI/3)*this.pa/2+this.B/2},d={x:Math.cos(a+
4*Math.PI/3)*this.pa/2+this.B/2,y:Math.sin(a+4*Math.PI/3)*this.pa/2+this.B/2},e={x:Math.cos(a)*this.B/2+this.B/2,y:Math.sin(a)*this.B/2+this.B/2};a={x:c.x+(d.x-c.x)/2,y:c.y+(d.y-c.y)/2};this.a.moveTo(b.x,b.y);this.a.lineTo(c.x,c.y);this.a.lineTo(d.x,d.y);this.a.lineTo(b.x,b.y);var f=this.a.createLinearGradient(c.x,c.y,d.x,d.y);f.addColorStop(0,"#ffffff");f.addColorStop(1,"#000000");this.a.fillStyle=f;this.a.fill();f=this.a.createLinearGradient(b.x,b.y,a.x,a.y);var h=this.K.Ma(qa);h.b[1]=1;h.b[2]=
1;h=h.Ma(oa);h.b[3]=1;f.addColorStop(0,h.toString());h.b[3]=0;f.addColorStop(1,h.toString());this.a.fillStyle=f;this.a.fill();this.strokeStyle="#000000";this.a.beginPath();this.a.moveTo(b.x,b.y);this.a.lineTo(e.x,e.y);this.a.stroke();f=1-this.K.b[2];e=this.K.b[1]*b.x+f*d.x+(1-this.K.b[1]-f)*c.x;f=this.K.b[1]*b.y+f*d.y+(1-this.K.b[1]-f)*c.y;this.a.beginPath();this.a.arc(e,f,4,0,2*Math.PI,z);this.a.stroke();this.a.restore();this.Xd=b;this.Yd=c;this.Zd=d;this.xe=a},hc:function(a,b){var c=Math.sqrt((a-
this.B/2)*(a-this.B/2)+(b-this.B/2)*(b-this.B/2));if(this.$a==="ring"||this.$a!=="triangle"&&c>=this.pa/2&&c<=this.B/2){this.K.b[0]=Math.atan2(this.B/2-b,this.B/2-a)/Math.PI*180+180;if(this.K.b[1]===0){this.K.b[1]=1;this.K.b[2]=1}this.$a="ring"}else{var d,e=this.Xd;c=this.Yd;var f=this.Zd;d=(e.x-f.x)*(c.y-f.y)-(c.x-f.x)*(e.y-f.y);c=((c.y-f.y)*(a-f.x)-(c.x-f.x)*(b-f.y))/d;d=1-Math.max(0,c)-Math.max(0,(-(e.y-f.y)*(a-f.x)+(e.x-f.x)*(b-f.y))/d);this.K.b[1]=Math.min(Math.max(c,0),1);this.K.b[2]=1-Math.min(Math.max(d,
0),1);this.$a="triangle"}this.e();this.update()}};function wa(a,b,c,d){this.view=a;this.f=b;this.name=c;this.value=d;this.Fc=[];for(a=0;a<this.f.length;a++){b=this.f[a];if(this.name in b)this.Fc[a]=b.S(this.name)}}wa.prototype={execute:function(){for(var a=0;a<this.f.length;a++){var b=this.f[a];if(b.S(this.name)!==undefined){b.setProperty(this.name,this.value);b.t(Q.q.a)}}this.view.e()},N:function(){for(var a=0;a<this.f.length;a++){var b=this.f[a];if(this.name in b){b.setProperty(this.name,this.Fc[a]);b.t(Q.q.a)}}this.view.e()}};
function xa(){this.p=document.createElement("div");$(this.p).addClass("PropertyPanel");this.sb=[];this.tb={};this.view=u;this.f=[];this.action=u}
xa.prototype={Gd:function(a){this.action=u;this.sb.length=0;this.tb={};this.f=a.concat();for(var b=z,c=0;c<a.length;c++){var d=a[c];if(d.wc())b=r;for(var e=d.ka(),f=0;f<e.length;f++)this.Fd(e[f],d)}this.fd();d=$("<div>").addClass("keydiv");$(this.p).append(d);d.append("<h1>Keyboard</h1>");e=[{key:"C",description:"Draw curves"},{key:"L",description:"Draw lines"}];a.length>0&&e.push({key:"Del",description:"Delete Selection"},{key:"Ctrl+D",description:"Duplicate Selection"},{key:"PageUp",description:"Move selection closer"},
{key:"PageDown",description:"Move selection away"});a.length>1&&e.push({key:"Ctrl+G",description:"Group selection"});b&&e.push({key:"Ctrl+Shift+G",description:"Break apart group"});e.push({key:"+",description:"Zoom in"});e.push({key:"-",description:"Zoom out"});e.push({key:"Arrow Keys",description:"Move while zoomed"});for(c=0;c<e.length;c++){a=$("<a>").text(e[c].key).addClass("key");a=$("<p>").append(a);a[0].appendChild(document.createTextNode(e[c].description));d.append(a)}},Fd:function(a,b){var c;
if(a.name in this.tb){c=this.tb[a.name];if(c.value!==b.S(a.name))c.value=u}else{c={ce:a,value:b.S(a.name)};this.sb.push(c);this.tb[a.name]=c}},fd:function(){function a(){f.oe(this)}function b(j){j.keyCode===13&&f.apply(this.Ra.name,this.value)}function c(){f.apply(this.Ra.name,this.Ra.b[parseInt(this.value,10)].value)}$(this.p).empty();var d,e,f=this;for(d=0;d<this.sb.length;d++){var h=this.sb[d],n=h.ce,q=document.createElement("div");e=document.createElement("span");e.appendChild(document.createTextNode(n.display));
q.appendChild(e);q.appendChild(document.createElement("br"));if(n.type==="select"){var k=document.createElement("select");for(e=0;e<n.b.length;e++){var i=n.b[e],g=document.createElement("option");g.appendChild(document.createTextNode(i.name));g.setAttribute("value",e);i.value===h.value&&g.setAttribute("selected","");k.appendChild(g)}k.Ra=n;k.onchange=c;q.appendChild(k)}else if(n.type==="colour"){e=document.createElement("input");e.setAttribute("type","text");e.value=h.value;e.Ra=n;$(e).keydown(b);
q.appendChild(e);h=document.createElement("img");h.src="wd-wheel.png";h.style.verticalAlign="middle";h.input=e;q.appendChild(h);$(h).click(a)}else if(n.type==="text"){e=document.createElement("input");e.setAttribute("type","text");e.value=h.value;e.Ra=n;$(e).keydown(b);q.appendChild(e)}else throw"Error: No such property";this.p.appendChild(q)}},apply:function(a,b){this.view.v.execute(new wa(this.view,this.f,a,b))},oe:function(a){if(!a.Ad){var b=new va(120),c=this;b.fe(a.input.value);b.Jc=function(d){c.cd(d,
a.input,a.input.Ra)};a.Be=b;a.Ad=r;a.parentNode.appendChild(b.p)}},cd:function(a,b,c){if(this.action===u||this.action.name!==c.name){this.action=new wa(this.view,this.f,c.name,a);this.view.v.execute(this.action,r)}this.action.value=a;b.value=a;for(b=0;b<this.f.length;b++){var d=this.f[b];d.setProperty(c.name,a);d.t()}this.view.e()}};function ya(){this.Aa=[];this.next=0;this.$=z}ya.prototype={execute:function(a,b){this.next<this.length&&this.Aa.slice(this.next,this.length-this.next);this.Aa.push(a);b||a.execute();this.$=r;this.next=this.Aa.length},N:function(){if(this.jc()){this.Aa[--this.next].N();this.$=r}},Vb:function(){if(this.ic()){this.Aa[this.next++].execute();this.$=r}},jc:function(){return this.next>0},ic:function(){return this.next<this.Aa.length},clear:function(){this.next=this.Aa.length=0;this.$=z}};function za(){this.Fa=u;this.files=[]}
za.prototype={ca:function(a,b,c){var d;try{d=new XMLHttpRequest}catch(e){try{d=new ActiveXObject("Msxml2.XMLHTTP")}catch(f){try{d=new ActiveXObject("Microsoft.XMLHTTP")}catch(h){d=u}}}d.open("POST",a,r);d.setRequestHeader("Content-Type","application/x-www-form-urlencoded");d.onreadystatechange=function(){if(d.readyState===4){var k={status:"",O:u};if(d.status===200)try{k.O=eval("("+d.responseText+")");k.status=k.O.status}catch(i){alert(i);k.status="Error in server response"}else k.status=d.message?
d.message:d.status===0?"Network error. Check internet connection":"Server returned status "+d.status;c(k)}};a="";var n=r,q;for(q in b)if(b.hasOwnProperty(q)){n||(a+="&");n=z;a+=q+"="+escape(b[q])}d.send(a)},xc:function(){return this.Fa!==u},Nb:function(a,b,c){var d=this;this.ca("index.php",{type:"login",username:a,password:b},function(e){var f=u;if(e.status==="ok"){d.Fa=a;d.files=e.O.files;d.files.sort(function(n,q){return parseInt(q.modificationDate,10)-parseInt(n.modificationDate,10)});f=e.O.mapping;
for(var h=0;h<d.files.length;h++)if(d.files[h].id in f)d.files[h].id=f[d.files[h].id]}c(e.status,f)})},Db:function(a,b,c){this.ca("index.php",{type:"changepassword",oldpassword:a,newpassword:b},function(d){c(d.status)})},hd:function(a,b,c){var d=this;this.ca("index.php",{type:"createuser",username:a,password:b},function(e){if(e.status==="ok"){d.Fa=a;for(var f=e.O.mapping,h=0;h<d.files.length;h++)if(d.files[h].id in f)d.files[h].id=f[d.files[h].id]}c(e.status,e.O.mapping)})},Ob:function(a){var b=this;
this.ca("index.php",{type:"logout"},function(c){if(c.status==="ok"){b.Fa=u;b.files=[]}a(c.status)})},ud:function(a){var b=this;this.ca("index.php",{type:"listfiles"},function(c){if(c.status==="ok"){b.files=c.O.files;b.files.sort(function(d,e){return parseInt(e.modificationDate,10)-parseInt(d.modificationDate,10)})}a(c.status)})},gd:function(a,b,c){var d=this,e=Math.round((new Date).getTime()/1E3);this.ca("index.php",{type:"createfile",name:a,data:b},function(f){if(f.status==="ok"){d.files.unshift({id:f.O.id,
name:a,creationDate:e,modificationDate:e,shared:0});c(f.status,f.O.id)}else c(f.status,-1)})},Xb:function(a,b){var c=this;this.ca("index.php",{type:"updatefile",id:a.id,name:a.name,data:a.data,shared:a.M},function(d){if(d.status==="ok")for(var e=0;e<c.files.length;e++)if(a.id===c.files[e].id){c.files[e].name=a.name;c.files[e].M=a.M}b(d.status)})},kd:function(a,b){var c=this;this.ca("index.php",{type:"deletefile",id:a},function(d){if(d.status==="ok")for(var e=0;e<c.files.length;e++)if(a===c.files[e].id){c.files.splice(e,
1);break}b(d.status)})},Lc:function(a,b){this.ca("index.php",{type:"readfile",id:a},function(c){c.status==="ok"?b(c.status,{id:c.O.id,name:c.O.name,data:c.O.data,M:c.O.shared==="1"?1:0}):b(c.status,u)})},yd:function(a,b,c){this.ca("index.php",{type:"gettemporaryurl",filetype:a,document:b},function(d){d.status==="ok"?c(d.status,{url:d.O.url}):c(d.status,u)})},ge:aa("Fa")};function Aa(a){this.Tc=a}Aa.prototype.print=function(a){a=a.split("\n");for(var b=0;b<a.length;b++){this.Tc.appendChild(document.createTextNode(a[b]));b<a.length-1&&this.Tc.appendChild(document.createElement("br"))}};
Aa.prototype.bb=function(){function a(g,j){g.Ea=j?"":g.Id?"-":g.Ea;var l=g.min-g.C.length+1-g.Ea.length;l=Array(l<0?0:l).join(g.Ub);return g.left?g.Ub==="0"||j?g.Ea+g.C+l.replace(/0/g," "):g.Ea+g.C+l:g.Ub==="0"||j?g.Ea+l+g.C:l+g.Ea+g.C}if(typeof arguments!=="undefined")if(!(arguments.length<1)){var b=arguments;if(b[0]instanceof Array)b=b[0];if(typeof b[0]==="string"){var c=b[0],d=RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g),e=[],f=[],h=0,n=0,q=0;n=0;for(var k="",i=u;;){i=d.exec(c);
if(!i)break;if(i[9])h+=1;n=n;q=d.lastIndex-i[0].length;f[f.length]=c.substring(n,q);n=d.lastIndex;e[e.length]={match:i[0],left:i[3]?r:z,Ea:i[4]||"",Ub:i[5]||" ",min:i[6]||0,rb:i[8],code:i[9]||"%",Id:parseInt(b[h],10)<0?r:z,C:String(b[h])}}f[f.length]=c.substring(n);if(!(b.length-1<h)){c=u;for(c=0;c<e.length;c++){if(e[c].code==="%")b="%";else if(e[c].code==="b"){e[c].C=String(Math.abs(parseInt(e[c].C,10)).toString(2));b=a(e[c],r)}else if(e[c].code==="c"){e[c].C=String(String.fromCharCode(parseInt(Math.abs(parseInt(e[c].C,
10)),10)));b=a(e[c],r)}else if(e[c].code==="d"){e[c].C=String(Math.abs(parseInt(e[c].C,10)));b=a(e[c],z)}else if(e[c].code==="f"){e[c].C=String(Math.abs(parseFloat(e[c].C)).toFixed(e[c].rb?e[c].rb:6));b=a(e[c],z)}else if(e[c].code==="o"){e[c].C=String(Math.abs(parseInt(e[c].C,10)).toString(8));b=a(e[c],z)}else if(e[c].code==="s"){e[c].C=e[c].C.substring(0,e[c].rb?e[c].rb:e[c].C.length);b=a(e[c],r)}else if(e[c].code==="x"){e[c].C=String(Math.abs(parseInt(e[c].C,10)).toString(16));b=a(e[c],z)}else if(e[c].code===
"X"){e[c].C=String(Math.abs(parseInt(e[c].C,10)).toString(16));b=a(e[c],z).toUpperCase()}else b=e[c].match;k+=f[c];k+=b}k+=f[c];this.print(k)}}}};function Ba(a,b){this.x=a;this.y=b}function Fa(a,b,c,d){var e=Math.sqrt((a-c)*(a-c)+(b-d)*(b-d));return{x:c!==a?(c-a)/e:1,y:d!==b?(d-b)/e:0}}function J(a,b,c,d){this.x=a;this.y=b;this.width=c;this.height=d;this.de()}
J.prototype={save:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},clone:function(){return new J(this.x,this.y,this.width,this.height)},yb:function(a){if(a.x<this.x){this.width+=this.x-a.x;this.x=a.x}if(a.y<this.y){this.height+=this.y-a.y;this.y=a.y}if(a.x+a.width>this.x+this.width)this.width+=a.x+a.width-this.x-this.width;if(a.y+a.height>this.y+this.height)this.height+=a.y+a.height-this.y-this.height},db:function(a,b){if(a<this.x){this.width+=this.x-a;this.x=a}else if(a>
this.x+this.width)this.width=a-this.x;if(b<this.y){this.height+=this.y-b;this.y=b}else if(b>this.y+this.height)this.height=b-this.y},contains:function(a){return this.x<=a.x&&this.x+this.width>a.x+a.width&&this.y<=a.y&&this.y+this.height>a.y+a.height},mc:function(a,b){return this.x<=a&&this.x+this.width>a&&this.y<=b&&this.y+this.height>b},de:function(){if(this.width<0){this.x+=this.width;this.width=-this.width}if(this.height<0){this.y+=this.height;this.height=-this.height}},Bd:function(a,b){this.x-=
a/2;this.y-=b/2;this.width+=a;this.height+=b}};function ea(a){var b;if(a instanceof Function)return a;else if(a instanceof Array)b=a.concat();else if(a instanceof Object){b={};for(var c in a)b[c]=ea(a[c])}else b=a;return b}function L(){this.m11=1;this.m21=this.m12=0;this.m22=1;this.w=this.A=0}
L.prototype={save:function(){return{m11:this.m11,m12:this.m12,m21:this.m21,m22:this.m22,dx:this.A,dy:this.w}},multiply:function(a){var b=new L;b.m11=this.m11*a.m11+this.m12*a.m21;b.m21=this.m21*a.m11+this.m22*a.m21;b.m12=this.m11*a.m12+this.m12*a.m22;b.m22=this.m21*a.m12+this.m22*a.m22;b.A=this.m11*a.A+this.m12*a.w+this.A;b.w=this.m21*a.A+this.m22*a.w+this.w;return b},apply:function(a,b){return new Ba(this.m11*a+this.m12*b+this.A,this.m21*a+this.m22*b+this.w)}};
function Ga(a,b,c,d){if(c===undefined){this.m11=a;this.m21=this.m12=0;this.m22=b;this.w=this.A=0}else{this.m11=a;this.m21=this.m12=0;this.m22=b;this.A=c-a*c;this.w=d-b*d}}Ga.prototype=L.prototype;function Ha(a,b,c){var d=Math.cos(a);a=Math.sin(a);this.m11=d;this.m12=a;this.m21=-a;this.m22=d;this.A=-b*d-c*a+b;this.w=b*a-c*d+c}Ha.prototype=L.prototype;function Ia(a,b){this.m11=1;this.m21=this.m12=0;this.m22=1;this.A=a;this.w=b}Ia.prototype=L.prototype;
function Ja(a,b,c,d,e,f,h,n,q,k){var i=(b+d)/2,g=(c+e)/2,j=(d+f)/2,l=(e+h)/2,p=(f+n)/2,v=(h+q)/2,y=(i+j)/2,s=(g+l)/2;j=(j+p)/2;l=(l+v)/2;var m=(y+j)/2,o=(s+l)/2,t=n-b,w=q-c;d=Math.abs((d-n)*w-(e-q)*t);f=Math.abs((f-n)*w-(h-q)*t);if((d+f)*(d+f)<k*(t*t+w*w))a.push(new Ba(m,o));else{Ja(a,b,c,i,g,y,s,m,o,k);Ja(a,m,o,j,l,p,v,n,q,k)}}function Ka(a){this.D=a}
Ka.prototype={clear:function(){for(var a=0;a<this.D.width*this.D.height*4;a++)this.D.data[a]=0},getImageData:ba("D"),width:function(){return this.D.width},height:function(){return this.D.height},get:function(a,b){var c=this.D.width*b*4+a*4;return this.D.data[c]|this.D.data[c+1]<<8|this.D.data[c+2]<<16|this.D.data[c+3]<<24},Ta:function(a,b,c){a=this.D.width*b*4+a*4;this.D.data[a]=c&255;this.D.data[a+1]=c>>8&255;this.D.data[a+2]=c>>16&255;this.D.data[a+3]=c>>24&255},vc:A()};
function La(a,b){this.W=a;this.fb=b;this.data=[]}
La.prototype={width:ba("W"),height:ba("fb"),getImageData:function(){var a=document.createElement("canvas");a.width=this.W;a.height=this.fb;a=a.getContext("2d").getImageData(0,0,this.W,this.fb);for(var b=this.W*this.fb,c=0;c<b;c++){var d=this.data[c]===r?255:0;a.data[c*4]=d;a.data[c*4+1]=d;a.data[c*4+2]=d;a.data[c*4+3]=255}return a},get:function(a,b){return this.data[this.W*b+a]===r},Ta:function(a,b,c){this.data[this.W*b+a]=c},vc:function(a,b,c){c=this.W*a+c;for(a=this.W*a+b;a<c;a++)this.data[a]=!this.data[a]},
nd:function(){for(var a=0;a<this.data.length-1;a++)if(this.data[a+1])return{x:a%this.W,y:Math.floor(a/this.W)};return u}};function Ma(){this.closed=z;this.h=[]}var Na=[3,3,7,1],Oa=[1,1,3,0];
Ma.prototype={save:function(){var a={};a.strokeStyle=this.strokeStyle;a.fillStyle=this.fillStyle;a.lineWidth=this.lineWidth;a.d=this.h.concat();return a},load:function(a){this.h=a.d;this.strokeStyle=a.strokeStyle;this.fillStyle=a.fillStyle;this.lineWidth=a.lineWidth},moveTo:function(a,b){this.h.push(0,a,b)},lineTo:function(a,b){this.h.push(1,a,b)},bezierCurveTo:function(a,b,c,d,e,f){this.h.push(2,a,b,c,d,e,f)},close:function(){this.h.push(4)},e:function(a){for(var b=0;b<this.h.length;){switch(this.h[b]){case 0:a.moveTo(this.h[b+
1],this.h[b+2]);break;case 1:a.lineTo(this.h[b+1],this.h[b+2]);break;case 2:a.bezierCurveTo(this.h[b+1],this.h[b+2],this.h[b+3],this.h[b+4],this.h[b+5],this.h[b+6]);break;case 4:a.closePath();break;default:alert("Error!")}b+=Na[this.h[b]]}if(this.lineWidth!==undefined)a.lineWidth=this.lineWidth;if(this.fillStyle!==undefined)a.fillStyle=this.fillStyle;if(this.strokeStyle!==undefined)a.strokeStyle=this.strokeStyle;a.fill()},transform:function(a){for(var b=0,c,d;b<this.h.length;){d=Oa[this.h[b]];console.log("pos=%d numPoints=%d",
b,d);for(c=0;c<d;c++){var e=a.apply(this.h[b+1+c*2],this.h[b+1+c*2+1]);this.h[b+1+c*2]=e.x;this.h[b+1+c*2+1]=e.y}b+=Na[this.h[b]]}},clone:function(){var a=new Ma;a.h=this.h.concat();a.fillStyle=this.fillStyle;a.strokeStyle=this.strokeStyle;return a},gc:function(a){for(var b=0,c,d,e=new J(this.h[1],this.h[2],0,0);b<this.h.length;){switch(this.h[b]){case 0:case 1:c=this.h[b+1];d=this.h[b+2];e.db(c,d);break;case 2:var f=[],h=f,n=this.h[b+5],q=this.h[b+6];c!==n&&d!==q&&Ja(h,c,d,this.h[b+1],this.h[b+2],
this.h[b+3],this.h[b+4],n,q,a*a);h.push(new Ba(n,q));for(h=0;h<f.length;h++)e.db(f[h].x,f[h].y)}b+=Na[this.h[b]]}return e},append:function(a){this.h=this.h.concat(a.h)}};function R(a,b){this.I(a,b)}var S={strokeStyle:"#000000",fillStyle:"#ffffff",lineWidth:2,smoothness:0.3,sloppiness:0.5,shadow:z};
R.prototype={Ia:1,Ha:2,eb:3,Wa:0.5522847498,ka:function(){var a=[];this.closed&&a.push({name:"fillStyle",display:"Fill Colour",type:"colour"});a.push({name:"strokeStyle",display:"Outline Colour",type:"colour"});a.push({name:"lineWidth",display:"Outline Thickness",type:"select",b:[{name:"None",value:0},{name:"Pencil",value:1},{name:"Pen",value:2},{name:"Marker",value:4}]});this.i.length>0&&this.i[0].type===this.Ha?a.push({name:"smoothness",display:"Smoothness",type:"select",b:[{name:"Sharper",value:0.1},
{name:"Sharp",value:0.2},{name:"Smooth",value:0.3},{name:"Smoothest",value:0.5}]}):a.push({name:"sloppiness",display:"Sloppiness",type:"select",b:[{name:"Draftsman",value:0},{name:"Artist",value:0.25},{name:"Cartoonist",value:0.5},{name:"Child",value:1},{name:"Drunk",value:2}]});a.push({name:"shadow",display:"Shadow",type:"select",b:[{name:"Shadow",value:r},{name:"None",value:z}]});if(this.closed)a=a.concat(this.L.ka());return a},S:function(a){return a in S||!this.closed?this[a]:this.L.S(a)},setProperty:function(a,
b){if(a in S||!this.closed){S[a]=b;this[a]=b}else this.L.setProperty(a,b)},I:function(a,b){this.F.I.apply(this);this.strokeStyle=S.strokeStyle;this.fillStyle=S.fillStyle;this.lineWidth=S.lineWidth;this.smoothness=S.smoothness;this.sloppiness=S.sloppiness;this.shadow=S.shadow;this.ea=a;this.fa=b;this.n=a;this.o=b;this.i=[];this.closed=z;this.L=new ja("");this.L.path=this},load:function(a){this.F.load.apply(this,[a]);this.strokeStyle=a.strokeStyle;this.fillStyle=a.fillStyle;this.lineWidth=a.lineWidth;
this.smoothness=a.smoothness;this.sloppiness=a.sloppiness;this.shadow=a.shadow;this.ea=a.startX;this.fa=a.startY;this.n=this.ea;this.o=this.fa;this.closed=a.closed;for(var b=this.i.length=0;b<a.segments.length;b++){var c=a.segments[b],d={ha:0,ia:0,Y:0,Z:0,type:c.type,x:c.x,y:c.y};if(c.r!==undefined)d.Q=c.r;if(c.x1!==undefined){d.na=c.x1;d.ua=c.y1}this.i.push(d)}if(a.textNode!==undefined){this.L=N(a.textNode);this.L.path=this}},save:function(){var a=this.F.save.apply(this);a.type="PathNode";a.strokeStyle=
this.strokeStyle;a.fillStyle=this.fillStyle;a.lineWidth=this.lineWidth;a.smoothness=this.smoothness;a.sloppiness=this.sloppiness;a.startX=this.ea;a.startY=this.fa;a.closed=this.closed;a.segments=[];a.shadow=this.shadow;for(var b=0;b<this.i.length;b++){var c=this.i[b],d={};d.type=c.type;if(c.type===this.Ia){d.x=c.x;d.y=c.y;d.r=c.Q}else if(c.type===this.Ha){d.x=c.x;d.y=c.y}else if(c.type===this.eb){d.x=c.x;d.y=c.y;d.x1=c.na;d.y1=c.ua;d.r=c.Q}a.segments.push(d)}if(this.L.S("text")!=="")a.textNode=this.L.save();
return a},clear:function(){this.i.length=0;this.closed=z},mb:function(){return this.i.length+1},ub:function(a){a===0&&alert("error");this.i.splice(a-1,1)},lineTo:function(a,b){this.i.push({type:this.Ia,x:a,y:b,ha:0,ia:0,Y:0,Z:0,Q:[Math.random(),Math.random(),Math.random(),Math.random()]})},Ya:function(a,b){this.i.push({type:this.Ha,x:a,y:b,ha:0,ia:0,Y:0,Z:0,length:0})},hb:function(a,b,c,d){this.i.push({type:this.eb,na:a,ua:b,x:c,y:d,ha:0,ia:0,Y:0,Z:0,Q:[Math.random()-0.5,Math.random()-0.5,Math.random()-
0.5,Math.random()-0.5]})},xd:function(a){if(a){a=this.i[0];return a.type===this.Ia?Fa(a.x,a.y,a.n,a.o):Fa(a.ha,a.ia,a.x,a.y)}else{a=this.i[this.i.length-1];return a.type===this.Ia?Fa(a.fx,a.sd,a.n,a.o):Fa(a.Y,a.Z,a.n,a.o)}},td:function(){var a=this.i[this.i.length-1];return{x:a.n,y:a.o}},t:function(a){var b=this.u.apply(this.ea,this.fa);this.n=b.x;this.o=b.y;var c=b.x;b=b.y;var d=u,e;if(this.closed&&this.i.length>0){e=this.i[this.i.length-1];e.x=this.ea;e.y=this.fa}for(var f=0;f<this.i.length;f++){e=
this.i[f];if(e.type===this.Ia)this.pd(d,c,b,e);else if(e.type===this.Ha)this.qc(d,c,b,e);else e.type===this.eb&&this.od(d,c,b,e);d=e;c=e.n;b=e.o}this.closed&&this.i.length>=3&&this.i[0].type===this.Ha&&this.qc(d,d.n,d.o,this.i[0],r);this.rect.x=this.n;this.rect.y=this.o;this.rect.width=0;this.rect.height=0;this.pb=this.ad(16);c=this.pb;if(c.length===0)c=new J(0,0,0,0);else{b=c[0].x;d=c[0].x;e=c[0].y;f=c[0].y;for(var h=1;h<c.length;h++){if(c[h].x<b)b=c[h].x;if(c[h].x>d)d=c[h].x;if(c[h].y<e)e=c[h].y;
if(c[h].y>f)f=c[h].y}c=new J(b,e,d-b,f-e)}this.rect=c;this.rect.Bd(this.lineWidth*2+1,this.lineWidth*2+1);if(this.rect.width<8){this.rect.x+=this.rect.width/2-4;this.rect.width=8}if(this.rect.height<8){this.rect.y+=this.rect.height/2-4;this.rect.height=8}if(this.closed){c=this.pb;if(c.length===0)c=new Ba(0,0);else{b=c[0].x;d=c[0].y;for(e=1;e<c.length;e++){b+=c[e].x;d+=c[e].y}c=new Ba(b/c.length,d/c.length)}this.L.t(a);this.L.transform(new Ia(c.x-this.L.rect.x-this.L.rect.width/2,c.y-this.L.rect.y-
this.L.rect.height/2))}},close:function(){this.closed=r},fc:function(){var a=this.i[this.i.length-1];Math.sqrt((a.x-this.ea)*(a.x-this.ea)+(a.y-this.fa)*(a.y-this.fa))<=8&&this.close()},e:function(a){var b;a.save();a.lineWidth=this.lineWidth;a.strokeStyle=this.strokeStyle;a.fillStyle=this.fillStyle;a.lineJoin="round";if(this.shadow){a.shadowOffsetX=3;a.shadowOffsetY=3;a.shadowBlur=5;a.shadowColor="rgba(0,0,0,0.5)"}a.beginPath();a.moveTo(this.n,this.o);for(b=0;b<this.i.length;b++){var c=this.i[b];
a.bezierCurveTo(c.ha,c.ia,c.Y,c.Z,c.n,c.o)}if(this.closed){a.closePath();a.fill();a.shadowColor="rgba(0,0,0,0)"}this.lineWidth>0&&a.stroke();a.restore();this.closed&&this.L.e(a)},Za:ca(r),Pa:function(a,b,c){c=8*c;if(a>=this.n-c&&a<this.n+c&&b>=this.o-c&&b<this.o+c)return 0;for(var d=this.closed?this.i.length-1:this.i.length,e=0;e<d;e++)if(a>=this.i[e].n-c&&a<this.i[e].n+c&&b>=this.i[e].o-c&&b<this.i[e].o+c)return e+1;return u},da:function(a,b,c){if(a===0){this.ea=b;this.fa=c}else{this.i[a-1].x=b;
this.i[a-1].y=c}},Na:function(a,b){a.save();a.lineWidth=1*b;a.strokeStyle="#0050B7";var c=4*b;a.strokeRect(this.n-c,this.o-c,c*2,c*2);var d=this.i.length;if(this.closed)d-=1;for(var e=0;e<d;e++)a.strokeRect(this.i[e].n-c,this.i[e].o-c,c*2,c*2);a.restore()},od:function(a,b,c,d){var e=this.u.apply(d.x,d.y);d.n=e.x;d.o=e.y;e=this.u.apply(d.na,d.ua);a=e.x;e=e.y;var f=Math.sqrt((a-b)*(a-b)+(e-c)*(e-c)),h=Math.sqrt((a-d.n)*(a-d.n)+(e-d.o)*(e-d.o));d.ha=b+this.Wa*(a-b)+d.Q[0]*this.sloppiness*f/2;d.ia=c+
this.Wa*(e-c)+d.Q[1]*this.sloppiness*f/2;d.Y=d.n+this.Wa*(a-d.n)+d.Q[2]*this.sloppiness*h/1.5;d.Z=d.o+this.Wa*(e-d.o)+d.Q[3]*this.sloppiness*h/1.5},qc:function(a,b,c,d,e){var f=this.u.apply(d.x,d.y);d.n=f.x;d.o=f.y;d.length=Math.sqrt((d.n-b)*(d.n-b)+(d.o-c)*(d.o-c));if(!d.length)d.length=1;d.Yb=(d.n-b)/d.length;d.Wc=(d.o-c)/d.length;f=d.Yb;var h=d.Wc;if(!e){d.Y=d.n-d.length*this.smoothness*f;d.Z=d.o-d.length*this.smoothness*h}if(a&&a.Yb!==undefined){f=(f+a.Yb)*0.5;h=(h+a.Wc)*0.5;a.Y=b-a.length*this.smoothness*
f;a.Z=c-a.length*this.smoothness*h}d.ha=b+d.length*this.smoothness*f;d.ia=c+d.length*this.smoothness*h},pd:function(a,b,c,d){a=this.u.apply(d.x,d.y);d.n=a.x;d.o=a.y;a=Math.sqrt((d.n-b)*(d.n-b)+(d.o-c)*(d.o-c))/10*this.sloppiness;if(a>20)a=20;d.n+=this.sloppiness*d.Q[0]*a/4;d.o+=this.sloppiness*d.Q[1]*a/4;d.fx=b;d.sd=c;var e=b,f=c,h=d.n,n=d.o;e+=a;h+=a;f+=a;n+=a;d.ha=e+d.Q[2]*(h-e);d.ia=f+d.Q[2]*(n-f);e=b-a;h=d.n-a;f=c-a;n=d.o-a;d.Y=e+d.Q[3]*(h-e);d.Z=f+d.Q[3]*(n-f)},aa:function(){var a;a=this.u.apply(this.ea,
this.fa);this.ea=a.x;this.fa=a.y;for(var b=0;b<this.i.length;b++){var c=this.i[b];a=this.u.apply(c.x,c.y);c.x=a.x;c.y=a.y;if(c.na!==undefined){a=this.u.apply(c.na,c.ua);c.na=a.x;c.ua=a.y}}this.u=new L;this.L.aa();this.t()},transform:function(a){this.u=a.multiply(this.u)},Da:aa("u"),ba:function(a,b){if(a>=this.rect.x-8&&a<this.rect.x+8+this.rect.width&&b>=this.rect.y-8&&b<this.rect.y+8+this.rect.height)if(this.closed){var c;c=this.pb;var d,e,f,h,n,q,k,i,g=0;if(c.length<3)c=0;else{f=c[c.length-1].x;
h=c[c.length-1].y;for(i=0;i<c.length;i++){d=c[i].x;e=c[i].y;if(d>f){n=f;k=d;q=h;h=e}else{n=d;k=f;q=e;h=h}if(d<a===a<=f&&(b-q)*(k-n)<(h-q)*(a-n))g=!g;f=d;h=e}c=g}if(c)return this}else{a:{c=this.pb;d=8;d*=d;for(e=1;e<c.length;e++){k=c[e-1].x;f=c[e-1].y;i=c[e].x-k;n=c[e].y-f;q=((a-k)*i+(b-f)*n)/(i*i+n*n);if(q>1)q=1;else if(q<0)q=0;k=k+q*i-a;f=f+q*n-b;if(k*k+f*f<=d){c=r;break a}}c=z}if(c)return this}return u},ad:function(a){var b=[];b.push({x:this.n,y:this.o,ye:0});for(var c=this.n,d=this.o,e=0;e<this.i.length;e++){var f=
this.i[e],h=b,n=f.n,q=f.o;c!==n&&d!==q&&Ja(h,c,d,f.ha,f.ia,f.Y,f.Z,n,q,a*a);h.push(new Ba(n,q));c=f.n;d=f.o}return b}};R.prototype=$.extend({},G.prototype,R.prototype);R.prototype.F=G.prototype;window.PathNode=R;function Pa(a,b){this.I(a,b)}var Ra={arrowSize:15};
Pa.prototype={I:function(a,b){this.F.I.apply(this);this.arrowSize=Ra.arrowSize;this.c=[new R(a,b),new R(0,0)]},load:function(a){this.F.load.apply(this,[a]);this.arrowSize=a.arrowSize;this.c.length=0;this.c.push(N(a.path));this.c.push(new R(0,0));this.c[1].dd(this.c[0])},save:function(){var a=this.F.save.apply(this);a.type="ArrowNode";a.arrowSize=this.arrowSize;a.path=this.c[0].save();return a},ba:function(a,b){var c;for(c=0;c<this.c.length;c++)if(this.c[c].ba(a,b))return this;return u},t:function(a){var b,
c,d=this.c[1];this.c[0].t(a);b=this.c[0].td();c=this.c[0].xd(z);var e,f,h,n;e=b.x-c.x*this.arrowSize;f=b.y-c.y*this.arrowSize;h=e+c.y*this.arrowSize/2;n=f-c.x*this.arrowSize/2;e+=-c.y*this.arrowSize/2;f+=c.x*this.arrowSize/2;d.clear();d.u=new L;d.da(0,e,f);d.Ya(b.x,b.y);d.Ya(h,n);d.t(a);this.rect.x=this.c[0].rect.x;this.rect.y=this.c[0].rect.y;this.rect.width=this.c[0].rect.width;this.rect.height=this.c[0].rect.height;for(a=1;a<this.c.length;a++)this.rect.yb(this.c[a].rect)},transform:function(a){for(var b=
0;b<this.c.length;b++)this.c[b].transform(a)},aa:function(){var a;for(a=0;a<this.c.length;a++)this.c[a].aa()},e:function(a){var b;for(b=0;b<this.c.length;b++)this.c[b].e(a)},lineTo:function(a,b){this.c[0].lineTo(a,b)},Ya:function(a,b){this.c[0].Ya(a,b)},fc:A(),mb:function(){return this.c[0].mb()},ub:function(a){this.c[0].ub(a)},Za:ca(r),Pa:function(a,b,c){return this.c[0].Pa(a,b,c)},da:function(a,b,c){this.c[0].da(a,b,c)},Na:function(a,b){this.c[0].Na(a,b)},Hb:function(){return this.c[0].u},Da:function(a){this.c[0].Da(a)},
setProperty:function(a,b){if(a==="arrowSize")this.arrowSize=Ra[a]=b;else{this.c[0].setProperty(a,b);this.c[1].setProperty(a,b)}},S:function(a){return a==="arrowSize"?this.arrowSize:this.c[0].S(a)},Sa:[{name:"arrowSize",display:"Arrow Head Size",type:"select",b:[{name:"Tiny",value:10},{name:"Small",value:15},{name:"Medium",value:20},{name:"Large",value:30}]}],ka:function(){return this.c[0].ka().concat(this.Sa)}};Pa.prototype=$.extend({},G.prototype,Pa.prototype);Pa.prototype.F=G.prototype;
window.ArrowNode=Pa;function N(a){var b;if(a.type==="Node"||a.type==="ImageNode")a.type="BaseNode";try{b=new window[a.type]}catch(c){alert(a.type+": "+c)}b.load(a);return b}function Sa(){this.l=new G}Sa.prototype={lc:function(a){for(var b=[],c={},d=0;d<a.length;d++){var e=a[d];if(e.wc())e=e.parent;if(!(e.id in c)){c[e.id]=r;b.push(e)}}return b}};function Ta(a,b){function c(m,o){s.bezierCurveTo(o[1].x,o[1].y,o[2].x,o[2].y,o[3].x,o[3].y);Ua.bb("Bezier: (%d,%d), (%d,%d), (%d,%d), (%d,%d)\n",o[0].x,o[0].y,o[1].x,o[1].y,o[2].x,o[2].y,o[3].x,o[3].y)}function d(m,o){return m.x*o.x+m.y*o.y}function e(m){var o=1-m;return 3*m*o*o}function f(m,o){var t=m.x-o.x,w=m.y-o.y;return Math.sqrt(t*t+w*w)}function h(m){return m.x*m.x+m.y*m.y}function n(m,o){var t=Math.sqrt(h(m));if(t!==0){m.x*=o/t;m.y*=o/t}return m}function q(m,o,t){t===undefined&&Ua.bb("Undef!");
t.x=m.x+o.x;t.y=m.y+o.y;return t}function k(m,o){return{x:m.x+o.x,y:m.y+o.y}}function i(m,o){return{x:m.x*o,y:m.y*o}}function g(m,o){return{x:m.x-o.x,y:m.y-o.y}}function j(m,o,t,w,D,I){var x,E=[],M,B=[[],[]],C=[],H,K;K=[{},{},{},{}];M=t-o+1;for(x=0;x<M;x++){H={x:D.x,y:D.y};var ia={x:I.x,y:I.y};n(H,e(w[x]));n(ia,3*w[x]*w[x]*(1-w[x]));E[x]=[H,ia]}B[0][0]=0;B[0][1]=0;B[1][0]=0;B[1][1]=0;C[0]=0;for(x=C[1]=0;x<M;x++){B[0][0]+=d(E[x][0],E[x][0]);B[0][1]+=d(E[x][0],E[x][1]);B[1][0]=B[0][1];B[1][1]+=d(E[x][1],
E[x][1]);H=1-w[x];H=g(m[o+x],k(i(m[o],H*H*H),k(i(m[o],e(w[x])),k(i(m[t],3*w[x]*w[x]*(1-w[x])),i(m[t],w[x]*w[x]*w[x])))));C[0]+=d(E[x][0],H);C[1]+=d(E[x][1],H)}w=B[0][0]*B[1][1]-B[1][0]*B[0][1];x=B[0][0]*C[1]-B[0][1]*C[0];C=C[0]*B[1][1]-C[1]*B[0][1];if(w===0)w=B[0][0]*B[1][1]*1.0E-11;B=C/w;C=x/w;if(B<0||C<0){B=f(m[t],m[o])/3;K[0]=m[o];K[3]=m[t];q(K[0],n(D,B),K[1]);q(K[3],n(I,B),K[2]);return K}K[0]=m[o];K[3]=m[t];q(K[0],n(D,B),K[1]);q(K[3],n(I,C),K[2]);return K}function l(m,o,t){var w,D;D=[];for(w=
0;w<=m;w++)D[w]={x:o[w].x,y:o[w].y};for(w=1;w<=m;w++)for(o=0;o<=m-w;o++){D[o].x=(1-t)*D[o].x+t*D[o+1].x;D[o].y=(1-t)*D[o].y+t*D[o+1].y}return D[0]}function p(m){var o=Math.sqrt(Math.sqrt(h(m)));if(o!==0){m.x/=o;m.y/=o}return m}function v(m,o,t,w,D){var I,x,E,M=(t-o+1)/2;x=0;for(I=o+1;I<t;I++){E=l(3,w,D[I-o]);E=g(E,m[I]);E=h(E);if(E>=x){x=E;M=I}}return{zc:x,Rc:M}}function y(m,o,t,w,D,I){var x,E,M,B,C,H;x=[{},{},{},{}];H=I*I;if(t-o+1===2){I=f(m[t],m[o])/3;x[0]=m[o];x[3]=m[t];q(x[0],n(w,I),x[1]);q(x[3],
n(D,I),x[2]);c(3,x)}else{B=[];B[0]=0;for(C=o+1;C<=t;C++)B[C-o]=B[C-o-1]+f(m[C],m[C-1]);for(C=o+1;C<=t;C++)B[C-o]/=B[t-o];E=B;x=j(m,o,t,E,w,D);C=v(m,o,t,x,E);B=C.zc;C=C.Rc;if(B<I)c(3,x);else{if(B<H)for(H=0;H<4;H++){C=m;B=o;M=t;E=E;x=x;var K=void 0,ia=[];ia=[];for(K=B;K<=M;K++){var zb=ia,Ab=K-B,sa=x,Ca=C[K],Da=E[K-B],W=[],Ea=[],ta=void 0,F=void 0,Qa=void 0;F=void 0;ta=l(3,sa,Da);for(F=0;F<=2;F++){W[F]={};W[F].x=(sa[F+1].x-sa[F].x)*3;W[F].y=(sa[F+1].y-sa[F].y)*3}for(F=0;F<=1;F++){Ea[F]={};Ea[F].x=(W[F+
1].x-W[F].x)*2;Ea[F].y=(W[F+1].y-W[F].y)*2}F=l(2,W,Da);Qa=l(1,Ea,Da);zb[Ab]=Da-((ta.x-Ca.x)*F.x+(ta.y-Ca.y)*F.y)/(F.x*F.x+F.y*F.y+(ta.x-Ca.x)*Qa.x+(ta.y-Ca.y)*Qa.y)}M=ia;x=j(m,o,t,M,w,D);C=v(m,o,t,x,M);B=C.zc;C=C.Rc;if(B<I){c(3,x);return}E=M}M={};H=g(m[C-1],m[C]);B=g(m[C],m[C+1]);M.x=(H.x+B.x)/2;M.y=(H.y+B.y)/2;H=M=p(M);y(m,o,C,w,H,I);H.x=-H.x;H.y=-H.y;y(m,C,t,H,D,I)}}}var s=new Ma;s.moveTo(a[0].x,a[0].y);(function(m,o,t){var w;w=g(m[1],m[0]);w=w=p(w);var D=o-1;D=g(m[D-1],m[D]);D=p(D);y(m,0,o-1,w,
D,t)})(a,a.length,b*b);return s};function Va(a){var b=document.createElement("canvas");b.width=a.width;b.height=a.height;b.getContext("2d").putImageData(a,0,0);b.style.borderWidth="1px";b.style.borderColor="#000000";b.style.borderStyle="solid";document.getElementById("debug").appendChild(b)}
function Wa(a,b,c,d,e){function f(k,i){var g,j,l;i=i.concat();i.sort(function(p,v){return p.y!==v.y?p.y-v.y:p.x-v.x});for(l=0;l<i.length-1;l++){for(;l<i.length&&i[l].qa!==1;)l+=1;for(g=l;l<i.length&&i[l].qa!==-1;)l+=1;j=l;j<i.length&&k.vc(i[g].y,i[g].x+1,i[j].x)}}function h(k){k.width();k.height();var i,g,j=1,l=0,p=[];g=k.nd();if(g===u)return u;i=g.x;g=g.y;var v,y,s,m;v=k.get(i+j,g+l);y=k.get(i+j+l,g+l+j);s=k.get(i,g);m=k.get(i+l,g+j);if(v&&y&&!s&&m){g+=1;j=-1;l=0}else if(v&&y&&!s&&!m){i+=1;l=1;j=
0}else if(v&&!y&&!s&&!m){i+=1;j=0;l=1}var o=i,t=g,w=j,D=l;p.push({x:i-l,y:g+j,qa:l});for(var I=0;;I++){v=k.get(i+j,g+l);y=k.get(i+j-l,g+l+j);s=k.get(i,g);m=k.get(i-l,g+j);if(v&&y&&s&&!m){i+=j;g+=l;v=l;l=j;j=-v;i+=j;g+=l;if(i===o&&g===t)break;p.push({x:i-l,y:g+j,qa:l})}else if(v&&s&&!y&&!m){i+=j;g+=l;if(i===o&&g===t)break;p.push({x:i-l,y:g+j,qa:l})}else if(!v&&!y&&s&&!m){v=l;l=-j;j=v;p.push({x:i-l,y:g+j,qa:l});if(w===j&&D===l&&i===o&&g===t)break}else if(!v&&y&&s&&!m){v=l;l=-j;j=v;p.push({x:i-l,y:g+
j,qa:l})}else{Ua.bb("Unknown situation: %s %s %s %s\n",v,y,s,m);break}}i=p;j=[i[0]];for(l=1;l<i.length;l++)if(i[l].x!==i[l-1].x||i[l].y!==i[l-1].y)j.push(i[l]);else j[j.length-1].qa+=i[l].qa;p=j;p.length>2&&p[0].x===p[p.length-1].x&&p[0].y===p[p.length-1].y&&p.pop();f(k,p);return p}b=Math.floor(b);c=Math.floor(c);var n=new Ka(a.getImageData(0,0,d,e));Va(n.getImageData());d=new La(d,e);console.log("flood fill");(function(k,i,g,j){function l(D,I,x,E){D+E>=t.Yc&&D+E<=t.ua&&o.push({y:D,qe:I,re:x,w:E})}
var p,v,y,s,m,o=[];p=0;var t={Xc:0,Yc:0,na:k.width()+1,ua:k.height()+1};m=k.get(g,j);var w=m===0?m+1:m-1;w=4278222848;if(!(m===w||g<t.Xc||g>t.na||j<t.Yc||j>t.ua)){l(j,g,g,1);for(l(j+1,g,g,-1);o.length>0;){p=o.pop();s=p.w;j=p.y+s;v=p.qe;y=p.re;for(g=v;g>=t.Xc&&k.get(g,j)===m;g--){k.Ta(g,j,w);i.Ta(g,j,r)}if(g<v){p=g+1;p<v&&l(j,p,v-1,-s);g=v+1}else{for(g++;g<=y&&k.get(g,j)!==m;g++);if(g>y)continue;p=g}do{for(;g<=t.na&&k.get(g,j)===m;g++){k.Ta(g,j,w);i.Ta(g,j,r)}l(j,p,g-1,s);g>y+1&&l(j,y+1,g-1,-s);for(g++;g<=
y&&k.get(g,j)!==m;g++);p=g}while(g<=y)}}})(n,d,b,c);Va(n.getImageData());Va(d.getImageData());b=new Ma;for(c=0;;c++){console.log("tracing...");if(c>100)throw"Trace limit exceeded";e=h(d);if(e===u||e.length===0)break;c>0&&e.reverse();Va(d.getImageData());Ua.bb("NumPoints=%d\n",e.length);for(var q=0;q<e.length;q++){Ua.bb("(%d,%d)\n",e[q].x,e[q].y);n.Ta(e[q].x,e[q].y,4294901760)}a.lineWidth=2;a.strokeStyle="#800000";a.beginPath();e=Ta(e,1);b.append(e)}Va(n.getImageData());b.fillStyle="#800000";return b}
;function Xa(a){this.I(a)}var Ya={blur:5};
Xa.prototype={I:function(a){this.F.I.apply(this);this.blur=Ya.blur;this.G=a;this.canvas=document.createElement("canvas")},load:function(a){this.F.load.apply(this,[a]);this.blur=a.blur;this.G=N(a.child)},save:function(){var a=this.F.save.apply(this);a.type="EffectNode";a.blur=this.blur;a.child=this.G.save();return a},uc:function(){return this.blur>0},ba:function(a,b){if(this.G.ba(a,b))return this},t:function(a){if(this.uc()){this.G.t(this.canvas.getContext("2d"));var b=this.blur*2,c=this.G.rect;this.rect.x=
c.x-b;this.rect.y=c.y-b;this.rect.width=c.width+b*2;this.rect.height=c.height+b*2;this.canvas.width=this.rect.width;this.canvas.height=this.rect.height;a=this.canvas.getContext("2d");a.save();a.translate(-c.x+b,-c.y+b);this.G.e(a);a.restore();b=a.getImageData(0,0,this.canvas.width,this.canvas.height);c=this.blur;var d=b.width,e=b.height,f=[],h=b.data,n=1/(c*2*c*2),q,k;for(k=0;k<3;k++)for(q=0;q<4;q++){var i,g,j,l=0;l=q;g=j=1;for(f[0]=h[l];j<d;){f[j]=h[l]+f[j-1];j+=1;l+=4}for(;g<e;){f[j]=h[l]+f[j-d];
j++;l+=4;for(i=1;i<d;){f[j]=h[l]+f[j-d]+f[j-1]-f[j-d-1];i++;j++;l+=4}g++}l=c*d*4+c*4+q;for(g=c;g<e-c;g++){for(i=c;i<d-c;i++){j=i<c?0:i-c;var p=g<c?0:g-c,v=i+c>=d?d-1:i+c,y=g+c>=e?e-1:g+c;j=f[v+y*d]+f[j+p*d]-f[j+y*d]-f[v+p*d];h[l]=Math.round(j*n);l+=4}l+=c*2*4}}a.putImageData(b,0,0)}else this.G.t(a)},transform:function(a){this.G.transform(a)},aa:function(){this.G.aa()},e:function(a){this.uc()?a.drawImage(this.canvas,this.rect.x,this.rect.y):this.G.e(a)},Za:function(){return this.G.Za()},Pa:function(a,
b,c){return this.G.Pa(a,b,c)},da:function(a,b,c){this.G.da(a,b,c)},Na:function(a,b){this.G.Na(a,b)},Hb:function(){return this.G.u},Da:function(a){this.G.Da(a)},setProperty:function(a,b){if(a==="blur")this.blur=Ya[a]=b;else this.G.setProperty(a,b)},S:function(a){return a==="blur"?this.blur:this.G.S(a)},Sa:[{name:"blur",display:"Blur radius",type:"select",b:[{name:"None",value:0},{name:"Blur",value:5},{name:"Blur Lots",value:30}]}],ka:function(){return this.G.ka().concat(this.Sa)}};
Xa.prototype=$.extend({},G.prototype,Xa.prototype);Xa.prototype.F=G.prototype;window.EffectNode=Xa;if(!window.JSON)window.JSON={};
(function(){function a(k){return k<10?"0"+k:k}function b(k){e.lastIndex=0;return e.test(k)?'"'+k.replace(e,function(i){var g=n[i];return typeof g==="string"?g:"\\u"+("0000"+i.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+k+'"'}function c(k,i){var g,j,l,p,v=f,y,s=i[k];if(s&&typeof s==="object"&&typeof s.toJSON==="function")s=s.toJSON(k);if(typeof q==="function")s=q.call(i,k,s);switch(typeof s){case "string":return b(s);case "number":return isFinite(s)?String(s):"null";case "boolean":case "null":return String(s);
case "object":if(!s)return"null";f+=h;y=[];if(Object.prototype.toString.apply(s)==="[object Array]"){p=s.length;for(g=0;g<p;g+=1)y[g]=c(g,s)||"null";l=y.length===0?"[]":f?"[\n"+f+y.join(",\n"+f)+"\n"+v+"]":"["+y.join(",")+"]";f=v;return l}if(q&&typeof q==="object"){p=q.length;for(g=0;g<p;g+=1){j=q[g];if(typeof j==="string")if(l=c(j,s))y.push(b(j)+(f?": ":":")+l)}}else for(j in s)if(Object.hasOwnProperty.call(s,j))if(l=c(j,s))y.push(b(j)+(f?": ":":")+l);l=y.length===0?"{}":f?"{\n"+f+y.join(",\n"+f)+
"\n"+v+"}":"{"+y.join(",")+"}";f=v;return l}}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+a(this.getUTCMonth()+1)+"-"+a(this.getUTCDate())+"T"+a(this.getUTCHours())+":"+a(this.getUTCMinutes())+":"+a(this.getUTCSeconds())+"Z":u};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var d=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
e=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,f,h,n={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},q;if(typeof window.JSON.stringify!=="function")window.JSON.stringify=function(k,i,g){var j;h=f="";if(typeof g==="number")for(j=0;j<g;j+=1)h+=" ";else if(typeof g==="string")h=g;if((q=i)&&typeof i!=="function"&&(typeof i!=="object"||typeof i.length!=="number"))throw Error("JSON.stringify");
return c("",{"":k})};if(typeof window.JSON.parse!=="function")window.JSON.parse=function(k,i){function g(l,p){var v,y,s=l[p];if(s&&typeof s==="object")for(v in s)if(Object.hasOwnProperty.call(s,v)){y=g(s,v);if(y!==undefined)s[v]=y;else delete s[v]}return i.call(l,p,s)}var j;k=String(k);d.lastIndex=0;if(d.test(k))k=k.replace(d,function(l){return"\\u"+("0000"+l.charCodeAt(0).toString(16)).slice(-4)});if(/^[\],:{}\s]*$/.test(k.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+k+")");return typeof i==="function"?g({"":j},""):j}throw new SyntaxError("JSON.parse");}})();function Za(){this.p=document.createElement("div");this.p.style.width="50px";this.p.style.height="320px";this.p.style.border="1px dotted #cccccc"}Za.prototype={X:function(a,b){var c=document.createElement("div"),d=document.createElement("img");d.src=a;d.p=c;c.appendChild(d);this.p.appendChild(c);$(c).mouseenter(function(){this.style.background="#9fb3e7"});$(c).mouseleave(function(){this.style.background="#ffffff"});b&&$(c).click(b)}};function $a(a){this.I(a)}
$a.prototype={Ia:1,Ha:2,eb:3,Wa:0.5522847498,ka:function(){var a=[];a.push({name:"fillStyle",display:"Fill Colour",type:"colour"});a.push({name:"strokeStyle",display:"Outline Colour",type:"colour"});a.push({name:"lineWidth",display:"Outline Thickness",type:"select",b:[{name:"None",value:0},{name:"Pencil",value:1},{name:"Pen",value:2},{name:"Marker",value:4}]});a.push({name:"shadow",display:"Shadow",type:"select",b:[{name:"Shadow",value:r},{name:"None",value:z}]});return a},setProperty:function(a,
b){for(var c=0;c<this.c.length;c++)if(a==="fillStyle"){this.c[c].fillStyle=b;this.Ga[c].fillStyle=b}},S:function(a){switch(a){case "fillStyle":return this.c[0].fillStyle;case "strokeStyle":return this.c[0].strokeStyle;case "lineWidth":return this.c[0].lineWidth}},I:function(a){if(a===undefined)a=new Ma;this.F.I.apply(this);this.c=[a];this.Ga=[a.clone()]},load:function(a){this.F.load.apply(this,[a]);this.c=[];for(var b=0;b<a.paths.length;b++){var c=new Ma;c.load(a.paths[b]);this.c.push(c);this.Ga.push(c.clone())}},
save:function(){var a=this.F.save.apply(this);a.type="SimplePathNode";a.paths=[];for(var b=0;b<this.c.length;b++)a.paths.push(this.c[b].save());return a},t:function(){console.log("Formatting.");this.Ga=[];for(var a=0;a<this.c.length;a++){var b=this.c[a].clone();b.transform(this.u);this.Ga.push(b);if(a===0)this.rect=b.gc(16);else this.rect.yb(b.gc(16))}if(this.rect.width<8){this.rect.x+=this.rect.width/2-4;this.rect.width=8}if(this.rect.height<8){this.rect.y+=this.rect.height/2-4;this.rect.height=
8}},e:function(a){console.log("drawing.");a.save();a.beginPath();for(var b=0;b<this.Ga.length;b++)this.Ga[b].e(a);a.restore()},aa:function(){for(var a=0;a<this.c.length;a++)this.c[a]=this.Ga[a]},ba:function(a,b){return this.rect.mc(a,b)?this:u}};$a.prototype=$.extend({},G.prototype,$a.prototype);$a.prototype.F=G.prototype;window.SimplePathNode=$a;function ab(a,b,c){this.l=a;this.f=b;this.Bb=[];this.pe=c}ab.prototype={execute:function(){for(var a=this.Bb.length=0;a<this.f.length;a++){this.Bb.push(this.f[a].save());this.f[a].transform(this.pe);this.f[a].t(Q.q.a)}},N:function(){for(var a=0;a<this.f.length;a++){this.f[a].load(this.Bb[a]);this.f[a].t(Q.q.a)}}};function bb(a,b,c){this.view=a;this.l=b;this.k=c}
bb.prototype={execute:function(){this.view.R();this.l.J(this.k,0);this.view.Ua(u);this.view.ga(this.k);this.view.oa()},N:function(){this.l.removeChild(this.k);this.view.R();this.view.Ua(u)}};function cb(a,b,c){this.m=a;this.selection=b;this.Rb=[];this.type=c}
cb.prototype={execute:function(){this.Rb.length=0;for(var a=this.selection.length-1;a>=0;a--){var b=this.selection[a],c=b.parent,d=c.removeChild(b);this.Rb.push(d);switch(this.type){case 0:c.J(b,0);break;case 1:c.J(b,c.children.length);break;case 2:d>0?c.J(b,d-1):c.J(b,d);break;case 3:d<c.children.length?c.J(b,d+1):c.J(b,d)}}},N:function(){for(var a=0;a<this.selection.length;a++){var b=this.selection[a],c=b.parent;c.removeChild(b);c.J(b,this.Rb[a])}}};
function db(a,b){this.l=a;this.selection=b.concat();this.parents=[];this.qb=[];for(var c=0;c<this.selection.length;c++)this.parents.push(this.l.pc(this.selection[c]))}db.prototype={execute:function(){for(var a=this.qb.length=0;a<this.selection.length;a++)this.qb.push(this.parents[a].removeChild(this.selection[a]))},N:function(){for(var a=0;a<this.selection.length;a++)this.qb[a]>=0&&this.parents[a].children.splice(this.qb[a],0,this.selection[a])}};
function eb(a,b,c){this.l=b;this.f=[];this.view=a;this.view.xb(c);c=this.view.m.lc(c);a=new Ia(10,10);for(b=0;b<c.length;b++){var d=c[b].duplicate();this.f.push(d);d.transform(a);d.t(this.view.a)}}eb.prototype={execute:function(){this.view.R();for(var a=0;a<this.f.length;a++){this.l.J(this.f[a],0);this.view.ga(this.f[a])}this.view.oa()},N:function(){this.view.R();for(var a=0;a<this.f.length;a++)this.l.removeChild(this.f[a]);this.view.oa()}};
function fb(a,b,c,d,e,f){this.k=a;this.handle=b;this.qd=c;this.rd=d;this.je=e;this.ke=f}fb.prototype={execute:function(){this.k.aa();this.k.da(this.handle,this.je,this.ke);this.k.t(Q.q.a)},N:function(){this.k.aa();this.k.da(this.handle,this.qd,this.rd);this.k.t(Q.q.a)}};function gb(a){this.view=a;this.f=this.view.selection.concat();this.view.xb(this.f);this.Qb=[];this.Pb=[]}
gb.prototype={execute:function(){this.nb=new G;this.Pb.length=0;for(var a=this.Qb.length=0;a<this.f.length;a++){var b=this.f[a];if(b.parent!==u){this.Qb.push(b.parent);this.Pb.push(b.parent.removeChild(b));this.nb.J(b,this.nb.children.length)}}this.view.m.l.J(this.nb,this.view.m.l.children.length)},N:function(){this.view.m.l.removeChild(this.nb);for(var a=this.f.length-1;a>=0;a--){var b=this.f[a];b.parent!==u&&this.Qb[a].J(b,this.Pb[a])}}};
function hb(a){this.view=a;this.f=this.view.selection.concat();this.view.xb(this.f);this.Ib=[]}
hb.prototype={execute:function(){for(var a={},b=0;b<this.f.length;b++){var c=this.f[b].parent;if(c.parent!==u){var d=c.parent;if(!(c.id in a)){a[c.id]=r;var e=d.removeChild(c),f=c.children.concat();this.Ib.push({k:c,tc:d,index:e,children:f});for(var h=0;h<f.length;h++){c.removeChild(f[h]);d.J(f[h],e+h)}}}}},N:function(){for(var a=this.Ib.length-1;a>=0;a--){for(var b=this.Ib[a],c=b.children.length-1;c>=0;c--){b.tc.removeChild(b.children[c]);b.k.J(b.children[c],0)}b.tc.J(b.k,b.index)}}};
function ib(a,b,c,d){this.view=a;this.w=this.A=0;this.Gb=z;this.P=b;this.ma(c,d)}
ib.prototype={ma:function(a,b){this.A=a;this.w=b;this.Gb=r},Qa:function(a,b){if(this.Gb){var c=this.view.a;this.view.e();c.save();c.strokeStyle="#0050B7";c.lineWidth=2/this.view.scale;c.fillStyle="rgba(0, 80, 183, 0.2)";var d=new J(this.A+0.5,this.w+0.5,a-this.A,b-this.w);c.fillRect(d.x,d.y,d.width,d.height);c.strokeRect(d.x,d.y,d.width,d.height);c.restore()}},ab:function(a,b){this.Gb=z;this.view.ee(new J(this.A,this.w,a-this.A,b-this.w));this.view.oa();this.view.e();this.view.g=this.P}};
function jb(a,b,c,d,e,f){this.view=a;this.handle=c;this.P=b;this.le=d;this.view.Oc(this.handle===this.view.Ja);this.ma(e,f)}
jb.prototype={ma:function(a,b){this.A=a;this.w=b;for(var c=this.f=this.view.wd(),d=[],e=0;e<c.length;e++)d.push(c[e].Hb());this.yc=d;this.s=new J(this.view.j.x,this.view.j.y,this.view.j.width,this.view.j.height);if(this.handle===this.view.Ja){this.jb=this.s.x+this.s.width/2;this.kb=this.s.y+this.s.height/2;this.ie=Math.atan2(this.kb-b,a-this.jb)}},sc:function(a,b){var c=a-this.A,d=b-this.w;switch(this.handle){case this.view.$b:c=(a-this.s.x)/this.s.width;d=(this.s.y+this.s.height-b)/this.s.height;
c=new Ga(c,d,this.s.x,this.s.y+this.s.height);break;case this.view.bc:c=(a-this.s.x)/this.s.width;d=(b-this.s.y)/this.s.height;c=new Ga(c,d,this.s.x,this.s.y);break;case this.view.cc:c=(this.s.x+this.s.width-a)/this.s.width;d=(b-this.s.y)/this.s.height;c=new Ga(c,d,this.s.x+this.s.width,this.s.y);break;case this.view.ac:c=(this.s.x+this.s.width-a)/this.s.width;d=(this.s.y+this.s.height-b)/this.s.height;c=new Ga(c,d,this.s.x+this.s.width,this.s.y+this.s.height);break;case this.view.Ja:c=new Ha(Math.atan2(this.kb-
b,a-this.jb)-this.ie,this.jb,this.kb);break;default:c=new Ia(c,d)}return c},Qa:function(a,b){for(var c=this.sc(a,b),d=0;d<this.f.length;d++){this.f[d].Da(c.multiply(this.yc[d]));this.f[d].t(Q.q.a)}this.view.Uc(c);if(this.handle===this.view.Ja){this.view.vb=a;this.view.wb=b}this.view.e();if(this.handle===this.view.Ja){c=this.view.a;c.save();c.beginPath();c.strokeStyle="#0050B7";c.lineWidth=1/this.view.scale;c.moveTo(this.jb,this.kb);c.lineTo(a,b);c.stroke();c.restore()}},ab:function(a,b){var c;if(a!==
this.A||b!==this.w){c=this.sc(a,b);for(var d=0;d<this.f.length;d++)this.f[d].Da(this.yc[d]);this.view.v.execute(new ab(this.view.m.l,this.f,c))}else if(this.le)if((c=this.view.m.l.ba(a,b))&&c.Za()){this.view.R();this.view.Ua(c)}this.view.Uc(new L);this.view.Oc(r);this.view.gb();this.view.e();this.view.g=this.P}};function kb(a,b,c,d,e,f){this.view=a;this.k=c;this.handle=d;this.P=b;this.ma(e,f)}
kb.prototype={ma:function(a,b){this.A=a;this.w=b;this.k.aa()},Qa:function(a,b){this.k.da(this.handle,a,b);this.k.t(this.view.a);this.view.e()},ab:function(a,b){if(a!==this.A||b!==this.w)this.view.v.execute(new fb(this.k,this.handle,this.A,this.w,a,b),r);this.view.e();this.view.g=this.P}};
function lb(a,b,c,d,e){this.view=a;this.P=b;this.Wd=this.view.canvas.width;this.Vd=this.view.canvas.height;this.A=e.pageX;this.w=e.pageY;var f=this;this.Bc=function(h){f.Rd(h.pageX,h.pageY);h.stopPropagation()};this.Vc=function(h){f.Sd(h.pageX,h.pageY);h.stopPropagation()};$(document).Zc("mousemove",this.Bc);$(document).Zc("mouseup",this.Vc)}
lb.prototype={Rd:function(a,b){this.view.canvas.width=this.Wd+a-this.A;this.view.canvas.height=this.Vd+b-this.w;this.view.e()},Sd:function(){$(document).me("mousemove",this.Bc);$(document).me("mouseup",this.Vc);this.view.g=this.P}};function T(a,b,c,d){this.view=a;this.P=b;this.k=u;this.Cc=0;this.Dd=c;this.zd=d;this.view.canvas.style.cursor="crosshair";this.view.Wb("Click to place first point of line");this.view.e()}
T.prototype={Sb:function(a){if(a.keyCode===27){this.k!==u&&this.k.parent.removeChild(this.k);this.oc()}},dc:function(a,b){this.Dd?this.k.Ya(a,b):this.k.lineTo(a,b)},Ic:function(a,b){if(this.k===u){this.k=this.zd?new Pa(a,b):new R(a,b);this.dc(a,b);this.k.t(this.view.a);this.view.m.l.J(this.k,0);this.index=1;this.view.Wb("Click to place another point, or double-click to end the line");this.view.e();this.Cc=2}else{this.dc(a,b);this.Cc++;this.index+=1}},Qa:function(a,b){if(this.k){this.k.da(this.index,
a,b);this.k.t(this.view.a);this.view.e()}},Gc:function(){if(!(this.k&&this.k.mb()<3)){if(this.k){var a=this.k.mb();this.k.ub(a-1);this.k.ub(a-2);this.k.fc();this.k.t();this.view.v.execute(new bb(this.view,this.view.m.l,this.k),r);this.view.R();this.view.Ua(u);this.view.ga(this.k);this.view.oa()}this.oc()}},oc:function(){this.view.g=this.P;this.view.canvas.style.cursor="default";this.view.Wb(u);this.view.e()}};function mb(a,b){this.view=a;this.view.canvas.style.cursor="crosshair";this.P=b}
mb.prototype={ma:function(a,b){this.view.canvas.style.cursor="default";this.view.g=this.P;var c=Wa(this.view.a,a,b,this.view.canvas.width,this.view.canvas.height);this.view.v.execute(new bb(this.view,this.view.m.l,new $a(c)),z);this.view.update()}};function nb(a){this.view=a}
nb.prototype={Qa:A(),ma:function(a,b,c){var d;if(this.view.ae(a,b))this.view.g=new lb(this.view,this,a,b,c);else if(d=this.view.vd(a,b))this.view.g=new jb(this.view,this,d,z,a,b);else if(this.view.selection.length&&this.view.j.mc(a,b))this.view.g=new jb(this.view,this,-1,r,a,b);else{c.shiftKey||this.view.R();if(this.view.Oa){c=this.view.Oa;d=c.Pa(a,b,1/this.view.scale);if(d!==u){this.view.g=new kb(this.view,this,c,d,a,b);return}}if(c=this.view.m.l.ba(a,b)){d=c===this.view.Oa;var e=this.view.Ed(c);
if(!e){this.view.ga(c);this.view.oa()}this.view.g=new jb(this.view,this,-1,!d&&e,a,b)}else{this.view.Ua(u);this.view.g=new ib(this.view,this,a,b)}this.view.e()}},ab:A(),Sb:function(a){var b=a.keyCode;if(b===36){if(this.view.selection.length){this.view.v.execute(new cb(this.view.m,this.view.getSelection(),0));this.view.update()}}else if(b===35){if(this.view.selection.length){this.view.v.execute(new cb(this.view.m,this.view.getSelection(),1));this.view.update()}}else if(b===33){if(this.view.selection.length){this.view.v.execute(new cb(this.view.m,
this.view.getSelection(),2));this.view.update()}}else if(b===34){if(this.view.selection.length){this.view.v.execute(new cb(this.view.m,this.view.getSelection(),3));this.view.update()}}else if(b===46||b===8){if(this.view.selection.length){this.view.v.execute(new db(this.view.m.l,this.view.selection));this.view.R();this.view.update()}}else if(b===68&&a.ctrlKey===r){if(this.view.selection.length){this.view.v.execute(new eb(this.view,this.view.m.l,this.view.selection));this.view.update()}}else if(b===
67)this.view.g=new T(this.view,this,r,z);else if(b===76)this.view.g=new T(this.view,this,z,z);else if(b===71&&a.ctrlKey&&a.shiftKey)this.view.v.execute(new hb(this.view));else if(b===71&&a.ctrlKey)this.view.v.execute(new gb(this.view));else if(!(b===85&&a.ctrlKey))if(b===107&&a.shiftKey||b===187&&!a.shiftKey){this.view.scale=1;this.view.U=0;this.view.V=0;this.view.e()}else if(b===107||b===187){this.view.scale*=1.1;this.view.e()}else if(b===109||b===189){this.view.scale/=1.1;this.view.e()}else if(b===
38){this.view.V=Math.min(this.view.V+16,0);this.view.e()}else if(b===39){this.view.U=Math.max(-(this.view.canvas.width*this.view.scale-this.view.canvas.width),this.view.U-16);this.view.e()}else if(b===40){this.view.V=Math.max(-(this.view.canvas.height*this.view.scale-this.view.canvas.height),this.view.V-16);this.view.e()}else if(b===37){this.view.U=Math.min(this.view.U+16,0);this.view.e()}else if(b===192&&a.shiftKey){this.view.canvas.height*=1.1;this.view.e()}else if(b===192)this.view.g=new mb(this.view,
this)}};function ob(a){this.selection=a;this.Dc=u}ob.prototype={execute:function(){var a,b=[];if(this.selection.length!==0){for(a=0;a<this.selection.length;a++)b.push(this.selection[a].save());try{this.Dc=window.localStorage.getItem("clipboard");window.localStorage.setItem("clipboard",window.JSON.stringify(b))}catch(c){alert(c)}}},N:function(){window.localStorage.setItem("clipboard",this.Dc)}};function pb(a,b){this.view=a;this.bd=b;this.Ec=0}
pb.prototype={execute:function(){var a,b,c;this.Ec=this.view.m.l.children.length;try{a=window.JSON.parse(""+this.bd);this.view.R();for(b=0;b<a.length;b++){c=N(a[b]);this.view.m.l.J(c,-1);c.t(this.view.a);this.view.ga(c)}this.view.oa();this.view.e()}catch(d){alert("Error reading Zwibbler clipboard: "+d)}},N:function(){this.view.m.l.children.length=this.Ec;this.view.R();this.view.oa();this.view.e()}};var la;
function qb(a,b,c){la=this;this.canvas=a;this.a=this.canvas.getContext("2d");this.ob=c;c.view=this;this.m=new Sa;this.t();this.selection=[];this.j=new J(0,0,0,0);this.Oa=u;this.v=b;this.scale=1;this.V=this.U=0;this.Kb=u;this.Jb=document.createElement("img");this.e();this.$b=1;this.bc=2;this.cc=3;this.ac=4;this.Ja=5;this.Zb=4;this.zb=9;this.Ac=u;this.cb=new L;this.nc=r;this.Ca=1;this.g=new nb(this);var d=this,e=parseInt(this.canvas.style.borderWidth,10);this.border=e;$(this.canvas).mousemove(function(f){if(d.g.Qa){var h=
$(d.canvas).offset();d.g.Qa((f.pageX-h.left-e-d.U)/d.scale,(f.pageY-h.top-e-d.V)/d.scale)}});$(this.canvas).mousedown(function(f){var h=$(d.canvas).offset();d.g.ma&&d.g.ma((f.pageX-h.left-e-d.U)/d.scale,(f.pageY-h.top-e-d.V)/d.scale,f);f.preventDefault()});$(this.canvas).mouseup(function(f){var h=$(d.canvas).offset();d.g.ab&&d.g.ab((f.pageX-h.left-e-d.U)/d.scale,(f.pageY-h.top-e-d.V)/d.scale);f.preventDefault()});$(this.canvas).click(function(f){var h=$(d.canvas).offset();$(d.canvas).focus();d.g.Ic&&
d.g.Ic((f.pageX-h.left-e-d.U)/d.scale,(f.pageY-h.top-e-d.V)/d.scale);f.preventDefault()});$(this.canvas).dblclick(function(f){var h=$(d.canvas).offset();d.g.Gc&&d.g.Gc((f.pageX-h.left-e-d.U)/d.scale,(f.pageY-h.top-e-d.V)/d.scale);f.preventDefault()});$(this.canvas).keydown(function(f){d.g.Sb&&d.g.Sb(f);f.preventDefault();return z});$(this.canvas).keyup(function(f){d.g.Qd&&d.g.Qd(f);f.preventDefault();return z})}
qb.prototype={getSelection:function(){var a=this.selection.concat();this.xb(a);return this.m.lc(a)},clear:function(){this.a.setTransform(1,0,0,1,0,0);this.a.clearRect(0,0,this.canvas.width,this.canvas.height)},t:function(){this.m.l.t(this.a)},update:function(){this.m.l.t();this.gb();this.e()},Wb:function(a){this.Kb=a;this.Jb.src="button.cgi?font=Arial&size=11&text="+encodeURIComponent(this.Kb)+"&fill=rgba(0,0,0,0.5)"},Lb:function(){if(this.g instanceof T)this.g=this.g.P;this.g=new T(this,this.g,z,
z)},Fb:function(){if(this.g instanceof T)this.g=this.g.P;this.g=new T(this,this.g,r,z)},Ab:function(){if(this.g instanceof T)this.g=this.g.P;this.g=new T(this,this.g,r,r)},e:function(){this.clear();this.a.lineCap="round";this.a.lineJoin="round";this.a.setTransform(this.scale,0,0,this.scale,this.U,this.V);this.m.l.e(this.a);if(this.selection.length>0){this.a.save();this.a.strokeStyle="#000000";this.a.lineWidth=1/this.scale;var a=this.cb.apply(this.j.x,this.j.y),b=this.cb.apply(this.j.x+this.j.width,
this.j.y),c=this.cb.apply(this.j.x+this.j.width,this.j.y+this.j.height),d=this.cb.apply(this.j.x,this.j.y+this.j.height),e=new Ba(this.vb,this.wb),f=this.Zb/this.scale;this.a.strokeRect(b.x-f,b.y-f,f*2,f*2);this.a.strokeRect(a.x-f,a.y-f,f*2,f*2);this.a.strokeRect(d.x-f,d.y-f,f*2,f*2);this.a.strokeRect(c.x-f,c.y-f,f*2,f*2);if(this.nc){this.a.beginPath();this.a.strokeStyle="#008000";this.a.lineWidth=3/this.scale;this.a.moveTo(e.x,e.y);this.a.arc(e.x,e.y,6/this.scale,0,1.5*Math.PI,z);this.a.stroke()}this.a.restore()}this.Oa&&
this.Oa.Na(this.a,1/this.scale);this.Ac&&this.Ac.e(this.a);if(this.Kb!==u&&this.Jb.complete)try{this.a.drawImage(this.Jb,0,0)}catch(h){}this.a.save();this.a.setTransform(1,0,0,1,0,0);this.a.lineWidth=1;this.a.strokeStyle="#4fa0d3";this.a.beginPath();for(a=this.zb;a>0;a-=3){this.a.moveTo(this.canvas.width,this.canvas.height-a);this.a.lineTo(this.canvas.width-a,this.canvas.height)}this.a.stroke();this.a.restore()},ee:function(a){for(var b=0;b<this.m.l.children.length;b++){var c=this.m.l.children[b];
if(c.children.length>0){for(var d=r,e=0;e<c.children.length;e++)a.contains(c.children[e].rect)||(d=z);d&&this.ga(c.children[0])}else a.contains(this.m.l.children[b].rect)&&this.ga(c,z)}},Uc:aa("cb"),Oc:aa("nc"),oa:function(){this.gb();this.ob.Gd(this.selection)},Ua:aa("Oa"),Ed:function(a){return a.Ca===this.Ca},wd:function(){return this.selection.concat()},ae:function(a,b){a*=this.scale;b*=this.scale;return a>=this.canvas.width-this.zb&&a<this.canvas.width+this.border&&b>=this.canvas.height-this.zb&&
b<this.canvas.height+this.border},vd:function(a,b){if(this.selection.length){var c=this.Zb*2/this.scale;if(a>=this.j.x-c&&a<this.j.x+c)if(b>=this.j.y-c&&b<this.j.y+c)return this.ac;else{if(b>=this.j.y+this.j.height-c&&b<this.j.y+this.j.height+c)return this.cc}else if(a>=this.j.x+this.j.width-c&&a<this.j.x+this.j.width+c)if(b>=this.j.y-c&&b<this.j.y+c)return this.$b;else if(b>=this.j.y+this.j.height-c&&b<this.j.y+this.j.height+c)return this.bc;if(a>=this.vb-c&&a<this.vb+c&&b>=this.wb-c&&b<this.wb+
c)return this.Ja}return u},ga:function(a,b){this.Ua(u);if(a.Ca!==this.Ca){b&&this.R();this.selection.push(a);a.Ca=this.Ca;if(a.parent&&a.parent.parent!==u)for(var c=a.parent,d=0;d<c.children.length;d++)this.ga(c.children[d]);a.children.length>0&&this.ga(a.children[0])}},gb:function(){if(this.selection.length!==0){var a=this.selection[0];this.j.x=a.rect.x;this.j.y=a.rect.y;this.j.width=a.rect.width;this.j.height=a.rect.height;for(a=1;a<this.selection.length;a++)this.j.yb(this.selection[a].rect);this.vb=
this.j.x+this.j.width-20/this.scale;this.wb=this.j.y}},R:function(){if(this.selection.length>0){this.Ca+=1;this.selection.length=0}},ec:function(a){a.Qc=this.Od++;for(var b=0;b<a.children.length;b++)this.ec(a.children[b])},xb:function(a){this.Od=0;this.ec(this.m.l);a.sort(function(b,c){return b.Qc-c.Qc})},copy:function(){this.v.execute(new ob(this.getSelection()))},$d:function(){try{var a=window.localStorage.getItem("clipboard");a===u?alert("Zwibbler clipboard is empty."):this.v.execute(new pb(this,
a))}catch(b){alert("Error reading zwibbler clipboard: "+b)}}};function U(a){return window.JSON.stringify(a)};var Q=u;function rb(a,b){Q.v.clear();Q.q.R();Q.q.m.l=N(a);Q.z=b;Q.q.update()}function sb(a){var b={};a=a.split("?");a=a[a.length-1].split("&");for(var c=0;c<a.length;c++){var d=a[c].split("=");if(d[0])try{b[d[0].toLowerCase()]=d.length>1?window.ue?decodeURIComponent(d[1].replace(/\+/g," ")):unescape(d[1]):""}catch(e){}}return b}
function tb(a){function b(){var h=400;if(c.xa)h=75;c.canvas.width=$(window).width()-h;c.canvas.height=$(window).height()-$(c.canvas).offset().top-15;c.q.e()}var c=this,d=sb(window.location.href);this.xa="component"in d?parseFloat(d.component):0;this.v=new ya;this.p=document.getElementById(a);a=new Za;a.X("wd-box.png",function(){c.Md()});a.X("wd-circle.png",function(){c.Jd()});a.X("wd-line.png",function(){c.Lb()});a.X("wd-curve.png",function(){c.Fb()});a.X("wd-arrow.png",function(){c.Ab()});this.xa||
a.X("wd-text.png",function(){c.Nd()});a.X("wd-undo.png",function(){c.N()});a.X("wd-redo.png",function(){c.Vb()});a.X("wd-copy.png",function(){c.q.copy()});a.X("wd-paste.png",function(){c.q.$d()});a.p.style.cssFloat="left";this.p.appendChild(a.p);this.canvas=$("<canvas width='700' tabindex='1' height='700'>")[0];this.canvas.style.borderColor="black";this.canvas.style.borderWidth="2px";this.canvas.style.borderStyle="solid";if(!c.xa)this.canvas.style.borderTop="2px solid white";this.canvas.style.cssFloat=
"left";this.canvas.style.cursor="default";this.ob=new xa;this.q=new qb(this.canvas,this.v,this.ob);this.p.appendChild(this.canvas);c.xa||this.p.appendChild(this.ob.p);$(window).resize(b);$(window).load(b);this.z={name:"Drawing created on "+(new Date).toLocaleDateString(),id:-1,M:0};this.hasFocus=z;Q=this;if("drawdoc"in d){var e;try{e=window.JSON.parse(d.ve)}catch(f){alert("Error loading drawing.");return}this.q.m.l=N(e);this.q.update()}this.options=new ma(this.xa);if(this.xa){$("#menubar").hide();
$("#about").hide();document.getElementById("logo").style.width="100px"}window.addEventListener("message",function(h){var n;try{n=window.JSON.parse(h.data)}catch(q){alert("Caught exception processing Zwibbler API message:"+q);return}if(n["function"]==="saveToString"){h=U({ticket:n.ticket,args:[U(Q.q.m.l.save())]});window.parent.postMessage(h,"*")}else if(n["function"]==="loadFromString"){var k;try{k=window.JSON.parse(n.args.sourceText)}catch(i){alert("Error loading drawing.");return}rb(k,{name:"Drawing created on "+
(new Date).toLocaleDateString(),id:-1,M:0});window.parent.postMessage(U({ticket:n.ticket,args:[]}),"*")}else n["function"]==="saveToTemporaryFile"&&V.yd(n.args.type,U(Q.q.m.l.save()),function(g,j){g==="ok"?window.parent.postMessage(U({ticket:n.ticket,args:[j.url]}),"*"):alert(g)})},z)}
tb.prototype={$:function(){return this.v.$},N:function(){if(this.v.jc()){this.v.N();this.q.update()}},Vb:function(){if(this.v.ic()){this.v.Vb();this.q.update()}},Kd:function(){this.q.R();this.v.clear();this.q.m=new Sa;this.q.update();this.z={name:"Drawing created on "+(new Date).toLocaleDateString(),id:-1,M:0}},Md:function(){var a=new R(10,10);a.lineTo(110,10);a.lineTo(110,110);a.lineTo(10,110);a.lineTo(10,10);a.close();this.v.execute(new bb(this.q,this.q.m.l,a));this.q.update()},Jd:function(){var a=
new R(50,0);a.hb(100,0,100,50);a.hb(100,100,50,100);a.hb(0,100,0,50);a.hb(0,0,50,0);a.close();this.v.execute(new bb(this.q,this.q.m.l,a));this.q.update()},Nd:function(){this.v.execute(new bb(this.q,this.q.m.l,new ja("Lorum ipsum dolor")));this.q.update()},Lb:function(){this.q.Lb()},Fb:function(){this.q.Fb()},Ab:function(){this.q.Ab()}};function ub(){}ub.prototype.hide=function(){this.p.remove()};ub.prototype.show=function(a){this.p=$("<div>");var b=$(window);this.p.css("position","fixed");this.p.css("background","black");this.p.css("opacity","0.25");this.p.css("left","0");this.p.css("top","0");this.p.css("zindex","1");this.p.css("width",""+b.width()+"px");this.p.css("height",""+b.height()+"px");this.p.css("display","none");this.p.click(function(){a()});$("body").append(this.p);this.p.fadeIn("normal")};
function vb(){this.T("");this.form=document.getElementById("createaccountform")}
vb.prototype={ja:"createaccount",onsubmit:function(){if(this.form.userNameInput.value==="")this.T("Username is blank.");else if(this.form.passwordInput1.value==="")this.T("Password is blank.");else if(this.form.passwordInput2.value!==this.form.passwordInput1.value)this.T("Passwords do not match.");else{this.form.submitButton.disabled=r;this.form.cancelButton.disabled=r;var a=this;V.hd(this.form.userNameInput.value,this.form.passwordInput1.value,function(b,c){if(b==="ok"){X.H();X.Tb(c)}else{a.form.submitButton.disabled=
z;a.form.cancelButton.disabled=z;a.T(b)}})}return z},T:function(a){$("#createaccounterror").text(a)}};vb.prototype.onsubmit=vb.prototype.onsubmit;function wb(){this.T("");this.form=document.getElementById("changepasswordform");this.form.oldpassword.value="";this.form.newpassword1.value="";this.form.newpassword2.value="";this.form.submitButton.disabled=z;this.form.cancelButton.disabled=z}
wb.prototype={ja:"changePasswordDiv",onsubmit:function(){var a=this.form.oldpassword.value,b=this.form.newpassword1.value;if(b!==this.form.newpassword2.value)this.T("Passwords do not match.");else if(b==="")this.T("Password is blank.");else{this.T("");this.form.submitButton.disabled=r;this.form.cancelButton.disabled=r;var c=this;V.Db(a,b,function(d){if(d==="ok")X.H();else{c.form.submitButton.disabled=z;c.form.cancelButton.disabled=z;c.T(d)}})}return z},T:function(a){$("#passwordError").text(a)}};
wb.prototype.onsubmit=wb.prototype.onsubmit;function xb(a){this.lb=a;$("#surediv").slideDown("normal")}xb.prototype={ja:"checksave",la:function(){X.H();this.lb&&this.lb()},Xa:function(){X.H()}};xb.prototype.okayClicked=xb.prototype.la;xb.prototype.cancelClicked=xb.prototype.Xa;function yb(a){$("#message-title").text(a.title);$("#message-text").text(a.text)}yb.prototype={ja:"message",la:function(){X.H()}};yb.prototype.okayClicked=yb.prototype.la;
function Bb(){$("#share-enabled").hide();$("#share-working").hide();$("#share-not-enabled").hide();Q.z.M?this.Pc():$("#share-not-enabled").show()}
Bb.prototype={ja:"share",ne:function(){var a=this;$("#share-enabled").hide();$("#share-working").show();Q.z.M=0;Q.z.data="";V.Xb(Q.z,function(b){$("#share-working").hide();if(b==="ok"){Q.M=0;X.H()}else{Q.z.M=1;a.error(b)}})},he:function(){var a=this;$("#share-not-enabled").hide();$("#share-working").show();Q.z.M=1;Q.z.data="";V.Xb(Q.z,function(b){$("#share-working").hide();if(b==="ok")a.Pc();else{Q.M=0;a.error(b)}})},Pc:function(){var a="http://zwibbler.com/shared/"+Q.z.id+".",b=a+"png",c=a+"pdf";
a=a+"svg";$("#share-png")[0].value=b;$("#share-pdf")[0].value=c;$("#share-svg")[0].value=a;$("#share-enabled").show()},error:function(a){$("#share-error").show();$("#share-error-code").text(a)}};Bb.prototype.shareClicked=Bb.prototype.he;Bb.prototype.unshareClicked=Bb.prototype.ne;$("#savefilename").keydown(function(a){a.keyCode===13&&X.ib().la()});
function Cb(){document.getElementById("savefilename").value=Q.z.name;$("#save-normal").show();V.Fa?$("#no-account-warning").hide():$("#no-account-warning").show();$("#save-working").hide();$("#save-error").hide();$("#savediv").slideDown("normal")}
Cb.prototype={ja:"save",hide:function(){$("#savediv").slideUp("normal")},la:function(){var a=document.getElementById("savefilename"),b=Q.z.name!==a.value;Q.z.name=a.value;$("#save-normal").hide();$("#save-working").show();a=U(Q.q.m.l.save());var c=this;if(document.getElementById("savetype").value==="client"){X.md(Q.z.name+".zwibbler","application/octet-stream",a);X.H()}else if(Q.z.id===-1||b)V.gd(Q.z.name,a,function(d,e){if(d==="ok"){Q.z.id=e;Q.z.M=0;X.H();Q.v.$=z}else c.error(d)});else{Q.z.data=
a;V.Xb(Q.z,function(d){if(d==="ok"){X.H();Q.v.$=z}else c.error(d)})}},error:function(a){$("#save-working").hide();$("#save-error").show();$("#save-error-code").text(a)},Xa:function(){X.H()}};Cb.prototype.okayClicked=Cb.prototype.la;Cb.prototype.cancelClicked=Cb.prototype.Xa;$("#previewcanvas").click(function(){X.ib().ya&&X.ib().la()});
function Y(){this.ya=u;if(!this.Cd){this.Cd=r;this.Eb=document.createElement("img");this.Eb.src="wd-clickopen.png"}this.Ba="normal";$("#deletebutton").hide();$("#browse-working").hide();$("#browse-prompt").hide();$("#browse-main").show();document.getElementById("fileinput").value="";this.Mc()}
Y.prototype={ja:"browse",Mc:function(){function a(){$("#deletebutton").hide();V.Lc(this.Hd,function(q,k){q==="ok"&&b.be(k)});return z}var b=this;document.getElementById("previewcanvas").getContext("2d").clearRect(0,0,350,350);var c=$("#filelist");c.empty();for(var d=$("<table width='100%'>"),e=0;e<V.files.length;e++){var f=V.files[e],h="#ffffff";if(e&1)h="#C0C0C0";var n=$("<a href=''>").text(f.name).click(a);n[0].Hd=V.files[e].id;f=new Date(parseInt(f.modificationDate,10)*1E3);f=f.toLocaleString();
d.append($("<tr>").append($("<td>").css("background",h).append(n)).append($("<td>").css("background",h).text(f)))}c.append(d)},be:function(a){var b;try{b=N(eval("("+a.data+")"))}catch(c){alert(c);return}this.ya=a;$("#deletebutton").show();a=document.getElementById("previewcanvas").getContext("2d");a.clearRect(0,0,350,350);a.save();a.setTransform(0.5,0,0,0.5,0,0);try{b.t(a);b.e(a)}catch(d){}a.setTransform(1,0,0,1,0,0);a.restore();this.Eb.complete&&a.drawImage(this.Eb,90,142)},jd:function(){$("#browse-main").hide();
$("#browse-prompt").show();this.Ba="prompt"},la:function(){var a=this;if(a.Ba==="normal"){X.H();this.ya&&X.Ud(this.ya,this.ya.data)}else if(a.Ba==="prompt"){$("#browse-prompt").hide();$("#browse-working").show();V.kd(this.ya.id,function(){$("#browse-working").hide();$("#browse-main").show();a.ya=u;a.Mc();a.Ba="normal"})}},Xa:function(){if(this.Ba==="normal")X.H();else if(this.Ba==="prompt"){$("#browse-prompt").hide();$("#browse-main").show();this.Ba="normal"}}};Y.prototype.okayClicked=Y.prototype.la;
Y.prototype.cancelClicked=Y.prototype.Xa;Y.prototype.deleteClicked=Y.prototype.jd;var Db={createaccount:vb,checksave:xb,save:Cb,browse:Y,changepassword:wb,message:yb,share:Bb,working:function(){this.ja="working"}};
function Z(){this.we=document.getElementById("main");this.za=u;this.Kc=new ub;this.za=u;var a=document.getElementById("uploadtarget"),b=this;a.onload=function(){var c=a.contentDocument.body.innerHTML;X.H();try{var d=window.JSON.parse(c),e=d.name;if(e.length>=9&&e.substr(e.length-9)===".zwibbler")e=e.substr(0,e.length-9);c={id:-1,name:e,M:0};rb(window.JSON.parse(d.data),c)}catch(f){alert("Error opening file: "+f)}};document.getElementById("fileinput").onchange=function(){document.getElementById("uploadform").submit();
b.ra("working")}}
Z.prototype={ra:function(a,b){var c=this;this.H();this.Kc.show(function(){c.H()});this.za=new Db[a](b);$("#"+this.za.ja).slideDown("normal")},H:function(){if(this.za!==u){$("#"+this.za.ja).slideUp("normal");this.Kc.hide();this.za=u}},ib:ba("za"),Nb:function(){var a=document.getElementById("signInForm"),b=a.username.value,c=a.password.value;a.signin.disabled=r;var d=this;V.Nb(b,c,function(e,f){a.signin.disabled=z;if(e==="ok")d.Tb(f);else{var h=document.getElementById("loginerror");a.signin.disabled=
z;$(h).empty();$(h).text(e)}})},Tb:function(a){document.getElementById("signin").style.display="none";document.getElementById("logout").style.display="block";if(a&&Q.z.id!==-1&&Q.z.id in a)Q.z.id=a[Q.z.id]},Ob:function(){var a=this,b=document.getElementById("logout");b.style.display="none";V.Ob(function(c){if(c==="ok")a.Hc();else b.style.display="block"})},Hc:function(){document.getElementById("signin").style.display="block";$(document.getElementById("logout")).hide();Q.z.id=-1;Q.z.M=0},Ld:function(){this.kc(function(){Q.Kd()})},
kc:function(a){Q.$()?this.ra("checksave",a):a()},Nc:function(){this.ra("save")},Db:function(){this.ra("changepassword")},$c:function(){var a=this;this.kc(function(){a.ra("browse")})},Ud:function(a,b){rb(eval("("+b+")"),a)},ed:function(){this.ra("createaccount")},Td:function(){if(!V.xc()||Q.$()||Q.z.id===-1){var a="Log in first";if(V.xc())a="Save first";this.ra("message",{title:a,text:"You can only share drawings if you log in and save them first."})}else this.ra("share")},ld:function(a){var b=document.createElement("form"),
c=document.createElement("input"),d=document.createElement("input");document.body.appendChild(b);b.appendChild(c);b.appendChild(d);b.method="post";b.action="server.cgi";c.type="hidden";c.name="type";c.value=a;d.type="hidden";d.name="document";d.value=U(Q.q.m.l.save());b.submit();document.body.removeChild(b);this.H()},md:function(a,b,c){var d=document.createElement("form"),e=document.createElement("input"),f=document.createElement("input"),h=document.createElement("input"),n=document.createElement("textarea");
document.body.appendChild(d);d.appendChild(e);d.appendChild(f);d.appendChild(h);d.appendChild(n);d.method="post";d.action="index.php";e.type="hidden";e.name="type";e.value="echo";f.type="hidden";f.name="name";f.value=a;h.type="hidden";h.name="contentType";h.value=b;n.name="contents";n.value=c;d.submit();document.body.removeChild(d);this.H()}};window.Page=Z;Z.prototype.newDrawing=Z.prototype.Ld;Z.prototype.browseDrawings=Z.prototype.$c;Z.prototype.saveDrawing=Z.prototype.Nc;Z.prototype.logout=Z.prototype.Ob;
Z.prototype.saveDrawing=Z.prototype.Nc;Z.prototype.createAccount=Z.prototype.ed;Z.prototype.login=Z.prototype.Nb;Z.prototype.currentDialog=Z.prototype.ib;Z.prototype.hideDialog=Z.prototype.H;Z.prototype.changePassword=Z.prototype.Db;Z.prototype.onShare=Z.prototype.Td;if(!document.createElement("canvas").getContext){document.getElementById("main").style.display="none";document.getElementById("no-canvas").style.display="block"}var Ua=new Aa(document.getElementById("debug"));new tb("draw");var V=new za,X=new Z;window.page=X;window.session=V;
$(document).ready(function(){V.Fa!==u?X.Tb():X.Hc();V.ud(function(){V.files.length>0&&V.Lc(V.files[0].id,function(a,b){a==="ok"&&rb(eval("("+b.data+")"),b)})});document.getElementById("main").style.cursor="default";Q.xa&&window.parent.postMessage(U({event:"ready"}),"*")});Z.prototype.downloadAs=Z.prototype.ld;za.prototype.setUsername=za.prototype.ge;window.EffectNode=Xa;

