function chessRules(n){var t=!1,i=["a","b","c","d","e","f","g","h"],r=[];r.a=1;r.b=2;r.c=3;r.d=4;r.e=5;r.f=6;r.g=7;r.h=8;this.isin=function(n,t){for(var i=0;i<t.length;i++)if(n==t[i])return!0;return!1};this.getMoves=function(t,i,r,u,f){n=t;var e=[];switch(i){case"pawn":e=this.pawn(r,u,f);break;case"knight":e=this.knight(r,u,f);break;case"bishop":e=this.bishop(r,u,f);break;case"rook":e=this.rook(r,u,f);break;case"queen":e=this.queen(r,u,f);break;case"king":e=this.king(r,u,f)}return e};this.pawn=function(u,f,e){var o,s,v,y,h=[],c,l,a;return(y=r[u],c=e=="white"?1:-1,o=u,s=parseInt(f+c),l=n.currentFEN(),s<1||s>8)?h:(n.squares[o][s].piece==null&&(t?h.push(o+s):(n.makeMove(u,f,o,s,!1),this.check(e)||h.push(o+s),n.loadFEN(l))),v=parseInt(s+c),(f==2&&e=="white"||f==7&&e=="black")&&n.squares[o][s].piece==null&&n.squares[o][v].piece==null&&(t?h.push(o+v):(n.makeMove(u,f,o,v,!1),this.check(e)||h.push(o+v),n.loadFEN(l))),y>1&&(o=i[y-2],a=n.squares[o][s].piece,a!=null&&a.color!=e&&(t?h.push(o+s):(n.makeMove(u,f,o,s,!0),this.check(e)||h.push(o+s),n.loadFEN(l))),o+s==n.enPassant&&(t?h.push(o+s):(n.makeMove(u,f,o,s,!0),n.squares[o][s-c].piece.square=null,n.squares[o][s-c].piece=null,this.check(e)||h.push(o+s),n.loadFEN(l)))),y<8&&(o=i[y+1-1],a=n.squares[o][s].piece,a!=null&&a.color!=e&&a!="king"&&(t?h.push(o+s):(n.makeMove(u,f,o,s,!0),this.check(e)||h.push(o+s),n.loadFEN(l))),o+s==n.enPassant&&(t?h.push(o+s):(n.makeMove(u,f,o,s,!0),n.squares[o][s-c].piece.square=null,n.squares[o][s-c].piece=null,this.check(e)||h.push(o+s),n.loadFEN(l)))),h)};this.knight=function(u,f,e){for(var w=n.currentFEN(),c,o,l,v=[],h,a,p,y=r[u],s=-2;s<=2;s++)for(h=-2;h<=2;h++)Math.abs(s)!=Math.abs(h)&&s!=0&&h!=0&&(l=parseInt(y+s),c=i[l-1],o=parseInt(f+h),l>0&&l<=8&&o>0&&o<=8&&(a=n.squares[c][o].piece,(a==null||a.color!=e)&&(p=a!=null,t?v.push(c+o):(n.makeMove(u,f,c,o,p),this.check(e)||v.push(c+o),n.loadFEN(w)))));return v};this.bishop=function(u,f,e,o){var b=n.currentFEN(),a,l,s,w,y,p,h,v,c;for(o==undefined&&(o=7),y=[],w=r[u],h=1;h<=o;h++)if(v=h,a=parseInt(w+h),l=i[a-1],s=parseInt(f+v),a>0&&a<=8&&s>0&&s<=8&&(c=n.squares[l][s].piece,(c==null||c.color!=e)&&(p=c!=null,t?y.push(l+s):(n.makeMove(u,f,l,s,p),this.check(e)||y.push(l+s),n.loadFEN(b))),c!=null))break;for(h=1;h<=o;h++)if(v=-h,a=parseInt(w+h),l=i[a-1],s=parseInt(f+v),a>0&&a<=8&&s>0&&s<=8&&(c=n.squares[l][s].piece,(c==null||c.color!=e)&&(p=c!=null,t?y.push(l+s):(n.makeMove(u,f,l,s,p),this.check(e)||y.push(l+s),n.loadFEN(b))),c!=null))break;for(h=-1;h>=-o;h--)if(v=h,a=parseInt(w+h),l=i[a-1],s=parseInt(f+v),a>0&&a<=8&&s>0&&s<=8&&(c=n.squares[l][s].piece,(c==null||c.color!=e)&&(p=c!=null,t?y.push(l+s):(n.makeMove(u,f,l,s,p),this.check(e)||y.push(l+s),n.loadFEN(b))),c!=null))break;for(h=-1;h>=-o;h--)if(v=-h,a=parseInt(w+h),l=i[a-1],s=parseInt(f+v),a>0&&a<=8&&s>0&&s<=8&&(c=n.squares[l][s].piece,(c==null||c.color!=e)&&(p=c!=null,t?y.push(l+s):(n.makeMove(u,f,l,s,p),this.check(e)||y.push(l+s),n.loadFEN(b))),c!=null))break;return y};this.rook=function(u,f,e,o){var w=n.currentFEN(),a,c,s,p,v,y,l,h;for(o==undefined&&(o=7),v=[],p=r[u],l=1;l<=o;l++)if(a=parseInt(p+l),c=i[a-1],s=f,a>0&&a<=8&&s>0&&s<=8&&(h=n.squares[c][s].piece,(h==null||h.color!=e)&&(y=h!=null,t?v.push(c+s):(n.makeMove(u,f,c,s,y),this.check(e)||v.push(c+s),n.loadFEN(w))),h!=null))break;for(l=1;l<=o;l++)if(a=p,c=i[a-1],s=parseInt(f+l),a>0&&a<=8&&s>0&&s<=8&&(h=n.squares[c][s].piece,(h==null||h.color!=e)&&(y=h!=null,t?v.push(c+s):(n.makeMove(u,f,c,s,y),this.check(e)||v.push(c+s),n.loadFEN(w))),h!=null))break;for(l=-1;l>=-o;l--)if(a=parseInt(p+l),c=i[a-1],s=f,a>0&&a<=8&&s>0&&s<=8&&(h=n.squares[c][s].piece,(h==null||h.color!=e)&&(y=h!=null,t?v.push(c+s):(n.makeMove(u,f,c,s,y),this.check(e)||v.push(c+s),n.loadFEN(w))),h!=null))break;for(l=-1;l>=-o;l--)if(a=p,c=i[a-1],s=parseInt(f+l),a>0&&a<=8&&s>0&&s<=8&&(h=n.squares[c][s].piece,(h==null||h.color!=e)&&(y=h!=null,t?v.push(c+s):(n.makeMove(u,f,c,s,y),this.check(e)||v.push(c+s),n.loadFEN(w))),h!=null))break;return v};this.queen=function(n,t,i){return this.bishop(n,t,i).concat(this.rook(n,t,i))};this.king=function(u,f,e){var l=n.currentFEN(),h,s,c,y,o,a,v=[];return a=r[u],o=f,n.castling=="-"||a!=5||t||this.check(e)||((e=="white"&&n.castling.match(/K/)||e=="black"&&n.castling.match(/k/))&&(h=a,c=i[h+1-1],s=i[h+2-1],n.squares[c][o].piece==null&&n.squares[s][o].piece==null&&(n.makeMove(u,f,c,o),passOk=this.check(e)?!1:!0,n.loadFEN(l),passOk&&(n.makeMove(u,f,s,o),this.check(e)||v.push(s+o),n.loadFEN(l)))),(e=="white"&&n.castling.match(/Q/)||e=="black"&&n.castling.match(/q/))&&(h=a,c=i[h-2],y=i[h-4],s=i[h-3],n.squares[c][o].piece==null&&n.squares[s][o].piece==null&&n.squares[y][o].piece==null&&(n.makeMove(u,f,c,o),passOk=this.check(e)?!1:!0,n.loadFEN(l),passOk&&(n.makeMove(u,f,s,o),this.check(e)||v.push(s+o),n.loadFEN(l))))),v.concat(this.bishop(u,f,e,1).concat(this.rook(u,f,e,1)))};this.check=function(i){var f,e,o,s,h,u,r;if(t)return!1;t=!0;try{f=n.pieces[n.getPiece("king",i)].square.x;e=n.pieces[n.getPiece("king",i)].square.y}catch(c){return t=!1,!1}for(u=0;u<n.pieces.length;u++)if(r=n.pieces[u],r.color!=i&&r.square!=null&&(o=r.square.x,s=r.square.y,h=eval("this."+r.name+'("'+o+'", '+s+', "'+r.color+'")'),this.isin(f+e,h)))return t=!1,!0;return t=!1,!1}}function chessRulesChecker(){var n=[],t;n.a=1;n.b=2;n.c=3;n.d=4;n.e=5;n.f=6;n.g=7;n.h=8;t=["0","a","b","c","d","e","f","g","h"];this.getPieceCoords=function(n,t,i,r,u,f,e){if(i&&r)return[i,r];switch(t){case"pawn":return this.pawn(n,i,r,u,f,e);case"knight":return this.knight(n,i,r,u,f,e);case"bishop":return this.bishop(n,i,r,u,f,e);case"rook":return this.rook(n,i,r,u,f,e);case"queen":return this.queen(n,i,r,u,f,e);case"king":return this.king(n,i,r,u,f,e)}throw new Error("Unknown piece: "+t);};this.pawn=function(t,i,r,u,f,e){var o=[],s=[],y=n[u],c,l,a,h,p,v;for(h=t.currentMove=="white"?1:-1,p=t.getPiece("pawn",t.currentMove,i),v=0;v<p.length;v++)c=t.pieces[p[v]],l=n[c.square.x],a=c.square.y,(!e&&(f==a+h*2||f==a+h)&&y==l||e&&f==a+h&&(y==l+1||y==l-1))&&o.push(c);return o.length>1?(s[0]=u,s[1]=f-h):o.length==1&&(s[0]=o[0].square.x,s[1]=o[0].square.y),s};this.knight=function(t,i,r,u,f,e){for(var l=[],o,h,c,a=n[u],v=t.getPiece("knight",t.currentMove,i,r),s=0;s<v.length;s++)o=t.pieces[v[s]],h=n[o.square.x],c=o.square.y,(Math.abs(f-c)==1&&Math.abs(a-h)==2||Math.abs(f-c)==2&&Math.abs(a-h)==1)&&l.push(o);return this.executeCheck(t,l,u,f,e)};this.bishop=function(i,r,u,f,e,o){for(var p=[],w,b,s,a,v,k,y,c,d=n[f],g=i.getPiece("bishop",i.currentMove,r,u),h,l=0;l<g.length;l++)if(c=i.pieces[g[l]],w=n[c.square.x],b=c.square.y,s=d-w,a=e-b,Math.abs(s)==Math.abs(a)){for(y=!1,v=s>0?1:-1,k=s==a?1:-1,h=1;h<Math.abs(s);h++)i.squares[t[d-v*h]][e-v*k*h].piece!=null&&(y=!0);y||p.push(c)}return this.executeCheck(i,p,f,e,o)};this.rook=function(i,r,u,f,e,o){for(var k=[],h,c,l,a,w,v,y,b=n[f],d=i.getPiece("rook",i.currentMove,r,u),s,p=0;p<d.length;p++)if(y=i.pieces[d[p]],h=n[y.square.x],c=y.square.y,e==c||b==h){for(v=!1,e==c?(a=!1,l=b-h):(a=!0,l=e-c),w=l>0?1:-1,s=1;s<Math.abs(l);s++)a&&i.squares[t[h]][e-w*s].piece!=null?v=!0:a||i.squares[t[b-w*s]][e].piece==null||(v=!0);v||k.push(y)}return this.executeCheck(i,k,f,e,o)};this.queen=function(i,r,u,f,e,o){for(var k=[],c,l,a,d,g,tt,p,w,nt,h,v,y=n[f],it=i.getPiece("queen",i.currentMove,r,u),s,b=0;b<it.length;b++)if(v=i.pieces[it[b]],c=n[v.square.x],l=v.square.y,a=y-c,d=e-l,Math.abs(a)==Math.abs(d)){for(h=!1,g=a>0?1:-1,tt=a==d?1:-1,s=1;s<Math.abs(a);s++)i.squares[t[y-g*s]][e-g*tt*s].piece!=null&&(h=!0);h||k.push(v)}else if(e==l||y==c){for(h=!1,e==l?(w=!1,p=y-c):(w=!0,p=e-l),nt=p>0?1:-1,s=1;s<Math.abs(p);s++)w&&i.squares[t[c]][e-nt*s].piece!=null?h=!0:w||i.squares[t[y-nt*s]][e].piece==null||(h=!0);h||k.push(v)}return this.executeCheck(i,k,f,e,o)};this.king=function(n){var t,i=[];return t=n.pieces[n.getPiece("king",n.currentMove)],i[0]=t.square.x,i[1]=t.square.y,i};this.executeCheck=function(n,t,i,r,u){var f=[],e;if(t.length>1)for(e=0;e<t.length;e++){var o=t[e].square.x,s=t[e].square.y,h=n.currentFEN();if(n.makeMove(o,s,i,r,u),n.switchMove(),!this.check(n)){f[0]=o;f[1]=s;n.loadFEN(h);break}n.loadFEN(h)}else t.length==1?(f[0]=t[0].square.x,f[1]=t[0].square.y):f=null;return f};this.check=function(n){var r=[],u,i,f,e,o,s,t;for(u=n.currentMove=="white"?"black":"white",i=n.pieces[n.getPiece("king",u)],f=i.square.x,e=i.square.y,t=0;t<n.pieces.length;t++)if(n.pieces[t].color==n.currentMove&&(o=n.pieces[t].square.x,s=n.pieces[t].square.y,r=eval("this."+n.pieces[t].name+'(board, "'+o+'", "'+s+'", "'+f+'", "'+e+'", true)'),r!=null))return!0;return!1}}function chessBoard(n,t){var r,u,i;for(this.letter=[],this.letter.a=1,this.letter.b=2,this.letter.c=3,this.letter.d=4,this.letter.e=5,this.letter.f=6,this.letter.g=7,this.letter.h=8,this.numbers=[0,8,7,6,5,4,3,2,1],this.letters=["0","a","b","c","d","e","f","g","h"],this.pieceNames=[],this.pieceNames.r="rook",this.pieceNames.n="knight",this.pieceNames.b="bishop",this.pieceNames.k="king",this.pieceNames.q="queen",this.pieceNames.p="pawn",this.currentMove,this.castling,this.enPassant,this.halfMoves=0,this.fullMoves=0,this.pieces=[],this.squares=[],this.squares.a=[],this.squares.b=[],this.squares.c=[],this.squares.d=[],this.squares.e=[],this.squares.f=[],this.squares.g=[],this.squares.h=[],this.rules=t||new chessRules(this),r=1;r<this.letters.length;r++)for(u=this.letters[r],i=1;i<=8;i++)this.squares[u][i]=new boardSquare(u,i);n=n||"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";this.loadFEN(n)}function boardSquare(n,t){this.x=n;this.y=t;this.piece}function boardPiece(n,t){this.square;this.name=n;this.color=t}function chessMove(){}function DOMRenderEngine(n){this.settings=n.settings;var i=this,t=null,r=null;this.createDOMModel=function(){var f,n,c,e,o,r,i,u,s,h,p;if(t==null&&(t=document.createElement("div"),t.className="tableView",f=document.createElement("table"),f.className="game_board",n="",n+='<tr class="row8"><td class="corner cola clefttop"><\/td><td class="lettertop topa cola"><div>A<\/div><\/td><td class="lettertop topb colb"><div>B<\/div><\/td><td class="lettertop topc colc"><div>C<\/div><\/td><td class="lettertop topd cold"><div>D<\/div><\/td><td class="lettertop tope cole"><div>E<\/div><\/td><td class="lettertop topf colf"><div>F<\/div><\/td><td class="lettertop topg colg"><div>G<\/div><\/td><td class="lettertop toph colh"><div>H<\/div><\/td><td class="corner colh crighttop"><div class="indicator black"><\/div><\/td><\/tr>\n',n+='<tr class="row8"><td class="numberleft cola"><div>8<\/div><\/td><td class="white square cola"><\/td><td class="black square colb"><\/td><td class="white square colc"><\/td><td class="black square cold"><\/td><td class="white square cole"><\/td><td class="black square colf"><\/td><td class="white square colg"><\/td><td class="black square colh"><\/td><td class="numberright right8 colh"><div>8<\/div><\/td><\/tr>\n',n+='<tr class="row7"><td class="numberleft cola"><div>7<\/div><\/td><td class="black square cola"><\/td><td class="white square colb"><\/td><td class="black square colc"><\/td><td class="white square cold"><\/td><td class="black square cole"><\/td><td class="white square colf"><\/td><td class="black square colg"><\/td><td class="white square colh"><\/td><td class="numberright right7 colh"><div>7<\/div><\/td><\/tr>\n',n+='<tr class="row6"><td class="numberleft cola"><div>6<\/div><\/td><td class="white square cola"><\/td><td class="black square colb"><\/td><td class="white square colc"><\/td><td class="black square cold"><\/td><td class="white square cole"><\/td><td class="black square colf"><\/td><td class="white square colg"><\/td><td class="black square colh"><\/td><td class="numberright right6 colh"><div>6<\/div><\/td><\/tr>\n',n+='<tr class="row5"><td class="numberleft cola"><div>5<\/div><\/td><td class="black square cola"><\/td><td class="white square colb"><\/td><td class="black square colc"><\/td><td class="white square cold"><\/td><td class="black square cole"><\/td><td class="white square colf"><\/td><td class="black square colg"><\/td><td class="white square colh"><\/td><td class="numberright right5 colh"><div>5<\/div><\/td><\/tr>\n',n+='<tr class="row4"><td class="numberleft cola"><div>4<\/div><\/td><td class="white square cola"><\/td><td class="black square colb"><\/td><td class="white square colc"><\/td><td class="black square cold"><\/td><td class="white square cole"><\/td><td class="black square colf"><\/td><td class="white square colg"><\/td><td class="black square colh"><\/td><td class="numberright right4 colh"><div>4<\/div><\/td><\/tr>\n',n+='<tr class="row3"><td class="numberleft cola"><div>3<\/div><\/td><td class="black square cola"><\/td><td class="white square colb"><\/td><td class="black square colc"><\/td><td class="white square cold"><\/td><td class="black square cole"><\/td><td class="white square colf"><\/td><td class="black square colg"><\/td><td class="white square colh"><\/td><td class="numberright right3 colh"><div>3<\/div><\/td><\/tr>\n',n+='<tr class="row2"><td class="numberleft cola"><div>2<\/div><\/td><td class="white square cola"><\/td><td class="black square colb"><\/td><td class="white square colc"><\/td><td class="black square cold"><\/td><td class="white square cole"><\/td><td class="black square colf"><\/td><td class="white square colg"><\/td><td class="black square colh"><\/td><td class="numberright right2 colh"><div>2<\/div><\/td><\/tr>\n',n+='<tr class="row1"><td class="numberleft cola"><div>1<\/div><\/td><td class="black square cola"><\/td><td class="white square colb"><\/td><td class="black square colc"><\/td><td class="white square cold"><\/td><td class="black square cole"><\/td><td class="white square colf"><\/td><td class="black square colg"><\/td><td class="white square colh"><\/td><td class="numberright right1 colh"><div>1<\/div><\/td><\/tr>\n',n+='<tr class="row1"><td class="corner cola cleftbottom"><div class="flipicon" title="'+this.settings.chessBoardLang.flipBoard+'"><\/div><\/td><td class="letterbottom bottoma cola"><div>A<\/div><\/td><td class="letterbottom bottomb colb"><div>B<\/div><\/td><td class="letterbottom bottomc colc"><div>C<\/div><\/td><td class="letterbottom bottomd cold"><div>D<\/div><\/td><td class="letterbottom bottome cole"><div>E<\/div><\/td><td class="letterbottom bottomf colf"><div>F<\/div><\/td><td class="letterbottom bottomg colg"><div>G<\/div><\/td><td class="letterbottom bottomh colh"><div>H<\/div><\/td>',n+='<td class="corner colh crightbottom"><div class="indicator white"><\/div><\/td><\/tr>\n',$(f).html(n),c=document.createElement("div"),c.className="markersView",e=document.createElement("div"),e.className="promotion",e.innerHTML="<div class='queen piece bqueen'><\/div><div class='rook piece brook'><\/div><div class='bishop piece bbishop'><\/div><div class='knight piece bknight'><\/div>",o=document.createElement("div"),o.className="board_buttons",o.innerHTML="<div onclick=\"goToStartPosition(this)\" class='button_start'><\/div><div onclick=\"goToPrevPosition(this)\" class='button_left'><\/div><div onclick=\"goToNextPosition(this)\" class='button_right'><\/div><div onclick=\"goToFinishPosition(this)\" class='button_end'><\/div>",t.appendChild(f),t.appendChild(c),t.appendChild(e),t.appendChild(o)),r=t.cloneNode(!0),this.boardTable=r.children[0],this.markersView=r.children[1],this.promotionView=r.children[2],this.blackIndicator=$(this.boardTable).find(".indicator.black")[0],this.whiteIndicator=$(this.boardTable).find(".indicator.white")[0],i=this.settings.displayCoordinates,this.isBoardrect=i!=null&&i!="",this.visibleCols=8,this.visibleRows=8,this.isBoardrect){var l=i.charAt(0),a=i.charAt(3),v=parseInt(i.charAt(1)),y=parseInt(i.charAt(4));for(this.startX=l,this.startY=v,this.finishX=a,this.finishY=y,this.visibleCols=letter[a]-letter[l]+1,this.visibleRows=y-v+1,u=letter.a;u<letter[l];u++)$(this.boardTable).find("td.col"+letters[u-1]).hide();for(s=y+1;s<=8;s++)$(this.boardTable).find("tr.row"+s).hide();for(h=1;h<v;h++)$(this.boardTable).find("tr.row"+h).hide();for(p=letter[a]+1;p<=letter.h;u++)$(this.boardTable).find("td.col"+letters[p-1]).hide()}return r};this.initStyles=function(){var n=this.squareSize||this.settings.squareSize,i=".piece, table.game_board td.white, table.game_board td.black, .game_board .square { width: "+n+"px; height: "+n+"px; }table.game_board td.lettertop, table.game_board td.letterbottom { width:  "+n+"px; }table.game_board td.numberleft, table.game_board td.numberright { height"+n+"px; }.game-over-panel { width: "+n*8+"px; height: "+(n*8|0)+"px; }.end-game-messages { padding-left: "+((8*n-300)/2|0)+"px; padding-top: "+((8*n-200)/2|0)+"px; }.close-overlay { left: "+(8*n-30|0)+"px;  }.end-game-btns { padding-left: "+((8*n-300)/2|0)+"px;  }",u=document.getElementsByTagName("head")[0],t=document.createElement("style");return t.type="text/css",t.styleSheet?t.styleSheet.cssText=i:t.appendChild(document.createTextNode(i)),u.appendChild(t),r||(r=t),t};this.resize=function(n){this.squareSize=(n-30)/8|0;var t=document.getElementsByTagName("head")[0],i=this.initStyles();t.removeChild(r);r=i;this.boardMarkers.onResize(this.squareSize)};this.initRenderer=function(){this.squareSize=this.settings.squareSize;this.board=n.board;this.boardMarkers=new BoardMarkers(this);this.gui=new GUI(this);this.gui.BoardDisabled=!this.settings.enabled;this.gui.flipDisabled=!1;$(".flipicon",this.boardTable).click(function(){i.mouseBehavior&&i.mouseBehavior.onBeforeRotate&&i.mouseBehavior.onBeforeRotate();i.gui.flipBoard();i.mouseBehavior&&i.mouseBehavior.onAfterRotate&&i.mouseBehavior.onAfterRotate()});this.gui.flipped=this.settings.inverted;this.gui.drawBoardPosition();this.drawStartMarkers();this.mouseBehavior=null};this.drawStartMarkers=function(){var n=this.settings.markers;n!=null&&n!=""&&this.boardMarkers.drawMarkers(n)};this.onBoardDraw=function(t){if(this.mouseBehavior&&this.mouseBehavior.onBoardDraw)this.mouseBehavior.onBoardDraw(t);n.onBoardDraw(t)};this.onBoardMove=function(t){n.onBoardMove(t)};this.onOpponentMove=function(n){if(this.mouseBehavior&&this.mouseBehavior.onOpponentMove)this.mouseBehavior.onOpponentMove(n)};this.onBeforeOpponentMove=function(n){if(this.mouseBehavior&&this.mouseBehavior.onBeforeOpponentMove)this.mouseBehavior.onBeforeOpponentMove(n)};this.setMouseBehavior=function(t){this.mouseBehavior=t;this.mouseBehavior.initialize(n)};this.removeMouseBehavior=function(){this.mouseBehavior&&(this.mouseBehavior.remove(),delete this.mouseBehavior)};this.drawBoardPosition=function(){this.gui.drawBoardPosition()};this.notaDrawArrow=function(n){this.boardMarkers.notaDrawArrow(n.fromX,n.fromY,n.toX,n.toY,n.piece=="knight")}}function ChessCoordinates(n){var t=n.charAt(0),i=Number(n.charAt(1));if(t<"a"||t>"h"||i<1||i>8)throw"Invalid chess square: "+n;return{getColumn:function(){return t},getRow:function(){return i}}}function GUI(n){var t=n.board,r=n.boardTable,u=n.boardMarkers,i;this.BoardDisabled=!1;this.flipDisabled=!1;this.enabled=function(){return!this.BoardDisabled};this.setEnabled=function(n){this.BoardDisabled=!n};this.flipped=!1;this.flipBoard=function(){this.flipDisabled||(this.flipped=!this.flipped,this.flipMoveIndicator(),this.drawBoardPosition(!0),this.drawCoordinates(),this.flipControlled(),n.boardMarkers.redrawMarkers())};this.flipControlled=function(){for(var f=$(r).find(".controlled").toArray(),u=[],i,n=f.length-1;n>=0;--n){var t=f[n],e=t.cellIndex,o=t.parentElement.rowIndex;t.controlled||$(t).removeClass("controlled");i=r.rows[9-o].cells[9-e];i.controlled=!0;u.push(i);$(i).addClass("controlled")}for(n=u.length-1;n>=0;--n)u[n].controlled=undefined};this.removeControlled=function(){$(r).find(".controlled").each(function(){$(this).removeClass("controlled")})};this.showControlled=function(n){for(var i,t=0;t<n.length;t++)i=this.getGUISquare(n[t].charAt(0),n[t].charAt(1)),$(i).addClass("controlled")};this.flipMoveIndicator=function(){var t=$(n.whiteIndicator),i=$(n.blackIndicator),r;t.addClass("black");t.removeClass("white");i.removeClass("black");i.addClass("white");r=n.whiteIndicator;n.whiteIndicator=n.blackIndicator;n.blackIndicator=r};this.onBoardMove=function(t){n.onBoardMove(t)};this.makeMove=function(n,i,r,u,f,e){var o=t.formMove(n,i,r,u,f);t.moveHandler(o);e||this.drawBoardPosition(t)};i=!0;this.makePieceElement=function(n,t,i,r){var u=document.createElement("div");return u.className="piece "+r.charAt(0)+i,u.color=r,u.name=i,u};this.addPiece=function(n,t,i,r){var f=this.getGUISquare(n,t),u=this.makePieceElement(n,t,i,r);return f.appendChild(u),u};this.getPiece=function(n,t){var i=this.getGUISquare(n,t);return i.childNodes.length===0?null:i.childNodes[0]};this.removePiece=function(n,t){var i=this.getGUISquare(n,t);$(i).empty()};this.drawBoardPosition=function(r){var h=[],a,o,s,c,l,f,e;if(!i)for(a=n.boardTable.getElementsByClassName("piece"),f=a.length>>>0;f--;)h.push(a[f]);for(f=t.pieces.length-1;f>=0;f--)if(o=t.pieces[f],s=o.square,s!=undefined){if(c=this.getGUISquare(s.x,s.y),l=c.childNodes.length===0?null:c.childNodes[0],!i&&l&&l.name==o.name&&l.color==o.color){h.splice(h.indexOf(l),1);continue}c.innerHTML="";e=this.makePieceElement(s.x,s.y,o.name,o.color);c.appendChild(e)}if(!i)for(f=h.length-1;f>=0;f--)e=h[f],e.parentNode&&e.parentNode.removeChild(e);u!=null&&(u.redrawMarkers(),u.clearMoveArrow());t.currentMove=="white"?(n.blackIndicator.style.display="none",n.whiteIndicator.style.display="block"):(n.whiteIndicator.style.display="none",n.blackIndicator.style.display="block");i===!0&&this.flipped===!0&&(this.flipMoveIndicator(),this.drawCoordinates());n.onBoardDraw(r);i=!1};this.drawCoordinates=function(){$(r).toggleClass("flipped")};this.getGUISquare=function(n,i){return n=="i"||n=="j"?$("#figures-table")[0].rows[8-i].cells[n=="i"?0:1]:(this.flipped?n=9-t.letter[n]:(n=t.letter[n],i=9-i),r.rows[i].cells[n])};this.getPieceElement=function(n,t){var i=this.getGUISquare(n,t);return $(i).children()[0]||null}}function SvgToString(){return this.svgString="",this.moveTo=function(n,t){return this.svgString=this.svgString+"M"+n+","+t,this},this.curveTo=function(n,t,i,r,u,f){return this.svgString=this.svgString+"C"+n+","+t+","+i+","+r+","+u+","+f,this},this.lineTo=function(n,t){return this.svgString=this.svgString+"L"+n+","+t,this},this}function BoardMarkers(n){var t,r,i,f,u;this.markers=[];t=[];t.a=1;t.b=2;t.c=3;t.d=4;t.e=5;t.f=6;t.g=7;t.h=8;r=[];r.A="#f00";r.D="#0f0";r.I="#ff0";r.C="#00f";i=[];i.N=.6;i.L=.4;i.E=.2;i.H=.1;this.squareSize=n.squareSize;this.canvas=null;this.bottomCanvas=null;this.getCanvas=function(){if(this.canvas==null){var t=n.markersView;this.canvas=Raphael(t,n.visibleCols*this.squareSize,n.visibleRows*this.squareSize)}return this.canvas};this.getBottomCanvas=function(){if(this.bottomCanvas==null){var t=n.markersView;this.bottomCanvas=Raphael(t,n.visibleCols*this.squareSize,n.visibleRows*this.squareSize);$(this.bottomCanvas.canvas).css("z-index","1")}return this.bottomCanvas};this.calculatePos=function(i,r){return n.gui.flipped&&(i=9-i,r=9-r),n.isBoardrect&&(i-=t[n.startX]-1,r-=8-n.finishY),{x:(i-.5)*this.squareSize,y:(r-.5)*this.squareSize}};this.drawPoint=function(n,i,r,u){var o=t[n],s=9-i,f=this.calculatePos(o,s),h=this.squareSize/5,e=this.getCanvas().circle(f.x,f.y,h);return e.attr({fill:r,stroke:"#000",opacity:u}),e};this.drawCircle=function(n,t,i,r){var f=this.getOffset(n,t),u=Math.ceil(this.squareSize/2),e=3,s=f.left+u,h=f.top+u,o=this.getCanvas().circle(s,h,u-e);return o.attr({stroke:i,opacity:1,"stroke-width":e,"stroke-opacity":r}),o};this.drawCross=function(n,t,i,r){var u=this.getOffset(n,t),f=4,o=(new SvgToString).moveTo(u.left+f,u.top+f).lineTo(u.left+this.squareSize-f,u.top+this.squareSize-f).moveTo(u.left+f,u.top+this.squareSize-f).lineTo(u.left+this.squareSize-f,u.top+f),e=this.getCanvas().path(o.svgString);return e.attr({stroke:i,opacity:1,"stroke-width":4,"stroke-opacity":r}),e};this.drawSolidRectangle=function(n,t,i,r,u,f){var e=this.getOffset(n,t);u=u||n;f=f||t;var o=this.getOffset(u,f),h=Math.min(e.left,o.left),c=Math.min(e.top,o.top),l=Math.abs(e.left-o.left)+this.squareSize,a=Math.abs(e.top-o.top)+this.squareSize,s=this.getBottomCanvas().rect(h,c,l,a,0);return s.attr({"stroke-width":0,stroke:i,opacity:r,fill:i}),s};this.drawRectangle=function(n,t,i,r){var f=this.getOffset(n,t),u=3,e=Math.floor(u/2),o=this.getCanvas().rect(f.left+e,f.top+e,this.squareSize-u,this.squareSize-u,0);return o.attr({stroke:i,opacity:1,"stroke-width":u,"stroke-opacity":r}),o};this.drawText=function(i,r,u,f,e,o){var s=t[i],h=9-r,c;return n.gui.flipped&&(s=9-s,h=9-h),n.isBoardrect&&(s-=t[n.startX]-1,h-=8-n.finishY),c="30",s=(s-.5)*this.squareSize,h=(h-.5)*this.squareSize,this.getCanvas().text(s+parseInt(c)-3,h,o).attr({"font-size":c,fill:"#fff"})};this.drawArrow=function(n,t,i,r,u,f,e){var rt=this.getOffset(n,t),ut=this.getOffset(i,r),p=this.squareSize/10,l=this.squareSize/3.5,w=this.squareSize/2.5,o=rt.left+this.squareSize/2,s=rt.top+this.squareSize/2,d=ut.left+this.squareSize/2,g=ut.top+this.squareSize/2,nt=Math.abs(d-o),tt=Math.abs(g-s),h=Math.sqrt(nt*nt+tt*tt),it=d==o||g==s?1:-1*nt/(d-o),c,v,k,a,st;c=nt==0?0:-Math.atan((d-o)/(g-s));tt==0?c=-c:g>s&&(c=Math.PI+c);c=c/Math.PI*180;try{if(k=SvgToString(),u){a=Math.sqrt(this.squareSize*this.squareSize/2);h<100&&(a*=h/(4*w));var b=Math.sqrt(h*h-a*a),ft=h/(4*w)*a,et=it*.7*a,y=it*a,ot=h/4;k.moveTo(o,s).curveTo(o+et,s-ot,o-p+y,s-ft,o-p+y,s-b+l).lineTo(o-l+y,s-b+w).lineTo(o+y,s-b).lineTo(o+l+y,s-b+w).lineTo(o+p+y,s-b+l).curveTo(o+p+y,s-ft,o+2+et,s-ot,o,s);v=this.getCanvas().path(k.svgString);v.attr({fill:f,stroke:"#000",opacity:e});st=it*180*(Math.atan(a/b)/Math.PI);v.rotate(c-st,o,s)}else k.moveTo(o,s).lineTo(o-p,s-h+l).lineTo(o-l,s-h+w).lineTo(o,s-h).lineTo(o+l,s-h+w).lineTo(o+p,s-h+l).lineTo(o,s),v=this.getCanvas().path(k.svgString),v.attr({fill:f,stroke:"#000",opacity:e}),v.rotate(c,o,s);return v}catch(ot){}};this.drawImage=function(t,i,r){var f=this.getOffset(t,i),u=document.createElement("div");return u.setAttribute("style","left: "+f.left+"px;top: "+f.top+"px;"),u.setAttribute("class",(r==5?"strawberry":"mushroom")+" image-marker"),$(n.markersView).append(u),u};this.drawMarkerArrow=function(n){var t=i[n.charAt(0)],u=r[n.charAt(1)],f=n.charAt(2),e=n.charAt(3),o=n.charAt(4),s=n.charAt(5),h=n.charAt(7)=="E";return this.drawArrow(f,e,o,s,h,u,t)};this.drawMarkerSquare=function(t){var f=i[t.charAt(0)],e=r[t.charAt(1)],u,o,s,h;return(x=t.charAt(2),y=t.charAt(3),t.charAt(5)=="0")?this.drawRectangle(x,y,e,f):t.charAt(5)=="1"?this.drawCircle(x,y,e,f):t.charAt(5)=="2"?this.drawCross(x,y,e,f):t.charAt(4)=="0"?(u=n.board,u.ckPlayer&&(o=u.squares[x][y],s=o?o.piece:null,s&&s.color!==u.ckPlayer&&(h=n.gui.getPiece(x,y),$(h).hide())),this.drawImage(x,y,t.charAt(5))):void 0};this.drawMarkerRectangle=function(n){var t=i[n.charAt(0)],u=r[n.charAt(1)],f=n.charAt(2),e=n.charAt(3),o=n.charAt(4),s=n.charAt(5);return this.drawSolidRectangle(f,e,u,t,o,s)};this.drawMarkerText=function(n){var t=i[n.charAt(0)],r=n.charAt(1),u=n.charAt(2),f=n.charAt(3),e=n.charAt(4),o=n.indexOf("'")+1;return this.drawText(r,u,f,e,t,n.substr(o,n.length-2))};this.drawMarker=function(n){switch(n.charAt(0)){case"A":return this.drawMarkerArrow(n.substr(1));case"S":return this.drawMarkerSquare(n.substr(1));case"R":return this.drawMarkerRectangle(n.substr(1));case"T":return this.drawMarkerText(n.substr(1));case"?":return null}throw'Unknown marker "'+n+'"';};this.clearMarkers=function(){var t,n;for(t in this.markers){n=this.markers[t];try{n.remove()}catch(i){$(n).remove()}}this.markers=[];f=""};this.notaDrawArrow=function(n,t,f,e,o){if(n==f&&t==e){u=null;return}var s=r.I,h=i.L;this.markers.push(this.drawArrow(n,t,f,e,o,s,h));this.markers.push(this.drawPoint(n,t,s,h));u={fromX:n,fromY:t,toX:f,toY:e,piece:o?"knight":"queen"}};this.moveArrows=[];this.clearMoveArrow=function(){this.moveArrows.length>0&&(this.moveArrows[0].remove(),this.moveArrows[1].remove(),this.moveArrows=[])};this.moveArrow=function(n){var t=r.I,u=i.L;return this.clearMoveArrow(),n.isNull||(this.moveArrows[0]=this.drawPoint(n.fromX,n.fromY,t,u,!0),this.moveArrows[1]=this.drawArrow(n.fromX,n.fromY,n.toX,n.toY,n.piece==="knight",t,u,!0)),this.moveArrows};this.drawMarkers=function(n){var i,t,r;for(this.clearMarkers(),f=n,i=n?n.split(" "):[],t=0;t<i.length;t++)i[t].toLowerCase()!=="x"&&(r=this.drawMarker(i[t]),this.markers.push(r))};this.addMarkers=function(n){for(var i=n?n.split(" "):[],r=[],u,t=0;t<i.length;t++)i[t].toLowerCase()!=="x"&&(u=this.drawMarker(i[t]),r.push(u));return r};this.onResize=function(n){this.squareSize=n;this.canvas&&this.canvas.remove();this.canvas=null;this.redrawMarkers()};this.redrawMarkers=function(){this.drawMarkers(f);u&&this.moveArrow(u)};this.getOffset=function(i,r){var u=t[i],f=9-r;return n.gui.flipped&&(u=9-u,f=9-f),n.isBoardrect&&(u-=t[n.startX]-1,f-=8-n.finishY),{left:(u-1)*this.squareSize,top:(f-1)*this.squareSize}}}function PlayControllerFactory(){this.CreatePlayController=function(n,t){return n=="ChessTask"?new ChessTaskPlayController(t):new DefaultPlayController}}function DefaultPlayController(){this.MoveMade=function(n,t){t(!0)}}function ChessTaskPlayController(n){var i=n.gui,r=$(n).data("serialized-state"),u=!1,f=$(n).data("move-callback"),t=chessBoardLang;this.MoveMade=function(n,e){var o=$(document).find("#puzzleMessage")[0],s=setTimeout(function(){o.innerHTML='<div class="ajaxload">'+t.checkingMove+"<\/div>"},300);$.ajax({type:"Post",url:f,dataType:"json",data:{MoveMade:n,SerializedState:r},context:o,complete:function(){clearTimeout(s)},success:function(n){var o,s,f,h,c,l;o=n.Result;s=n.Actions;r=n.SerializedState;i.BoardDisabled=n.IsFinished;u=n.IsFinished;i.TaskFinished=u;i.showActions(s);n.IsFinished?(h=$(document).find("#puzzle_information")[0],n.IsSolved?(f='<span class="accept_icon">'+t.problemSolved+" ("+n.Score+")<\/span>",$(h).addClass("solved")):(f='<span class="cancel_icon">'+t.problemUnsolved+" ("+n.Score+')<\/span><br/><span style="font-size:12px; font-weight: normal;">'+t.tooManyMistakes+"<\/span>",$(h).addClass("unsolved")),this.className="solved",$("#rate").length!=0&&$.fn.raty.readOnly(!1,"#rate"),$(".next_practice")&&$(".next_practice").show(),c=parseInt(n.ObtainedElo),l=c>=0?"+":"",n.IsUserCheater?$("#elo_change").html(t.UserIsCheater):n.IsRatingChanged?$("#elo_change").html(t.eloChange+" "+n.NewRating+" ( "+l+n.ObtainedElo+" )"):n.IsUserAuthenticated&&$("#elo_change").html(t.eloNotChanged),$("#task_info").hide(),$("#user_elo").html("("+n.NewRating+")")):o?(this.className="correct",f=t.correctMove):(this.className="incorrect",f=t.incorrectMove);this.innerHTML=f;e(o);s.length==0&&n.IsFinished&&$(".task_notation .line").addClass("active").live("click",function(){loadMove($(this).attr("data-fen"),this,$(this).attr("data-move"))})},error:function(){this.innerHTML=t.internalServerError;e(!1)}})}}function ObservableNotationRenderer(){NotationMove.prototype.moveNumber=function(){var t=this.fullMoves+(this.chessMove.color=="white"?".":"…")+"&nbsp;",n=this.chessMove.color=="white";return this.previousMove&&(n|=this.previousMove.variations.length>0,n|=this.previousMove.variationLevel!=this.variationLevel||this.previousMove.commentsAfter.length>0,n|=this.previousMove.chessMove.isNull),n?t:""};NotationMove.prototype.moveString=function(){return this.chessMove.isNull?"[…]":this.chessMove.AsString()};NotationMove.prototype.addAdditionalParams=function(){this.selected=ko.observable(!1);this.expanded=ko.observable(!1);this.incorrect=ko.observable(!1);this.line=null;this.observableCommentsAfter=ko.observableArray(this.commentsAfter)};var n=this;n.enabled=!0;n.parser=null;n.currentPGNId=null;n.games=[];n.currentGame=ko.observable();n.currentMove=ko.observable();n.notationUpdated=ko.observable(!1);n.markVariationsAsIncorrect=ko.observable(!1);n.notationMainLines=[];n.notation=ko.computed(function(){var t=n.notationUpdated();return n.notationUpdated(!1),n.notationMainLines[n.currentPGNId]});n.setEnabled=function(t){n.enabled=t===!1?!1:!0};n.addMove=function(t,i,r){for(var f=n.currentMove(),o=this.board,c=o.formMove(t.charAt(0),t.charAt(1),t.charAt(2),t.charAt(3),t.charAt(4)),l=f.nextMoves,e,a,s,h,v,y,u=0;u<l.length;u++)if(s=l[u].chessMove,s.equals(c)){n.setCurrentMove(l[u]);return}for(u=0;u<f.variations().length;u++)if(s=f.variations()[u]()[0].chessMove,s.equals(c)){n.setCurrentMove(f.variations()[u]()[0]);return}for(o.moveHandler(c),e=null,a=!1,u=0;u<l.length;u++)s=l[u],s.variationLevel==f.variationLevel&&(a=!0);a||!i?(i?(h=f.previousMove,h||(h=f),v=h.variationLevel+1):(h=f,v=f.variationLevel+1),e=new NotationMove(c,o.currentFEN(),o.currentMove=="white"?o.fullMoves-1:o.fullMoves,v,h),e.variations=ko.observableArray(),i||r||e.incorrect(!0),y=ko.observableArray([e]),e.line=y,f.variations.push(y)):(e=new NotationMove(c,o.currentFEN(),o.currentMove=="white"?o.fullMoves-1:o.fullMoves,f.variationLevel,f),e.variations=ko.observableArray(),e.line=f.line,f.nextMoves.push(e),f.line.push(e));e.expanded(!0);n.setCurrentMove(e)};n.setCurrentMove=function(t){if(!n.enabled)return!1;var i=n.currentMove();i&&i.selected(!1);n.currentMove(t);t.selected(!0)};n.goToStart=function(t){n.setCurrentMove(n.notationMainLines[t]()[0])};n.goToEnd=function(t){var i=n.notationMainLines[t]();i.length>0&&n.setCurrentMove(i[i.length-1])};n.goToNextMove=function(){var t=n.nextMove();t&&(t.chessMove.isNull?(n.setCurrentMove(t),n.goToNextMove()):n.setCurrentMove(t))};n.goToPreviousMove=function(){var t=n.previousMove();t&&(t.chessMove.isNull?(n.setCurrentMove(t),n.goToPreviousMove()):n.setCurrentMove(t))};n.nextMove=ko.computed(function(){var i=n.currentMove(),f=!1,r,t,u;if(i)for(r=i.nextMoves,t=0;t<r.length;t++)if(u=r[t],u.variationLevel==i.variationLevel){f=!0;break}return f?u:null});n.previousMove=ko.computed(function(){var t=n.currentMove();return t?t.previousMove:null});n.importFromPgn=function(t,i,r){var u=n.parser.parsePGN(t);n.games=u;n.currentPGNId=i;n.loadGame(r)};n.result=ko.computed(function(){var t=n.games[n.currentGame()];return t&&t.tags.Result?t.tags.Result.replace("1/2","½").replace("1/2","½").replace("-","&nbsp;-&nbsp;"):" * "});n.loadNextGame=function(){n.loadGame(n.currentGame()+1)};n.loadPreviousGame=function(){n.loadGame(n.currentGame()-1)};n.loadGame=function(t){var f=n.board,i=n.games,r=n.currentPGNId,u;n.parser.parseNotation(f,i[t],n.rulesChecker);u=i[t].mainLine;n.notationMainLines[r]=n.transformNotation(u);n.notationUpdated(!0);n.goToStart(r)};n.transformNotation=function(t){for(var u=ko.observableArray([]),f,r,e,i=0;i<t.length;i++){if(f=ko.observableArray(),t[i].variations.length>0)for(r=0;r<t[i].variations.length;r++)e=n.transformNotation(t[i].variations[r]),f.push(ko.observableArray(e));t[i].variations=f;t[i].line=u;u.push(t[i])}return u}}function chessGame(){this.notation;this.variations=[];this.variations[0]="";this.tags=[];this.mainLine=null}function NotationMove(n,t,i,r,u){var f=this;this.chessMove=n;this.fen=t;this.fullMoves=i;this.variations=[];this.commentsBefore=[];this.commentsAfter=[];this.shortCommentsAfter=[];this.shortCommentsBefore=[];this.markers="";this.nextMoves=[];this.previousMove=u;this.variationLevel=r;typeof this.addAdditionalParams=="function"&&this.addAdditionalParams()}function PgnParser(){var n=[];this.parsePGN=function(t){var e,u,s,f,r,h,o,c,i;if(n=[],t=t.replace(/\r\n/g,"\n"),t=t.replace(/\{([\W\w]*?)\}/g,function(t){return n.push(t.substring(1,t.length-1)),"{"+(n.length-1)+"} "}),e=[],t=t.replace(/"([^"\\\r\n]*(?:\\.[^"\\\r\n]*)*)"/g,function(t){var i=t.replace(/\{([\d]+)\}/g,function(t){return n[t.substring(1,t.length-1)]});return e.push(i.substring(1,i.length-1).replace(/\\/g,"")),'"'+(e.length-1)+'"'}),t=t.replace(/(;[\W\w]*?)\n/,function(t){var i=t.replace(/\{([\d]+)\}/g,function(t){return"{"+n[t.substring(1,t.length-1)]+"} "});return n.push(i.substring(1,i.length)),"{"+(n.length-1)+"}\n"}),u=t.match(/(\[[\W\w]*?(?:0-1|1-0|1\/2-1\/2|\*))(?:[\s]+|$)/g),s=[],u!=null)for(f=0;f<u.length;f++){for(r=new chessGame,h=u[f].match(/(\[[\W\w]*?\])/g),o=0;o<h.length;o++)c=h[o].match(/\[[\s]*([\w]+)[\s]*"([\d]+)"[\s]*\]/),r.tags[c[1]]=e[c[2]];for(i=u[f].replace(/(\[[\W\w]*?\])/g,""),i=i.replace(/\b[\d]+[\s]*[\.]+/g,"");/\([^\(\)]*?\)/.test(i);)i=i.replace(/\([^\(\)]*?\)/,function(n){return r.variations.push(n.substring(1,n.length-1)),"<"+(r.variations.length-1)+"> "});i=i.replace(/[\s]+(?:0-1|1-0|1\/2-1\/2|\*)[\s]+/,"");r.notation=i;s.push(r)}return s};this.parseNotation=function(n,t,i){var r=t.tags.SetUp&&t.tags.FEN?t.tags.FEN:"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";this.rules=i;n.loadFEN(r);t.startFen=r;t.mainLine=this.parseNotationTokens(n,t,t.notation,0,0,null)};this.parseNotationTokens=function(t,i,r,u,f,e){var ft=r.split(/[\s]+/),l,p=[],b=null,o=null,nt=[],d=[],tt,f=f,k=!0,et,it,rt,ot,ht,ct,v,s,y,a,h,c,ut,lt,g,w;for(u==0&&(et=t.formNullMove(),tt=t.currentFEN(),it=new NotationMove(et,tt,0,0,null),o=it,p.push(it)),rt=0,ot=ft.length;rt<ot;rt++){if(l=ft[rt],/[RBQKPN]?[a-h]?[1-8]?[x]?[a-h][1-8][=]?[QNRB]?[+#]?/i.test(l))b=this.parseMove(t,l),k=!1;else if(/(O-O-O|O-O)\+?/i.test(l))b=this.castle(t,l),k=!1;else if(/Z0/.test(l))b=t.formNullMove(),k=!0;else if(/<[\d]+>/.test(l)){if(k=!0,o==null)throw new Error("Error: variation without move");var st=parseInt(l.match(/<([\d]+)>/)[1]),at=tt,g=p[p.length-1];t.loadFEN(g.fen);ht=this.parseNotationTokens(t,i,i.variations[st],st,f+1,g);o.variations.push(ht);t.loadFEN(at)}else if(/\{[\d]+\}/.test(l))if(ct=l.match(/\{([\d]+)\}/)[1],v=n[ct],v=v.replace(/\$([\d]+)/g,function(n){return nagMatch(n.substr(1))}),v=v.replace(/\&lt\;/g,"<"),v=v.replace(/\&gt\;/g,">"),v=v.replace(/\&amp\;/g,"&"),s=v.match(/(?:\[\%t[\s]+(.*)\])?[\s]*(.*)/),s[1]&&!k)if(y=s[1].toLowerCase(),y=="blon")o.commentsBefore.push(s[2]);else if(y=="bshr"){if(s[2].length>0){for(h=searchBefore(s[2]),s[2]=h[0],c=1,a="";h[c]!=undefined&&h[c]!=null;)a+=h[c],c++;if(s[2].length>0)for(h=searchBadNAGs(s[2]),s[2]=h[0],c=1;h[c]!=undefined&&h[c]!=null;)a+=h[c],c++;a.length>0&&o.shortCommentsBefore.push(a);s[2].length>0&&o.commentsBefore.push(s[2])}}else y=="bmrk"?o.markers=s[2]:console.error("Тип комментария «"+y+"» не поддерживается");else{for(y=s[1]?s[1].toLowerCase():null,h=searchNAGs(s[2]),s[2]=h[0],c=1,a="";h[c]!=undefined&&h[c]!=null;)a+=h[c],c++;if(s[2].length>0)for(h=searchBadNAGs(s[2]),s[2]=h[0],c=1;h[c]!=undefined&&h[c]!=null;)a+=h[c],c++;a.length>0&&(o&&!k?o.shortCommentsAfter.push(a):nt.push(a));s[2].length>0&&(o&&!k?o.commentsAfter.push(s[2]):y&&y!="3anl"&&y!="bmrk"&&d.push(s[2]))}else/\$[\d]+/.test(l)&&(ut=l.match(/\$([\d]+)/)[1],ut=nagMatch(ut),o.shortCommentsAfter.push(ut));if(b){if(o!=null&&o!=it&&p.push(o),lt=t.fullMoves,t.moveHandler(b),tt=t.currentFEN(),g=p.length-1>=0?p[p.length-1]:e?e:null,o=new NotationMove(b,tt,lt,f,g),g&&!e&&g.nextMoves.push(o),e&&(e=null),nt.length>0){for(w=0;w++;w<nt.length)o.shortCommentsBefore.push(nt[w]);nt=[]}if(d.length>0){for(w=0;w++;w<d.length)o.commentsBefore.push(d[w]);o.commentsBefore.push(d);d=[]}b=null}}return o!=null&&o!=it&&p.push(o),p};this.parseMove=function(n,t){var i=t.match(/([RBQKPN])?([a-h])?([1-8])?([x])?([a-h])([1-8])([=]?)([QNRB]?)([+#]?)/),r,e,o,s,h,f;if(!i)throw new Error(Msg.format(Msg.t("parseMove : некорректная запись хода : {0}"),t));if(e=i[1],e)switch(e.toLowerCase()){case"r":r="rook";break;case"b":r="bishop";break;case"q":r="queen";break;case"n":r="knight";break;case"k":r="king"}else r="pawn";o=i[2];s=i[3];h=i[4]?!0:!1;var c=i[5],l=i[6],u=i[8].toLowerCase();if(u)switch(u){case"r":u="rook";break;case"b":u="bishop";break;case"q":u="queen";break;case"n":u="knight"}if(f=this.rules.getPieceCoords(n,r,o,s,c,l,h),!f)throw new Error(Msg.format(Msg.t("parseMove : нет доступных фигур для хода {0}"),t));return n.formMove(f[0],f[1],c,l,u,i[3]!==undefined,i[2]!==undefined)};this.castle=function(n,t){var i;return i=n.currentMove=="white"?1:8,/^O-O\+?$/.test(t)?n.formMove("e",i,"g",i,!1,!1,!1):n.formMove("e",i,"c",i)}}function searchBefore(n){var i=n.match(/\^[0-9]+/g),t,r,u;if(n=n.replace(/\^[0-9]+/g,""),r=0,t=[],t["178"]="²",t["179"]="³",t["177"]="±",t["181"]="µ",t["157"]="«",t["176"]="°",t["155"]="›",t["169"]="©",t["167"]="§",t["164"]="¤",t["165"]="¥",t["166"]="¦",t["163"]="£",t["162"]="¢",t["133"]="…",t["153"]="™",t["185"]="№",t["148"]="”",t["132"]="„",t["130"]="‚",t["131"]="»",t["146"]="’",t["145"]="‘",t["171"]="ť",t["172"]="¬",t["173"]="­",t["174"]="®",t["175"]="¯",t["147"]="ž",t["158"]="“",r=0,i==null)return i=[],i[0]=n,i;while(i[r]!=undefined&&i[r]!=null)r++;for(u=r;u>0;)i[u-1]=i[u-1].replace("^",""),i[u]=t[i[u-1]],u--;return r++,i[0]=n,i}function searchNAGs(n){for(var i=[],t=1;n.search("'with the idea'")!=-1;)n=n.replace("'with the idea'",""),i[t]="…",t++;while(n.search("'better is'")!=-1)n=n.replace("'better is'",""),i[t]="№",t++;while(n.search("'centre'")!=-1)n=n.replace("'centre'",""),i[t]="”",t++;while(n.search("'diagonals'")!=-1)n=n.replace("'diagonals'",""),i[t]="’",t++;while(n.search("'file'")!=-1)n=n.replace("'file'",""),i[t]="‘",t++;while(n.search("'queen's side'")!=-1)n=n.replace("'queen's side'",""),i[t]="ť",t++;while(n.search("'ending'")!=-1)n=n.replace("'ending'",""),i[t]="¬",t++;while(n.search("'pair of bishops'")!=-1)n=n.replace("'pair of bishops'",""),i[t]="­",t++;while(n.search("'bishops of opposite color'")!=-1)n=n.replace("'bishops of opposite color'",""),i[t]="®",t++;while(n.search("'bishops of the same color'")!=-1)n=n.replace("'bishops of the same color'",""),i[t]="¯",t++;while(n.search("'time'")!=-1)n=n.replace("'time'",""),i[t]="ž",t++;while(n.search("'passed pawn'")!=-1)n=n.replace("'passed pawn'",""),i[t]="“",t++;return i[0]=n,i}function searchBadNAGs(n){var t=[],i,r;if(n.replace(/[\sPNBRQK=!?]+/,"")==""){if(t=n.match(/[PNBRQK=]/g),n=n.replace(/[\sPNBRQK=]/g,""),signs=[],signs.P="§",signs.N="¤",signs.B="¥",signs.R="¦",signs.Q="£",signs.K="¢",signs["="]="=",i=0,t==null)return t=[],t[0]=n,t;while(t[i]!=undefined&&t[i]!=null)i++;for(r=0,r=i;r>0;r=r-1)t[r]=signs[t[r-1]];i++;n!=""&&(t[i]=n,n="")}return t[0]=n,t}function nagMatch(n){var t=[];return t["0"]="null annotation",t["1"]="good move",t["2"]="poor move",t["3"]="very good move",t["4"]="very poor move",t["5"]="speculative move",t["6"]="questionable move",t["7"]="forced move",t["8"]="singular move",t["9"]="worst move",t["10"]="drawish position",t["11"]="equal chances, quiet position",t["12"]="equal chances, active position",t["13"]="unclear position",t["14"]="White has a slight advantage",t["15"]="Black has a slight advantage",t["16"]="White has a moderate advantage",t["17"]="Black has a moderate advantage",t["18"]="White has a decisive advantage",t["19"]="Black has a decisive advantage",t["20"]="White has a crushing advantage",t["21"]="Black has a crushing advantage",t["22"]="White is in zugzwang",t["23"]="Black is in zugzwang",t["24"]="White has a slight space advantage",t["25"]="Black has a slight space advantage",t["26"]="White has a moderate space advantage",t["27"]="Black has a moderate space advantage",t["28"]="White has a decisive space advantage",t["29"]="Black has a decisive space advantage",t["30"]="White has a slight time advantage",t["31"]="Black has a slight time advantage",t["32"]="White has a moderate time advantage",t["33"]="Black has a moderate time advantage",t["34"]="White has a decisive time advantage",t["35"]="Black has a decisive time advantage",t["36"]="White has the initiative",t["37"]="Black has the initiative",t["38"]="White has a lasting initiative",t["39"]="Black has a lasting initiative",t["40"]="White has the attack",t["41"]="Black has the attack",t["42"]="White has insufficient compensation for material deficit",t["43"]="Black has insufficient compensation for material deficit",t["44"]="White has sufficient compensation for material deficit",t["45"]="Black has sufficient compensation for material deficit",t["46"]="White has more than adequate compensation for material deficit",t["47"]="Black has more than adequate compensation for material deficit",t["48"]="White has a slight center control advantage",t["49"]="Black has a slight center control advantage",t["50"]="White has a moderate center control advantage",t["51"]="Black has a moderate center control advantage",t["52"]="White has a decisive center control advantage",t["53"]="Black has a decisive center control advantage",t["54"]="White has a slight kingside control advantage",t["55"]="Black has a slight kingside control advantage",t["56"]="White has a moderate kingside control advantage",t["57"]="Black has a moderate kingside control advantage",t["58"]="White has a decisive kingside control advantage",t["59"]="Black has a decisive kingside control advantage",t["60"]="White has a slight queenside control advantage",t["61"]="Black has a slight queenside control advantage",t["62"]="White has a moderate queenside control advantage",t["63"]="Black has a moderate queenside control advantage",t["64"]="White has a decisive queenside control advantage",t["65"]="Black has a decisive queenside control advantage",t["66"]="White has a vulnerable first rank",t["67"]="Black has a vulnerable first rank",t["68"]="White has a well protected first rank",t["69"]="Black has a well protected first rank",t["70"]="White has a poorly protected king",t["71"]="Black has a poorly protected king",t["72"]="White has a well protected king",t["73"]="Black has a well protected king",t["74"]="White has a poorly placed king",t["75"]="Black has a poorly placed king",t["76"]="White has a well placed king",t["77"]="Black has a well placed king",t["78"]="White has a very weak pawn structure",t["79"]="Black has a very weak pawn structure",t["80"]="White has a moderately weak pawn structure",t["81"]="Black has a moderately weak pawn structure",t["82"]="White has a moderately strong pawn structure",t["83"]="Black has a moderately strong pawn structure",t["84"]="White has a very strong pawn structure",t["85"]="Black has a very strong pawn structure",t["86"]="White has poor knight placement",t["87"]="Black has poor knight placement",t["88"]="White has good knight placement",t["89"]="Black has good knight placement",t["90"]="White has poor bishop placement",t["91"]="Black has poor bishop placement",t["92"]="White has good bishop placement",t["93"]="Black has good bishop placement",t["84"]="White has poor rook placement",t["85"]="Black has poor rook placement",t["86"]="White has good rook placement",t["87"]="Black has good rook placement",t["98"]="White has poor queen placement",t["99"]="Black has poor queen placement",t["100"]="White has good queen placement",t["101"]="Black has good queen placement",t["102"]="White has poor piece coordination",t["103"]="Black has poor piece coordination",t["104"]="White has good piece coordination",t["105"]="Black has good piece coordination",t["106"]="White has played the opening very poorly",t["107"]="Black has played the opening very poorly",t["108"]="White has played the opening poorly",t["109"]="Black has played the opening poorly",t["110"]="White has played the opening well",t["111"]="Black has played the opening well",t["112"]="White has played the opening very well",t["113"]="Black has played the opening very well",t["114"]="White has played the middlegame very poorly",t["115"]="Black has played the middlegame very poorly",t["116"]="White has played the middlegame poorly",t["117"]="Black has played the middlegame poorly",t["118"]="White has played the middlegame well",t["119"]="Black has played the middlegame well",t["120"]="White has played the middlegame very well",t["121"]="Black has played the middlegame very well",t["122"]="White has played the ending very poorly",t["123"]="Black has played the ending very poorly",t["124"]="White has played the ending poorly",t["125"]="Black has played the ending poorly",t["126"]="White has played the ending well",t["127"]="Black has played the ending well",t["128"]="White has played the ending very well",t["129"]="Black has played the ending very well",t["130"]="White has slight counterplay",t["131"]="Black has slight counterplay",t["132"]="White has moderate counterplay",t["133"]="Black has moderate counterplay",t["134"]="White has decisive counterplay",t["135"]="Black has decisive counterplay",t["136"]="White has moderate time control pressure",t["137"]="Black has moderate time control pressure",t["138"]="White has severe time control pressure",t["139"]="Black has severe time control pressure",t["1"]="!",t["2"]="?",t["3"]="!!",t["4"]="??",t["5"]="!?",t["6"]="?!",t["16"]="±",t["17"]="µ",t["14"]="²",t["15"]="³",t["18"]="«",t["19"]="°",t["13"]="›",t["44"]="©",t["7"]="™",t["130"]="„",t["40"]="‚",t["36"]="»",t[n]==undefined||t[n]==null?(console.warn(Msg.t("NAG is not supported")),n):t[n]}function BoardSounds(n){var t=this;t.canPlayOgg=!1;t.canPlayMp3=!1;t.isMute=!1;t.sounds=[];t.mute=function(){t.isMute=!0;for(var n in t.sounds)t.sounds[n].muted=!0};t.unmute=function(){t.isMute=!1;for(var n in t.sounds)t.sounds[n].muted=!1};t.toggleMute=function(){t.isMute?t.unmute():t.mute()};t.init=function(){var r=document.createElement("audio"),i,u;if(t.canPlayOgg=!!r.canPlayType&&r.canPlayType("audio/ogg")!="",t.canPlayMp3=!!r.canPlayType&&r.canPlayType("audio/mp3")!="",t.canPlayAny=!!r.canPlayType,t.sounds_src=n,t.canPlayMp3||t.canPlayOgg)for(i in t.sounds_src)t.sounds[i]=document.createElement("audio"),t.sounds[i].src=t.sounds_src[i],t.sounds[i].src+=t.canPlayOgg?".ogg":".mp3",t.sounds[i].volume=1;u=localStorage!=undefined&&localStorage!=null;t.isMute=u&&localStorage.PageMutedIndex==="true"};t.play=function(n){if(n=="myTurn"||n=="enemyTurn"||n=="startGame"){var i=t.sounds[n];i&&i.play()}}}function NotationViewModel(n){var t=this;t.game=new ObservableNotationRenderer;t.savedFen=null;t.savedCurrentMove=null;n.setNotationRenderer(t.game);t.initGame=function(n){t.game.importFromPgn(n,"game_notation",0);t.game.goToStart("game_notation")};t.setCurrentMove=function(n,i){t.game.setCurrentMove(n);$(i.currentTarget).focus();PubSub.publish("update-fen");PubSub.publish("update_table_tree");PubSub.publish("init-tree-notation")};t.switchTurn=function(){if(t.game.board.switchMove(),document.getElementsByClassName("indicator black")[0].style.display=="none"?(document.getElementsByClassName("indicator black")[0].style.display="block",document.getElementsByClassName("indicator white")[0].style.display="none"):(document.getElementsByClassName("indicator black")[0].style.display="none",document.getElementsByClassName("indicator white")[0].style.display="block"),history.state)if(history.state.currentFen)history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:t.game.board.currentFEN(!0)},null,location.pathname);else{var n=history.state;history.pushState({probe:n.probe,tree:n.tree,currentFen:t.game.board.currentFEN(!0)},null,location.pathname)}else history.pushState({probe:null,tree:null,currentFen:t.game.board.currentFEN(!0)},null,location.pathname);PubSub.publish("update-fen")};t.switchEnPassant=function(n,i){if(t.game.board.switchEnPassant(i),history.state)if(history.state.currentFen)history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:t.game.board.currentFEN(!0)},null,location.pathname);else{var r=history.state;history.pushState({probe:r.probe,tree:r.tree,currentFen:t.game.board.currentFEN(!0)},null,location.pathname)}else history.pushState({probe:null,tree:null,currentFen:t.game.board.currentFEN(!0)},null,location.pathname);PubSub.publish("update-fen")};t.addMove=function(n){var i;if(n){t.savedCurrentMove||(t.savedCurrentMove=t.game.currentMove());var f=t.savedCurrentMove,r=t.game.board,u=r.formMoveFromString(n);r.moveHandler(u);i=jQuery.extend(!0,{},f);i.chessMove=u;i.fen=r.currentFEN();t.game.setCurrentMove(i)}}}function NetworkBoardGui(n){var t=this;t.probe=n.probe.probe;t.can7TbAccess=n.can7TbAccess;t.autoLoad=n.autoLoad;t.boardNotationWrapper=null;t.stateContainer=$("#state-container");t.boardWrapper=null;t.notationController=null;t.descriptionController=null;t.queriesController=null;t.favoritesController=null;t.draganddropController=null;t.likedislikeController=null;t.statisticsController=null;t.init=function(){var r,i;t.boardNotationWrapper=$(".full-notation-column");t.boardNotationWrapper.hide();t.boardWrapper=n.boardWrapper;$(t.boardWrapper).chessBoard(n.board);r=new smtbTwoClickAndDragBehavior;t.boardWrapper.setMouseBehavior(r);t.boardWrapper.mouseBehavior.playController=t;t.boardWrapper.notationController=t.notationController;t.boardWrapper.boardRenderer.gui.setEnabled(!0);t.notationController=new NotationViewModel(t.boardWrapper);t.descriptionController=new DescriptionViewModel;n.queriesController&&(t.queriesController=n.queriesController,t.queriesController.init(t));t.favoritesController=new Favorites;t.favoritesController.init(t.probe,t.can7TbAccess);t.draganddropController=new DragAndDrop;t.draganddropController.addDragDropSquares(t.boardWrapper.board.squares);ko.applyBindings(t.notationController,$("#board-notation-container").get(0));t.initNotationControlButtons();t.autoLoad&&($("#fen-value").val(t.probe.fen),t.probe.currentMetric=="dtz50"&&($("#metric-dtz50").attr("checked",!0),$("#metric-dtm").attr("checked",!1)),t.queriesController.LoadFen());i=document.cookie;i.lastIndexOf("lastFEN=")==-1||t.probe.fen||t.queriesController.CustomFen(i.substring(i.lastIndexOf("lastFEN=")+8,i.indexOf(";",i.lastIndexOf("lastFEN="))==-1?i.length:i.indexOf(";",i.lastIndexOf("lastFEN="))));t.likedislikeController=new Likedislike;t.likedislikeController.reloadLikedislikeButtons(t.probe);t.statisticsController=new Statistics;PubSub.publish("update-fen")};t.CleanBoard=function(){if(t.probe&&t.descriptionController.ChangeDescription(t.probe),t.notationController.initGame('[SetUp "1"] [FEN "8/8/8/8/8/8/8/8 w - - 0 1"] *'),PubSub.publish("hide_board"),PubSub.publish("update-fen"),history.state&&history.state.currentFen!="8/8/8/8/8/8/8/8 w - - 0 1")if(history.state)if(history.state.currentFen)history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:t.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname);else{var n=history.state;history.pushState({probe:n.probe,tree:n.tree,currentFen:t.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname)}else history.pushState({probe:null,tree:null,currentFen:t.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname)};t.UpdateFen=function(){$("#current-fen").val(t.boardWrapper.boardRenderer.board.currentFEN(!0));t.queriesController.switchEnPassantBtn.val(t.boardWrapper.boardRenderer.board.enPassant.substr(0,1))};t.UpdateStatisticsMask=function(n,i){i.x&&t.statisticsController.UpdateStatisticsMask(t.boardWrapper.boardRenderer.board.currentFEN(!0))?t.statisticsController.statisticsForm.show():t.statisticsController.statisticsForm.hide()};t.InitNewProbe=function(){t.probe&&(t.descriptionController.ChangeDescription(t.probe),t.notationController.initGame(t.probe.pgn),t.favoritesController.reloadAllFavoritesForm(t.probe),t.likedislikeController.reloadLikedislikeButtons(t.probe),history.state||(document.cookie="lastFEN="+t.probe.fen+"; path=/",history.replaceState({probe:t.probe,tree:null,currentFen:null},null,location.pathname)),t.boardNotationWrapper.show(),t.queriesController.OnGetAuthor(t.probe),PubSub.publish("update-statistics-mask",{x:!0}),t.probe.pgn.length>=370?$(".nano").nanoScroller():$(".nano").nanoScroller({stop:!0}));t.stateContainer.hide();PubSub.publish("update-fen");t.queriesController.tableTreeController.positionsArray.length==0&&history.state&&history.state.tree&&(t.queriesController.tableTreeController.positionsArray=history.state.tree);t.can7TbAccess||t.favoritesController.getFenFigureCount(t.notationController.game.board.currentFEN(!0))!=7?t.queriesController.treeSubmitBtn.show():t.queriesController.treeSubmitBtn.hide();history.state&&history.state.currentFen&&(t.boardWrapper.board.loadFEN(history.state.currentFen),t.boardWrapper.boardRenderer.gui.drawBoardPosition())};t.InitNewFailProbe=function(){t.probe&&t.descriptionController.ChangeDescription(t.probe);(history.state&&history.state.currentFen||t.probe&&t.probe.fen)&&(t.boardWrapper.board.loadFEN(history.state.currentFen?history.state.currentFen:t.probe.fen),t.boardWrapper.boardRenderer.gui.drawBoardPosition());t.stateContainer.hide();t.boardNotationWrapper.hide();PubSub.publish("update-fen")};t.UpdateFavorites=function(n,i){t.descriptionController.ChangeDescription(i);t.favoritesController.reloadAllFavoritesForm(i);t.likedislikeController.reloadLikedislikeButtons(i);t.stateContainer.hide()};t.InitBranchError=function(n,i){i&&(t.stateContainer.text(Errors(i.state,i.numberError)),t.stateContainer.show(),PubSub.publish("update-statistics-mask",{x:!1}))};t.UpdateProbe=function(n,i){t.probe=i};t.HideBoard=function(){t.boardNotationWrapper.hide();t.descriptionController.descriptionWrapper.hide();t.favoritesController.addToFavoritesForm.hide();t.queriesController.shareAuthorForm.hide()};t.SwitchBoardAndButtons=function(n,i){t.boardWrapper.boardRenderer.gui.setEnabled(!i);$("#board-shift-left").attr("disabled",i);$("#board-shift-up").attr("disabled",i);$("#board-shift-down").attr("disabled",i);$("#board-shift-right").attr("disabled",i);$("#switch-turn-btn").attr("disabled",i);$("#switch-en-passant-btn").attr("disabled",i);$("#clean-board-btn").attr("disabled",i);$("#metric-dtm").attr("disabled",i);$("#metric-dtz50").attr("disabled",i)};t.ShowActive=function(){var n=document.getElementsByClassName("notation-move active");n[0]&&(n[0].parentNode.parentNode.scrollTop=n[0].offsetTop)};t.initTreeNotation=function(){t.notationController.savedFen=null;t.notationController.savedCurrentMove=t.notationController.game.currentMove();$("#table-tree tbody tr").each(function(){$(this).on("click",function(n){var i=$(n.target),r;i=i.hasClass("table-tree-move")?i:i.prev().hasClass("table-tree-move")?i.prev():i.next();r=i.text();i.hasClass("table-tree-move")&&(r.match(/[A-Z][a-z][0-9][a-z][0-9]/)||r.match(/[A-Z][a-z][0-9]x[a-z][0-9]/)||r.match(/[a-z][0-9]/))||(r=null);t.notationController.savedFen?t.boardWrapper.board.loadFEN(t.notationController.savedFen):t.notationController.savedFen=t.boardWrapper.board.currentFEN(!0);t.notationController.addMove(r)})})};t.initNotationControlButtons=function(){$("#to-start-btn").click(function(){t.notationController.game.goToStart("game_notation");t.ShowActive(!0);PubSub.publish("update-fen");PubSub.publish("update_table_tree");PubSub.publish("init-tree-notation")});$("#to-end-btn").click(function(){t.notationController.game.goToEnd("game_notation");t.ShowActive(!0);PubSub.publish("update-fen");PubSub.publish("update_table_tree");PubSub.publish("init-tree-notation")});$("#back-btn").click(function(){t.notationController.game.goToPreviousMove();t.ShowActive(!0);PubSub.publish("update-fen");PubSub.publish("update_table_tree");PubSub.publish("init-tree-notation")});$("#forward-btn").click(function(){t.notationController.game.goToNextMove();t.ShowActive(!0);PubSub.publish("update-fen");PubSub.publish("update_table_tree");PubSub.publish("init-tree-notation")})};t.init()}function NetworkBoardGuiManager(n){var t=this;t.gui=new NetworkBoardGui(n);t.UpdateTableTree=function(){t.gui.queriesController&&t.gui.queriesController.tableTreeController&&t.gui.queriesController.tableTreeController.InitCurrentTree()};PubSub.subscribe("init_probe",t.gui.InitNewProbe);PubSub.subscribe("init_board",t.gui.InitNewBoard);PubSub.subscribe("clean_board",t.gui.CleanBoard);PubSub.subscribe("switch-turn",t.gui.notationController.switchTurn);PubSub.subscribe("switch-en-passant",t.gui.notationController.switchEnPassant);PubSub.subscribe("update-fen",t.gui.UpdateFen);PubSub.subscribe("init-tree-notation",t.gui.initTreeNotation);PubSub.subscribe("update-statistics-mask",t.gui.UpdateStatisticsMask);PubSub.subscribe("switch-board-and-buttons",t.gui.SwitchBoardAndButtons);PubSub.subscribe("init_branch_error",t.gui.InitBranchError);PubSub.subscribe("update_probe",t.gui.UpdateProbe);PubSub.subscribe("hide_board",t.gui.HideBoard);PubSub.subscribe("update_table_tree",t.UpdateTableTree);PubSub.subscribe("update-favorites",t.gui.UpdateFavorites);PubSub.subscribe("update-favorites-error",t.gui.InitBranchError);PubSub.subscribe("init_fail_probe",t.gui.InitNewFailProbe)}function Errors(n,t){var i;switch(n){case"inQueue":i=Msg.format(Msg.t("Serice overloaded. Try again later. Your queue number: {0}"),t);break;case"accessDenied":i=Msg.t("You are banned from using the service");break;case"userIsBanned":i=Msg.t("You are banned.");break;case"exceededCalls":i=Msg.t("Call limit reached");break;case"internalServerError":i=Msg.format(Msg.t("Internal server error. We will do our best to fix it: ERROR: {0}"),t);break;case"noTable":i=Msg.t("Table does not exist");break;case"currentlyNotAvailable":i=Msg.t("Table temporarily unavailable");break;case"invalidPosition":i=Msg.t("Inavlid position");break;case"noAccessToThisPosition":i=Msg.t("Position does not exist. The link must be invalid.");break;case"insufficientPrivilege":i=Msg.t("You don't have the required rights");break;case"longEnding":i=Msg.t("Use up to 7 pieces");break;case"noEmptyCell":i=Msg.t("No free slots to save the position");break;case"fenNotShared":i=Msg.t("Position does not exist");break;case"saveError":i=Msg.t("Error occurred while saving");break;case"wrongFen":i=Msg.t("Invalid FEN");break;case"noLicenseKey":i=Msg.t("You are not logged in as a VIP member");break;default:i=Msg.t("Unknown error")}return i}function DescriptionViewModel(){var n=this;n.descriptionWrapper=$(".theme-description-module");n.gameSummaryWrapper=$("#game-info-container");n.pgnReaderContainer=$("#pgn-reader-container");n.themeModule=$("#theme-text");n.descriptionModule=$("#description-text");n.result=null;n.resultModule=null;n.init=function(){n.gameSummaryWrapper!=null&&(n.themeModule.click(function(){this.innerHTML.length>120&&(this.style.whiteSpace=this.style.whiteSpace=="nowrap"?"normal":"nowrap")}),n.resultModule=$(document.createElement("span")),n.result=document.createElement("span"),n.resultModule.append(n.result),n.gameSummaryWrapper.append(n.resultModule),n.gameSummaryWrapper.hide())};n.ChangeDescription=function(t){if(t.theme||t.description?(n.descriptionWrapper.show(),t.theme?(n.themeModule[0].innerHTML=t.theme,n.themeModule[0].innerHTML.length>100?(n.themeModule[0].title=Msg.t("Maximize"),n.themeModule[0].style.whiteSpace="nowrap"):(n.themeModule[0].title="",n.themeModule[0].style.whiteSpace="normal"),n.themeModule.show()):n.themeModule.hide(),t.description?(n.descriptionModule[0].innerHTML=t.description,n.descriptionModule.show(),n.descriptionModule[0].innerHTML.length>120?(n.descriptionModule.addClass("collapsed"),n.descriptionModule.siblings(".theme-expander").show()):(n.descriptionModule.removeClass("collapsed"),n.descriptionModule.siblings(".theme-expander").hide())):(n.descriptionModule.siblings(".theme-expander").hide(),n.descriptionModule.hide())):n.descriptionWrapper.hide(),t.dtm||t.pgn)if(n.gameSummaryWrapper.show(),t.pgn&&t.dtm){var i=n.FetchTheResultFromPgn(t.pgn);i?(n.result.innerHTML=i+(t.dtm==-1?"":Math.round(t.dtm/2)),n.resultModule.show()):n.resultModule.hide()}else n.resultModule.hide();else n.gameSummaryWrapper.hide();n.pgnReaderContainer.text(t.pgn)};n.FetchTheResultFromPgn=function(n){return n.indexOf("1-0")>=0?Msg.t("White mates in")+" ":n.indexOf("0-1")>=0?Msg.t("Black mates in")+" ":n.indexOf("1/2-1/2")>=0?Msg.t("Draw"):""};n.init()}function DragAndDrop(){var n=this;n.init=function(){var r=$(".tableView"),i=$(document.createElement("div")),t,n;i.attr("class","figures-board");t=document.createElement("table");t.id="figures-table";n="";n+='<tr class="row8"><td id="dragdrop_left_top" class="white square coli"><div class="piece wking" data-dragdrop><\/div><\/td><td class="black square colj"><div class="piece bking" data-dragdrop><\/div><\/td><\/tr>\n';n+='<tr class="row7"><td class="white square coli"><div class="piece wqueen" data-dragdrop><\/div><\/td><td class="black square colj"><div class="piece bqueen" data-dragdrop><\/div><\/td><\/tr>\n';n+='<tr class="row6"><td class="white square coli"><div class="piece wrook" data-dragdrop><\/div><\/td><td class="black square colj"><div class="piece brook" data-dragdrop><\/div><\/td><\/tr>\n';n+='<tr class="row5"><td class="white square coli"><div class="piece wbishop" data-dragdrop><\/div><\/td><td class="black square colj"><div class="piece bbishop" data-dragdrop><\/div><\/td><\/tr>\n';n+='<tr class="row4"><td class="white square coli"><div class="piece wknight" data-dragdrop><\/div><\/td><td class="black square colj"><div class="piece bknight" data-dragdrop><\/div><\/td><\/tr>\n';n+='<tr class="row3"><td class="white square coli"><div class="piece wpawn" data-dragdrop><\/div><\/td><td class="black square colj"><div class="piece bpawn" data-dragdrop><\/div><\/td><\/tr>\n';n+='<tr class="row2"><td colspan="2" id="cancel-select" class="cancel-select"><i class="icon-remove"><\/i>'+Msg.t("Remove selection")+"<\/td><\/tr>\n";$(t).html(n);i.append(t);r.append(i)};n.addDragDropSquares=function(n){n.i=[];n.j=[];for(var t=3;t<=8;t++)n.i[t]=new boardSquare("i",t),n.i[t].piece=null,n.j[t]=new boardSquare("j",t),n.j[t].piece=null;n.i[3].piece=new boardPiece("pawn","white");n.i[3].piece.square=n.i[3];n.j[3].piece=new boardPiece("pawn","black");n.j[3].piece.square=n.j[3];n.i[4].piece=new boardPiece("knight","white");n.i[4].piece.square=n.i[4];n.j[4].piece=new boardPiece("knight","black");n.j[4].piece.square=n.j[4];n.i[5].piece=new boardPiece("bishop","white");n.i[5].piece.square=n.i[5];n.j[5].piece=new boardPiece("bishop","black");n.j[5].piece.square=n.j[5];n.i[6].piece=new boardPiece("rook","white");n.i[6].piece.square=n.i[6];n.j[6].piece=new boardPiece("rook","black");n.j[6].piece.square=n.j[6];n.i[7].piece=new boardPiece("queen","white");n.i[7].piece.square=n.i[7];n.j[7].piece=new boardPiece("queen","black");n.j[7].piece.square=n.j[7];n.i[8].piece=new boardPiece("king","white");n.i[8].piece.square=n.i[8];n.j[8].piece=new boardPiece("king","black");n.j[8].piece.square=n.j[8]};n.init()}var neutral_chessBoardLang,ChessTaskPlayer;chessBoard.prototype.loadFEN=function(n){for(var l,e,t,a,i,s,r,o,u,h,v,y,f=1,c=this.letters.length;f<c;f++)for(l=this.letters[f],e=1;e<=8;e++)this.squares[l][e].piece=null;for(this.pieces=[],t=n.split(" "),a=t[0].split("/"),i=1;i<=8;i++)for(s=a[i-1].split(""),r=1,o=1;o<=s.length;o++){if(u=s[o-1],/[rbqkpn]/.test(u))h="black";else if(/[RBQKPN]/.test(u))h="white";else{r=parseInt(r)+parseInt(u);continue}switch(u.toLowerCase()){case"r":name="rook";break;case"b":name="bishop";break;case"q":name="queen";break;case"k":name="king";break;case"p":name="pawn";break;case"n":name="knight"}v=this.letters[r];y=this.numbers[i];this.addPiece(name,h,v,y);r++}this.currentMove=t[1]=="b"?"black":"white";this.castling=t[2];this.enPassant=t[3];this.halfMoves=t[4]?t[4]:0;this.fullMoves=t[5]?t[5]:1};chessBoard.prototype.addPiece=function(n,t,i,r){if(this.squares[i][r].piece)throw new Error("Добавление фигур: на «"+i+r+"» уже есть фигура");var u=new boardPiece(n,t);u.square=this.squares[i][r];this.pieces.push(u);this.squares[i][r].piece=u};chessBoard.prototype.removePiece=function(n,t){var i=this.squares[n][t];i.piece&&(i.piece.square=null,i.piece=null)};chessBoard.prototype.formMoveFromString=function(n){var i=n.toLowerCase(),t;return i=="a1a1"||i=="z0"?this.formNullMove():(t=new PgnParser,t.rules=new chessRulesChecker,t.parseMove(this,n))};chessBoard.prototype.formNullMove=function(){return new chessMove};chessBoard.prototype.formMove=function(n,t,i,r,u,f,e){var v,y,w,b,p,k,g,c,nt,h,l,s,i,r;if(n=="a"&&t==1&&i=="a"&&r==1)return new chessMove;var d=this.squares[n][t].piece,a=d.name,o=new chessMove;if(o.piece=a,o.color=d.color,o.fromX=n,o.fromY=t,o.toX=i,o.toY=r,o.isNull=!1,o.promoteTo=u,o.shortAddDigit=!!f,o.shortAddLetter=!!e,u&&(o.promoteTo=u.length==1?this.pieceNames[u]:u),a=="king"&&Math.abs(this.letter[n]-this.letter[i])>1)this.letter[n]>this.letter[i]?(o.castling=-1,o.castleFromX="a",o.castleToX="d",o.castleFromY=t,o.castleToY=t):(o.castling=1,o.castleFromX="h",o.castleToX="f",o.castleFromY=t,o.castleToY=t);else if(a!="pawn"&&f===undefined&&e===undefined){for(h=0;h<this.pieces.length;h++)if((v=this.pieces[h],v.square)&&(y=v.square.x,w=v.square.y,this.currentMove==v.color&&a==v.name&&!(y==n&&w==t))){for(b=this.rules.getMoves(this,a,y,w,this.currentMove),p=!1,s=0;s<b.length;s++)if(b[s]==i+r.toString()){p=!0;break}y==n&&p&&(o.shortAddDigit=!0);p&&o.shortAddDigit==!1&&(o.shortAddLetter=!0)}}else a=="pawn"&&(k=this.currentMove=="white"?1:-1,i+r==this.enPassant&&this.squares[i][r-k].piece!=null&&(o.captured=!0,o.capturedSquare=this.squares[i][r-k]),(r==1||r==8)&&(o.promoteTo||(o.promoteTo=this.pieceNames.q)));if(o.captured=this.squares[i][r].piece!=null,g=this.currentFEN(),this.moveHandler(o),c=this.pieces[this.getPiece("king",this.currentMove)],c){if(nt={x:c.square.x,y:c.square.y,piece:c},o.check=this.rules.check(this.currentMove),o.check&&this.rules.king(c.square.x,c.square.y,this.currentMove).length==0)for(o.checkmate=!0,h=0;h<this.pieces.length;h++)if(l=this.pieces[h],l.color==this.currentMove&&l.square!=null){var tt=l.square.x,it=l.square.y,rt=this.currentFEN();for(conSq=eval("this.rules."+l.name+'("'+tt+'", '+it+', "'+l.color+'")'),s=0;s<conSq.length;s++)i=conSq[s][0],r=conSq[s][1],this.makeMove(tt,it,i,r),this.rules.check(this.currentMove)||(o.checkmate=!1),this.loadFEN(rt)}c.square=nt}return this.loadFEN(g),o};chessBoard.prototype.moveHandler=function(n){var f=n.piece,u=n.fromX,i=n.fromY,r=n.toX,t=n.toY,o=n.promoteTo,e;if(n.castling!==0){this.castle(n);return}n.isNull||this.makeMove(u,i,r,t);f=="pawn"?(e=this.currentMove=="white"?1:-1,r+t==this.enPassant&&(this.squares[r][t-e].piece.square=null,this.squares[r][t-e].piece=null),this.enPassant=Math.abs(t-i)==2?r+(parseInt(t)-e):"-",o&&(this.squares[r][t].piece.name=o)):(this.enPassant="-",f=="rook"&&this.castling!="-"&&(u=="a"&&i==8?this.castling=this.castling.replace(/q/,""):u=="h"&&i==8?this.castling=this.castling.replace(/k/,""):u=="a"&&i==1?this.castling=this.castling.replace(/Q/,""):u=="h"&&i==1&&(this.castling=this.castling.replace(/K/,""))),f=="king"&&this.castling!="-"&&(this.currentMove=="white"?(this.castling=this.castling.replace(/K/,""),this.castling=this.castling.replace(/Q/,"")):(this.castling=this.castling.replace(/k/,""),this.castling=this.castling.replace(/q/,""))),this.castling==""&&(this.castling="-"));f=="pawn"||o?this.halfMoves=0:this.halfMoves++;this.currentMove=="black"&&this.fullMoves++;this.switchMove()};chessBoard.prototype.castle=function(n){this.makeMove(n.fromX,n.fromY,n.toX,n.toY);this.makeMove(n.castleFromX,n.castleFromY,n.castleToX,n.castleToY);var t;t=n.color=="white"?/[KQ]/g:/[kq]/g;this.enPassant="-";this.halfMoves++;n.color=="black"&&this.fullMoves++;this.castling=this.castling.replace(t,"");this.castling==""&&(this.castling="-");this.switchMove()};chessBoard.prototype.getPiece=function(n,t,i,r){for(var f=[],u=0;u<this.pieces.length;u++)this.pieces[u].name==n&&this.pieces[u].color==t&&this.pieces[u].square!=null&&(i&&this.pieces[u].square.x==i||!i)&&(r&&this.pieces[u].square.y==r||!r)&&f.push(u);return f};chessBoard.prototype.getPieceAt=function(n,t){for(var i,r=0;r<this.pieces.length;r++)if(i=this.pieces[r],i.square!=null&&i.square.x==n&&i.square.y==t)return i;return null};chessBoard.prototype.switchMove=function(){this.currentMove=this.currentMove=="white"?"black":"white"};chessBoard.prototype.switchEnPassant=function(n){this.enPassant=n==="-"?n:n+(this.currentMove==="white"?"6":"3")};chessBoard.prototype.promoteTo=function(n,t,i,r,u,f){var e=this.formMove(n,t,i,r,u);f(e.LongString())};chessBoard.prototype.makeMove=function(n,t,i,r){var u=this.squares[n][t].piece;u.square=this.squares[i][r];this.squares[i][r].piece!=null&&(this.squares[i][r].piece.square=null);this.squares[i][r].piece=u;this.squares[n][t].piece=null};chessBoard.prototype.currentFEN=function(n){for(var t="",i,r,f,o,s,e,h,c,u=8;u>=1;u--){for(r=0,f=1,o=this.letters.length;f<o;f++)if(s=this.letters[f],e=this.squares[s][u].piece,e!=null){r!=0&&(t+=r,r=0);h=e.name;c=e.color;switch(h){case"rook":i="r";break;case"bishop":i="b";break;case"queen":i="q";break;case"king":i="k";break;case"pawn":i="p";break;case"knight":i="n"}c=="white"&&(i=i.toUpperCase());t+=i}else r++;r!=0&&(t+=r);u!=1&&(t+="/")}return t+=" "+this.currentMove.substr(0,1),t+=" "+this.castling,t+=" "+this.enPassant.substr(0,1)+(this.enPassant==="-"?"":this.currentMove==="white"?"6":"3"),n||(t+=" "+this.halfMoves,t+=" "+this.fullMoves),t};chessMove.prototype.piece=null;chessMove.prototype.fromX="a";chessMove.prototype.fromY=1;chessMove.prototype.toX="a";chessMove.prototype.toY=1;chessMove.prototype.promoteTo=null;chessMove.prototype.isNull=!0;chessMove.prototype.captured=!1;chessMove.prototype.shortAddLetter=!1;chessMove.prototype.shortAddDigit=!1;chessMove.prototype.color=null;chessMove.prototype.check=!1;chessMove.prototype.checkmate=!1;chessMove.prototype.castling=0;chessMove.prototype.pieceNames=[];chessMove.prototype.pieceNames.r='<span class="CAChess">&#xA6;<\/span>';chessMove.prototype.pieceNames.n='<span class="CAChess">&#xA4;<\/span>';chessMove.prototype.pieceNames.b='<span class="CAChess">&#xA5;<\/span>';chessMove.prototype.pieceNames.q='<span class="CAChess">&#xA3;<\/span>';chessMove.prototype.pieceNames.k='<span class="CAChess">&#xA2;<\/span>';chessMove.prototype.pieceNames.p='<span class="CAChess">&#xA7;<\/span>';chessMove.prototype.LongString=function(){return this.fromX+this.fromY+this.toX+this.toY+(this.promoteTo?this.promoteTo=="knight"?"n":this.promoteTo.charAt(0).toLowerCase():"")};chessMove.prototype.equals=function(n){return this.fromX==n.fromX&&this.fromY==n.fromY&&this.toX==n.toX&&this.toY==n.toY&&(this.promoteTo==n.promoteTo||!this.promoteTo&&!n.promoteTo)};chessMove.prototype.AsString=function(){if(this.isNull)return"Z0";var i=this.piece,n="",t="",r="",f="",e="",u=this.check?"+":"";return u=this.checkmate?"#":u,this.castling!=0?n+=this.castling==1?"O-O":"O-O-O":i=="pawn"?(this.captured||this.capturedSquare?(n=this.fromX,t=this.toX,r="x",t+=this.toY):t=this.toX+this.toY,this.promoteTo&&(e="="+this.pieceNames[this.promoteTo=="knight"?"n":this.promoteTo.charAt(0).toLowerCase()])):(this.captured&&(r="x"),f=this.pieceNames[i=="knight"?"n":i.charAt(0).toLowerCase()],this.shortAddLetter&&(n=this.fromX),this.shortAddDigit&&(n+=this.fromY),t=this.toX+this.toY),f+n+r+t+e+u};GUI.prototype.animateBlinkPiece=function(n,t,i){return new BlinkPieceAnimation(this,n,t,i)};GUI.prototype.animateMakeMove=function(n,t){return new MakeMoveAnimation(this,n,t)};GUI.prototype.animateMovePiece=function(n,t,i,r,u){return new MovePieceAnimation(this,n,t,i,r,u)};GUI.prototype.animateAddPiece=function(n,t,i,r,u){return new AddPieceAnimation(this,n,t,i,r,u)};GUI.prototype.animateRemovePiece=function(n,t,i){return new RemovePieceAnimation(this,n,t,i)};DeferredQueue=function(){this.promise=jQuery(this).promise()};DeferredQueue.prototype.append=function(){var n=arguments,t=n[0];if(!t||!jQuery.isFunction(t))throw new TypeError("1st parameter should be a function");return n=Array.prototype.slice.call(n,1),this.promise=this.promise.pipe(function(){return jQuery.Deferred(function(){return t.apply(this,n)}).promise()})},function(n){n.fn.callbackAnimate=function(t,i,r,u){return setTimeout(t,r),this.each(function(){n(this).animate(i,r,u)})};n.fn.deferredAnimate=function(t,i,r){var u=this;return n.Deferred(function(n){u.callbackAnimate(function(){n.resolve()},t,i,r)}).promise()}}(jQuery);var BlinkPieceAnimation=function(n,t,i,r){var u=jQuery.extend({speed:200,blinks:4},r);return jQuery.fn.blink=function(n){return n=jQuery.extend({speed:200,blinks:3,callback:null},n),this.each(function(){for(var t=0,i=1;i<=n.blinks;i++)$.browser.msie?$(this).animate({top:"+=0"},n.speed,function(){$(this).css("display","none")}).animate({top:"+=0"},n.speed,function(){t++;$(this).css("display","block");this.style.removeAttribute("filter");t==n.blinks&&jQuery.isFunction(n.callback)&&n.callback()}):$(this).fadeOut(n.speed).fadeIn(n.speed,function(){t++;t==n.blinks&&jQuery.isFunction(n.callback)&&n.callback()})})},jQuery.Deferred(function(r){var f=n.getPieceElement(t,i);jQuery(f).blink({speed:u.speen,blinks:u.blinks,callback:function(){r.resolve()}})}).promise()},RemovePieceAnimation=function(n,t,i,r){var u=jQuery.extend({speed:600,easing:null},r);return jQuery.Deferred(function(r){var f=n.getGUISquare(t,i),e=n.getPieceElement(t,i);jQuery(e).fadeOut(u.speed,u.easing,function(){jQuery(f).empty();r.resolve()})}).promise()},AddPieceAnimation=function(n,t,i,r,u,f){var e=jQuery.extend({speed:600,easing:null},f);return jQuery.Deferred(function(f){var o=n.makePieceElement(t,i,r,u),s;$(o).hide();s=n.getGUISquare(t,i);s.appendChild(o);jQuery(o).fadeIn(e.speed,e.easing,function(){f.resolve()})}).promise()},MovePieceAnimation=function(n,t,i,r,u,f){var e=jQuery.extend({duration:600,easing:null},f);return jQuery.Deferred(function(f){var h=n.getGUISquare(t,i),c=n.getGUISquare(r,u),o=jQuery(h).children()[0],a=jQuery(h).position(),s=jQuery(o).position(),v,y,l;o.style.left=s.left+"px";o.style.top=s.top+"px";v=s.left-a.left;y=s.top-a.top;o.style.position="absolute";l=jQuery(c).position();jQuery(o).animate({left:l.left+v,top:l.top+y},{duration:e.duration,easing:e.easing,complete:function(){jQuery(h).empty();jQuery(c).empty();jQuery(c).append(o);var n=o.style;n.position="relative";n.left="";n.top="";f.resolve()}})}).promise()},MakeMoveAnimation=function(n,t,i){var r=jQuery.extend({speed:600},i);return jQuery.Deferred(function(i){var f=function(){i.resolve()},u,e,o;if(t.isNull){f();return}u={duration:r.speed};t.castling?(e=(new jQuery.Deferred).resolve(),e.pipe(function(){return n.animateMovePiece(t.fromX,t.fromY,t.toX,t.toY,u)}).pipe(function(){return n.animateMovePiece(t.castleFromX,t.castleFromY,t.castleToX,t.castleToY,u)}).pipe(f)):t.promoteTo?(o=(new jQuery.Deferred).resolve(),o.pipe(function(){return n.animateMovePiece(t.fromX,t.fromY,t.toX,t.toY,u)}).pipe(function(){return n.animateRemovePiece(t.toX,t.toY,{speed:r.speed/2})}).pipe(function(){return n.animateAddPiece(t.toX,t.toY,t.promoteTo,t.color,{speed:r.speed/2})}).pipe(f)):t.capturedSquare?jQuery.when(n.animateMovePiece(t.fromX,t.fromY,t.toX,t.toY,u),n.animateRemovePiece(t.capturedSquare.x,t.capturedSquare.y,r.speed/2)).then(f):jQuery.when(n.animateMovePiece(t.fromX,t.fromY,t.toX,t.toY,u)).then(f)}).promise()},MouseBehavior=base2.Base.extend({boardWrapper:null,constructor:function(){},initialize:function(n){this.boardWrapper=n},remove:function(){this.boardWrapper=null},getSquareCoords:function(n){var t=this.boardWrapper.boardRenderer;if(t.visibleCols!=8||t.visibleRows!=8||n.button!=0)return null;var u=this.mouseCoords(n),e=t.boardTable.rows[1].cells[1],f=$(e).offset(),i=Math.floor((u.x-f.left)/t.squareSize)+1,r=8-Math.floor((u.y-f.top)/t.squareSize);return(t.gui.flipped&&(i=9-i,r=9-r),i<1||i>8||r<1||r>8)?null:{x:this.boardWrapper.board.letters[i],y:r}},mouseCoords:function(n){if(n.pageX||n.pageY)return{x:n.pageX,y:n.pageY};var t=document.body;return{x:n.clientX+t.scrollLeft-t.clientLeft,y:n.clientY+t.scrollTop-t.clientTop}},getMouseOffset:function(n){return{x:Math.floor(n/2),y:Math.floor(n/2)}}}),DragPiecesBehavior=MouseBehavior.extend({dragObject:null,dragFromCoords:null,mouseOffset:null,dropTargets:[],_boardPosition:null,initialize:function(n){this.base(n);$(this.boardWrapper).mousedown(this,this.onMouseDown);$(this.boardWrapper).mousemove(this,_.throttle(this.onMouseMove,23));$(document).mouseup(this,this.onMouseUp)},remove:function(){$(this.boardWrapper).unbind("mousedown");$(this.boardWrapper).unbind("mousemove");$(document).unbind("mouseup",this.onMouseUp);this.base()},onDrag:function(){return!0},onDrop:function(){return!0},onMovePiece:function(){},_addDropTarget:function(n){this.dropTargets.push(n)},onMouseMove:function(n){var t=n.data;if(!t.dragObject)return!0;var u=t.mouseCoords(n),r=this.boardRenderer.squareSize,i=15,f={y:u.y-r/2-t._boardPosition.top-i,x:u.x-r/2-t._boardPosition.left-i},e=t.dragObject.style;return e.top=f.y+i+"px",e.left=f.x+i-(r>61?2:0)+"px",!0},onMouseDown:function(n){var t=n.data,s=this.boardRenderer.gui,e,u,i,r;if(s.BoardDisabled)return!1;if(e=t.getSquareCoords(n),e!=null){if((u=t.premoveFromCoords,t.dragFromCoords=u?{x:u.x,y:u.y}:e,t.premoveFromCoords=null,t.dragFromCoords==null)||(i=s.getGUISquare(t.dragFromCoords.x,t.dragFromCoords.y).children[0],!i)||!t.onDrag(t.dragFromCoords))return!1;var h=t.mouseCoords(n),o=this.boardRenderer.squareSize,f=15;return t._boardPosition=$(this.boardRenderer.boardTable.rows[0].cells[0]).offset(),r={y:h.y-t._boardPosition.top-f,x:h.x-t._boardPosition.left-f},t.mouseOffset={x:r.x%o,y:r.y%o},i.style.position="absolute",i.style.top=r.y-t.mouseOffset.y+f+"px",i.style.left=r.x-t.mouseOffset.x+f-(o>61?2:0)+"px",t.dragObject=i,$(t.dragObject).addClass("dragging"),!0}},onMouseUp:function(n){var t=n.data,f=t.boardWrapper,e=f.boardRenderer.gui,i,u,r;if(e.BoardDisabled)return!1;if(t.dragObject==null)return!0;if(i=t.getSquareCoords(n),u=t.onDrop(i),u&&(r=t.dragFromCoords,i!=null&&r!=null&&!(i.x==r.x&&i.y==r.y)))t.onMovePiece(r,i);return t.dragObject&&(t.dragObject.style.position="static",t.dragObject.style.top="auto",t.dragObject.style.left="auto",$(t.dragObject).removeClass("dragging")),t.dropTargets=[],t.dragObject=null,!0}}),RulesBasedDragBehavior=DragPiecesBehavior.extend({possibleMoveSquares:[],playController:null,initialize:function(n){this.base(n)},showPossibleMoves:function(n){this._showPossibleMoves=n},remove:function(){this.base()},controlledSquares:function(n,t){var r=[],i=this.boardWrapper.board.squares[n][t].piece;return i!=undefined&&i.color==this.boardWrapper.playingColor&&(r=this.boardWrapper.rules.getMoves(this.boardWrapper.board,i.name,n,t,i.color)),r},onDrag:function(n){var i,t,r;if(this.possibleMoveSquares=this.controlledSquares(n.x,n.y),!this.possibleMoveSquares||this.possibleMoveSquares.length==0)return!1;for(i=this.boardWrapper.boardRenderer.gui,this._showPossibleMoves&&i.showControlled(this.possibleMoveSquares),t=0;t<this.possibleMoveSquares.length;t++)r=i.getGUISquare(this.possibleMoveSquares[t].charAt(0),this.possibleMoveSquares[t].charAt(1)),this.dropTargets.push(r);return!0},onDrop:function(n){var i=!1,r=this.boardWrapper.boardRenderer.gui,t;if(this._showPossibleMoves&&r.removeControlled(),n!=null)for(t=0;t<this.possibleMoveSquares.length;t++)n.x==this.possibleMoveSquares[t].charAt(0)&&n.y==this.possibleMoveSquares[t].charAt(1)&&(i=!0);return i?(this.possibleMoveSquares=[],!0):!1},onMovePiece:function(n,t){var i=this,h=i.boardWrapper.board.squares[n.x][n.y].piece,r=h.square,l=i.boardWrapper.boardRenderer.gui.getGUISquare(r.x,r.y),a=i.boardWrapper.boardRenderer.gui.getGUISquare(t.x,t.y),u,e,f,c,o,s;if(h.name=="pawn"&&(t.y==1||t.y==8)){i.boardWrapper.boardRenderer.gui.removePiece(t.x,t.y);u=this.boardWrapper.boardRenderer.promotionView;$(u).data("move","p"+r.x+r.y+t.x+t.y);e=["queen","rook","bishop","knight"];f=[];for(c in e)(function(n){var e=$(u).find("."+n);f.push(e);e[0].className=n+" piece "+i.boardWrapper.board.currentMove.charAt(0)+n;e.click(function(){for(var e in f)f[e].unbind("click");$(u).fadeOut();i.boardWrapper.board.promoteTo(r.x,r.y,t.x,t.y,n,function(u){i.boardWrapper.notationRenderer.setEnabled();i.playController.checkMove(u,function(u){s.style.position="static";u&&i.boardWrapper.boardRenderer.gui.makeMove(r.x,r.y,t.x,t.y,n)})})})})(e[c]);i.boardWrapper.notationRenderer.setEnabled(!1);i.boardWrapper.boardRenderer.gui.BoardDisabled=!0;o=i.boardWrapper.boardRenderer.boardTable;u.style.position="absolute";$(u).css("left",$(o).width()/2-$(u).width()/2+"px");$(u).css("top",$(o).height()/2-$(u).height()/2+"px");$(u).fadeIn();$(l).children().remove();$(a).append(i.dragObject);i.dragObject.style.position="static"}else return s=i.dragObject,i.dragObject=null,i.playController.checkMove(r.x+r.y+t.x+t.y,function(n){s.style.position="static";n&&i.boardWrapper.boardRenderer.gui.makeMove(r.x,r.y,t.x,t.y,null)}),!0;return!1},onGameStopped:function(){if(this.dragObject){this.onDrop(null);this.dragObject.style.position="static";$(this.dragObject).removeClass("dragging");this.dropTargets=[];this.dragObject=null}}}),SetupPositionBehavior=DragPiecesBehavior.extend({pieceSelector:null,selectorDragObject:null,constructor:function(n){this.base();this.pieceSelector=n;var t=["king","queen","bishop","knight","rook","pawn"],i=["white","black"];for(color in i)for(piece in t)$(this.pieceSelector).append('<div style="width: 50px; border: 1px solid transparent; float: left;"><div style="float:left;" class="piece '+i[color].charAt(0)+t[piece]+'" data-name="'+t[piece]+'" data-color="'+i[color]+'"><\/div><\/div>'),t[piece]=="pawn"&&i[color]=="white"&&$(this.pieceSelector).append('<div class="clear"><\/div>');$(this.pieceSelector).append("")},initialize:function(n){this.base(n);$(this.pieceSelector).find(".piece").mousedown(this,this.onPieceSelectorMouseDown);$(this.pieceSelector).parent().mousemove(this,this.onPieceSelectorMouseMove);$(this.pieceSelector).mouseup(this,this.onPieceSelectorMouseUp);n.onBoardDraw=this.setupRemoveButtons;n.onBoardDraw()},remove:function(){this.boardWrapper.onBoardDraw=null;$(this.pieceSelector).find(".piece").unbind("mousedown");$(this.pieceSelector).parent().unbind("mousemove");$(this.pieceSelector).parent().unbind("mouseup");this.base()},setupRemoveButtons:function(){var n=this.mouseBehavior;$(this).find(".piece:visible").each(function(){var t=document.createElement("a");t.className="remove-piece";t.setAttribute("href","javascript:void(0);");$(t).mousedown(n,n.onRemoveButtonMouseDown);$(this).append($(t))})},onRemoveButtonMouseDown:function(n){var t,i;return(n.which==1||n.which==2)&&(t=n.handleObj.data,t&&(i=t.getSquareCoords(n),t.removePiece(i.x,i.y))),!1},removePiece:function(n,t){return this.boardWrapper.board.removePiece(n,t),this.boardWrapper.boardRenderer.gui.drawBoardPosition(),!1},onDrag:function(n,t){if(t.which==2)return this.removePiece(n.x,n.y);var i=this,u=i.boardWrapper.boardRenderer.gui.getPieceElement(n.x,n.y),r=$(u).find(".remove-piece");return r&&r.hide(),$(this).find("td.white, td.black").each(function(){i.dropTargets.push(this)}),!0},onDrop:function(n){var i=this,r=i.boardWrapper.boardRenderer.gui.getPieceElement(n.x,n.y),t=$(r).find(".remove-piece");return t&&t.show(),this.base(n)},onMovePiece:function(n,t){var i=this.boardWrapper.board.squares,u=i[n.x][n.y].piece,r=i[t.x][t.y].piece;return i[n.x][n.y].piece=r,i[t.x][t.y].piece=u,u.square=i[t.x][t.y],r&&(r.square=i[n.x][n.y]),this.boardWrapper.boardRenderer.gui.drawBoardPosition(),!1},onMouseDown:function(n){var i=n.data,r=this.boardRenderer.gui,t;return r.BoardDisabled?!1:(this.dragFromCoords=i.getSquareCoords(n),this.dragFromCoords==null)?!0:(t=this.boardRenderer.gui.getGUISquare(this.dragFromCoords.x,this.dragFromCoords.y).children[0],!t)?!1:i.onDrag(this.dragFromCoords,n)?($(t).attr("data-original-z-index",t.style["z-index"]),t.style["z-index"]=4,this.base(n)):!1},onMouseUp:function(n){var t=n.data,i=t.boardWrapper.boardRenderer.gui;return i.BoardDisabled?!1:t.dragObject==null?!0:(t.dragObject.style["z-index"]=$(t.selectorDragObject).attr("data-original-z-index"),$(t.dragObject).removeAttr("data-original-z-index"),this.base(n))},onPieceSelectorMouseDown:function(n){var t=n.data,i,r;if(!t.pieceSelector||$(n.target).closest(t.pieceSelector).length!=1)return!0;i=this;$(i).attr("data-original-z-index",i.style["z-index"]);i.style["z-index"]=4;i.style.position="absolute";t.mouseOffset=t.getMouseOffset($(i).width());r=t.mouseCoords(n);i.style.top=r.y-t.mouseOffset.y+"px";i.style.left=r.x-t.mouseOffset.x+"px";t.selectorDragObject=i;$(this).find("td.white, td.black").each(function(){t.dropTargets.push(this)})},onPieceSelectorMouseMove:function(n){var t=n.data;if(!t.selectorDragObject)return!0;var i=t.selectorDragObject.style,r=t.mouseOffset,u=t.mouseCoords(n);return i.top=u.y-r.y+"px",i.left=u.x-r.x+"px",!0},onPieceSelectorMouseUp:function(n){var t=n.data,i,u,r;return t.selectorDragObject?(i=t.getSquareCoords(n),i!=null&&(u=$(t.selectorDragObject),r=t.boardWrapper.board,r.squares[i.x][i.y].piece!=null&&r.removePiece(i.x,i.y),r.addPiece(u.data("name"),u.data("color"),i.x,i.y),t.boardWrapper.boardRenderer.gui.drawBoardPosition()),t.dropTargets=[],t.selectorDragObject.style.position="static",t.selectorDragObject.style["z-index"]=$(t.selectorDragObject).attr("data-original-z-index"),$(t.selectorDragObject).removeAttr("data-original-z-index"),t.selectorDragObject=null,!0):!0}}),SetupElementsBehavior=SetupPositionBehavior.extend({taskContainer:null,constructor:function(n,t){this.pieceSelector=n;this.taskContainer=t},appendPiece:function(n,t,i){var r=n.boardRenderer.gui.getGUISquare(t.x,t.y),u=$(r).children();u.length==0?($(r).append(i),i.attr("data-x",t.x).attr("data-y",t.y)):i.siblings().hide()},onPieceSelectorMouseDown:function(n){return $(this).siblings().show(),this.base(n)},onPieceSelectorMouseUp:function(n){var t=n.data,i,r;return t.selectorDragObject?(i=t.getSquareCoords(n),i!=null?(r=$(t.selectorDragObject),t.appendPiece(t.boardWrapper,i,r)):$(t.selectorDragObject).siblings().hide(),t.dropTargets=[],t.selectorDragObject.style.position="static",t.selectorDragObject=null,!0):!0},onMovePiece:function(n,t){var i=this.boardWrapper.boardRenderer.gui.getGUISquare(n.x,n.y),r=$(i).children().length==1?$(i).children()[0]:null;return this.appendPiece(this.boardWrapper,t,$(r)),!1},onDrag:function(){var n=this;return $(this).find("td.white, td.black").each(function(){n.dropTargets.push(this)}),!0}}),ChooseSquaresBehavior=MouseBehavior.extend({choosenSquares:null,disabled:!1,initialize:function(n){this.choosenSquares=new GenericCollection("board coordinates");this.base(n);$(this.boardWrapper).mousedown(this,this.onChooseSquare)},remove:function(){$(this.boardWrapper).unbind("mousedown");this.base()},onChooseSquare:function(n){var i=n.data,t,u,r;return this.boardRenderer.gui.chooseItemDisabled||i.disabled?!1:(t=i.getSquareCoords(n),t==null)?!0:(u=$(this.boardRenderer.gui.getGUISquare(t.x,t.y)),!u||u.children().length==0)?!1:(r=i.choosenSquares,r.contains(t)?r.remove(t):r.add(t),i.drawSelectedPieces(),!1)},drawSelectedPieces:function(){var t,n,i,r;for($(this.boardWrapper).find("td.selected").removeClass("selected"),t=this.choosenSquares.dataHolder,n=0;n<t.length;n++)i=t[n],r=this.boardWrapper.boardRenderer.gui.getGUISquare(i.x,i.y),$(r).addClass("selected")}}),AdvancedChoosePiecesBehavior=ChooseSquaresBehavior.extend({rightChoiceAudio:null,wrongChoiceAudio:null,rightChoices:[],choseSqureCallback:null,remove:function(){this.choosenSquares.clear();this.drawSelectedPieces();this.base()},constructor:function(n){n&&(this.rightChoiceAudio={audio:n.rightChoiceAudio,wasPlayed:!1},this.wrongChoiceAudio={audio:n.wrongChoiceAudio,wasPlayed:!1},this.rightChoices=n.rightChoices,this.choseSqureCallback=n.choseSqureCallback);this.base()},showRightChoices:function(){for(var n in this.rightChoices)this.choosenSquares.add({x:this.rightChoices[n][0],y:this.rightChoices[n][1]});this.drawSelectedPieces()},onChooseSquare:function(n){var t=n.data,i,u,r;return this.gui.chooseItemDisabled||t.disabled?!1:(i=t.getSquareCoords(n),i==null)?!0:t.isSquareAvailable(i)===!1?!1:(u=i.x+i.y,t.rightChoices.indexOf(u)>=0?(r=t.choosenSquares,r.contains(i)||(t.playAudio(t.rightChoiceAudio),r.add(i),t.drawSelectedPieces(),t.choseSqureCallback&&t.choseSqureCallback(!0,i))):(t.playAudio(t.wrongChoiceAudio),t.choseSqureCallback&&t.choseSqureCallback(!1,i)),!1)},isSquareAvailable:function(n){var t=$(this.boardWrapper.boardRenderer.gui.getGUISquare(n.x,n.y));return!t||t.children().length==0?!1:!0},playAudio:function(n){if(n&&n.audio)try{n.wasPlayed&&(n.audio.src=n.audio.currentSrc);n.audio.load();n.audio.play();n.wasPlayed=!0}catch(t){}}}),AdvancedChooseSquaresBehavior=AdvancedChoosePiecesBehavior.extend({isSquareAvailable:function(){return!0}}),TwoClickAndDragBehavior=RulesBasedDragBehavior.extend({twoClicksDrag:!1,originalOnSelectStart:undefined,_documentOnSelectStart:function(){return!1},_enableDocumentSelect:function(){typeof this.originalOnSelectStart!="undefined"&&(document.onselectstart=this.originalOnSelectStart,this.originalOnSelectStart=function(){return!1})},_disableDocumentSelect:function(){typeof this.originalOnSelectStart=="undefined"&&(this.originalOnSelectStart=document.onselectstart,document.onselectstart=this._documentOnSelectStart)},initialize:function(n){this.base(n)},remove:function(){$(this.boardWrapper).unbind("mousedown");$(this.boardWrapper).unbind("mousemove");$(this.boardWrapper).unbind("mouseup");this.base()},onMouseMove:function(n){return n.data.twoClicksDrag?!0:this.base(n)},onMouseDown:function(n){var t=n.data,i=this.gui;if(i&&i.BoardDisabled)return!1;if(t._disableDocumentSelect(),t.twoClicksDrag){t.onMouseUp(n);return(t.setClickTimeout(t),t.isMadeMove)?!0:this.base(n)}return t.setClickTimeout(),this.base(n)},setClickTimeout:function(){var n=this;this.clickFlag=!0;this.clickTimeouts=this.clickTimeout||[];this.clickTimeouts.push(setTimeout(function(){n.clickFlag=!1},1e3))},clearTimeouts:function(){if(this.clickTimeouts)for(var n=this.clickTimeouts.length-1;n>=0;n--)clearTimeout(this.clickTimeouts[n])},onMouseUp:function(n){var t=n.data,s=t.boardWrapper,e=s.gui,r,u,i,f,o;if(e&&e.BoardDisabled)return!1;if(t.clearTimeouts(),t._enableDocumentSelect(),t.dragObject==null)return!0;if(r=t.dragObject,u=t.premoveFromCoords||t.dragFromCoords,t.premoveFromCoords=null,i=t.getSquareCoords(n),!u)return!1;if(t.isMadeMove=!1,i!=null){if(t.twoClicksDrag=!1,i.x==u.x&&i.y==u.y&&t.clickFlag)f=$(t.dragObject.parentNode),f.hasClass("start")?f.removeClass("start"):t.isPremove||(f.addClass("start"),t.twoClicksDrag=!0);else{if($(t.dragObject.parentNode).removeClass("start"),o=t.onDrop(i),o){t.onMovePiece(u,i);t.isMadeMove=!0}t.dropTargets=[];t.dragObject=null}r&&(r.style.position="static")}else if(r&&!t.twoClicksDrag){t.onDrop(i);$(t.dragObject.parentNode).removeClass("start");t.dropTargets=[];t.dragObject=null;r.style.position="static"}return!0},onBoardDraw:function(n){if(n)return!0;this.possibleMoveSquares=[];this.twoClicksDrag=!1;this.boardWrapper.gui.removeControlled()}}),PremoveBehavior=TwoClickAndDragBehavior.extend({initialize:function(n){this.base(n)},remove:function(){$(this.boardWrapper).unbind("mousedown");$(this.boardWrapper).unbind("mousemove");$(this.boardWrapper).unbind("mouseup");this.base()},onDrag:function(n){return this.isPremove?!0:this.base(n)},onMouseDown:function(n){var u,t,i;if(n.which!=1)return n.preventDefault(),!1;if(u=this.gui,u&&u.BoardDisabled)return!1;t=n.data;t._disableDocumentSelect();var h=t.boardWrapper.board.currentMove,e=t.boardWrapper.playingColor,o=h!=e;if(t.isPremove=o,t.isDragDrop=!0,!o)return this.base(n);if(i=t.getSquareCoords(n),i==null)return!0;var c=t.boardWrapper.board.squares,r=this.boardRenderer.gui.getGUISquare(i.x,i.y).children[0],s=t.getSquareCoords(n),f=c[s.x][s.y].piece;if(f&&f.color==e){if(t.premovePieceParent&&$(t.premovePieceParent).removeClass("premove-selected"),t.premovePieceElement==r){t.premovePieceElement=null;t.premovePiece=null;return}return t.premovePieceElement=r,t.premovePiece=f,$(r).parent().addClass("premove-selected"),t.premovePieceParent=$(r).parent(),this.base(n)}},onOpponentMove:function(n){if(this.isPremove&&this.premovePiece){if(this.isPremove=!1,this.premoveFromCoords=this.premovePiece.square,$(this.premovePieceParent).removeClass("premove-selected"),!this.premoveFromCoords)return!1;var t=this.boardWrapper.board.rules.getMoves(this.boardWrapper.board,this.premovePiece.name,this.premoveFromCoords.x,this.premoveFromCoords.y,this.boardWrapper.playingColor);if(t.length>0){this.onDrag(this.premovePiece.square);this.twoClicksDrag=!this.isDragDrop;this.dragObject=this.premovePieceElement;(n.charAt(2)!=this.premoveFromCoords.x||n.charAt(3)!=this.premoveFromCoords.y)&&$(this.premovePieceParent).addClass("start")}else{if(this.isDragDrop)return!0;this.twoClicksDrag=!1;this.premoveFromCoords=null;this.dragObject=null}this.premovePiece=null;this.premovePieceParent=null;this.isDragDrop=!1}},onBeforeOpponentMove:function(){this.drawBecauseOpponentMove=!0},onMouseUp:function(n){return(n.data.isDragDrop=!1,n.which!=1)?(n.preventDefault(),!1):this.base(n)},onBeforeRotate:function(){this.premovePieceParent&&$(this.premovePieceParent).removeClass("premove-selected")},onAfterRotate:function(){var n=this.premovePiece;n&&(this.premovePieceElement=this.boardWrapper.boardRenderer.gui.getGUISquare(n.square.x,n.square.y).children[0],this.premovePieceParent=this.premovePieceElement.parentNode,$(this.premovePieceParent).addClass("premove-selected"))},onBoardDraw:function(n){if(this.premovePiece&&!n){if(this.drawBecauseOpponentMove)return this.drawBecauseOpponentMove=!1,this.base(n);$(this.premovePieceParent).removeClass("premove-selected");this.premovePieceElement=null;this.premovePieceParent=null;this.isPremove=null;this.premovePiece=null}return this.base(n)}});(function(n){n.fn.chessBoard=function(t){return this.each(function(){if(this.boardTransformed)return this;if(this.board=new chessBoard(n(this).data("start-fen")),this.rules=this.board.rules,this.squareSize=n(this).data("square-size")||50,this.playingColor=t?t.playingColor:undefined,this.settings=n.extend({inverted:n(this).data("board-inverted")==!0||!1,enabled:n(this).data("enabled")||!0,chessBoardLang:neutral_chessBoardLang,displayCoordinates:n(this).data("rect"),squareSize:this.squareSize,markers:n(this).data("markers")||null},t),this.onBoardDraw=function(){},this.onBoardMove=function(){},this.renderEngine=n(this).data("render-engine"),this.renderEngine||(this.renderEngine="dom"),this.renderEngine=="dom"){this.boardRenderer=new DOMRenderEngine(this);var i=this.boardRenderer.createDOMModel();this.appendChild(i);this.boardRenderer.initStyles();this.boardRenderer.initRenderer()}return this.notationRenderer=null,this.setNotationRenderer=function(n){this.notationRenderer=n;this.notationRenderer.board=this.board;this.parser=new PgnParser;this.notationRenderer.parser=this.parser;this.rulesChecker=new chessRulesChecker;this.notationRenderer.rulesChecker=this.rulesChecker},this.resize=function(n){this.squareSize=n;this.boardRenderer.resize(n)},this.setMouseBehavior=function(n){this.renderEngine=="dom"&&(this.mouseBehavior=n,this.boardRenderer.setMouseBehavior(n))},this.removeMouseBehavior=function(){this.renderEngine=="dom"&&this.boardRenderer.removeMouseBehavior()},this.drawStartMarkers=function(){this.renderEngine=="dom"&&this.boardRenderer.drawStartMarkers()},this.renderEngine=="dom"&&(this.gui=this.boardRenderer.gui,this.boardTable=this.boardRenderer.boardTable,this.boardMarkers=this.boardRenderer.boardMarkers),this.boardTransformed=!0,this})}})(jQuery);neutral_chessBoardLang={flipBoard:Msg.t("Flip the board"),checkingMove:Msg.t("Checking move..."),correctMove:Msg.t("Right move!"),incorrectMove:Msg.t("Incorrect move"),problemSolved:Msg.t("Problem solved"),problemUnsolved:Msg.t("Not solved"),internalServerError:Msg.t("Internal server error."),yourTurn:Msg.t("It's your turn"),animating:Msg.t("Animating..."),eloChange:Msg.t("Your new ELO rating is"),eloNotChanged:Msg.t("Your ELO rating stay unchanged."),UserIsCheater:Msg.t("UserIsCheater"),tooManyMistakes:Msg.format(Msg.t("The percentage of correct moves must be greater than {0}%"),75)};ChessTaskPlayer=function(n){var t=this;t.IsFinished=!1;t.actionsQueue=new DeferredQueue;t.showingCallback=null;t.showedCallback=null;t.moveShowingCallback=null;t.showCommentCallback=null;t.showAction=function(i){var h=i.charAt(0),r=i.substr(1),u=n.gui,e,f,o,s;switch(h){case"p":n.board.loadFEN(r);n.gui.drawBoardPosition();break;case"m":return t.moveShowingCallback&&t.moveShowingCallback(),e=n.board.formMoveFromString(r),u.BoardDisabled=!0,f=u.animateMakeMove(e),$.when(f).then(function(){n.onBoardMove(r);u.BoardDisabled=!1}),f;case"b":return o=r.charAt(0),s=r.charAt(1),u.animateBlinkPiece(o,s);case"x":n.boardMarkers.drawMarkers(r);break;case"c":t.showCommentCallback&&t.showCommentCallback(r)}};this.showActions=function(n){var r=function(n){return t.showAction(n)},i;this.showingCallback&&this.showingCallback();for(i in n)this.actionsQueue.append(function(n){var t=r(n),i;t!=null?(i=this,t.then(function(){i.resolve()})):this.resolve()},n[i]);this.actionsQueue.append(function(){t.showedCallback&&t.showedCallback();this.resolve()})}};ko.bindingHandlers.chessNotation={init:function(){}};ko.bindingHandlers.chessBoard={init:function(n){jQuery(n).chessBoard()},update:function(n,t){var u=t(),i=ko.utils.unwrapObservable(u),r;i&&(n.board.loadFEN(i.fen),r=i.chessMove,n.boardRenderer.drawBoardPosition(),n.boardRenderer.notaDrawArrow(r))}},function(n){var o="0.4.0",u="hasOwnProperty",f=/[\.\/]/,s="*",h=function(){},c=function(n,t){return n-t},e,i,r={n:{}},t=function(n,u){var b=r,a=i,y=Array.prototype.slice.call(arguments,2),h=t.listeners(n),v=0,f,l=[],p={},s=[],o,w;for(e=n,i=0,o=0,w=h.length;o<w;o++)"zIndex"in h[o]&&(l.push(h[o].zIndex),h[o].zIndex<0&&(p[h[o].zIndex]=h[o]));for(l.sort(c);l[v]<0;)if(f=p[l[v++]],s.push(f.apply(u,y)),i)return i=a,s;for(o=0;o<w;o++)if(f=h[o],"zIndex"in f)if(f.zIndex==l[v]){if(s.push(f.apply(u,y)),i)return i=a,s;do if(v++,f=p[l[v]],f&&s.push(f.apply(u,y)),i)return i=a,s;while(f)}else p[f.zIndex]=f;else if(s.push(f.apply(u,y)),i)return i=a,s;return i=a,s.length?s:null};t.listeners=function(n){for(var a=n.split(f),t=r,i,v,o,e,p,h,c=[t],l=[],u=0,y=a.length;u<y;u++){for(h=[],e=0,p=c.length;e<p;e++)for(t=c[e].n,v=[t[a[u]],t[s]],o=2;o--;)i=v[o],i&&(h.push(i),l=l.concat(i.f||[]));c=h}return l};t.on=function(n,t){for(var e=n.split(f),i=r,u=0,o=e.length;u<o;u++)i=i.n,!i[e[u]]&&(i[e[u]]={n:{}}),i=i[e[u]];for(i.f=i.f||[],u=0,o=i.f.length;u<o;u++)if(i.f[u]==t)return h;return i.f.push(t),function(n){+n==+n&&(t.zIndex=+n)}};t.stop=function(){i=1};t.nt=function(n){return n?new RegExp("(?:\\.|\\/|^)"+n+"(?:\\.|\\/|$)").test(e):e};t.unbind=function(n,t){for(var v=n.split(f),i,o,l,e,p,c=[r],a,h=0,y=v.length;h<y;h++)for(e=0;e<c.length;e+=l.length-2){if(l=[e,1],i=c[e].n,v[h]!=s)i[v[h]]&&l.push(i[v[h]]);else for(o in i)i[u](o)&&l.push(i[o]);c.splice.apply(c,l)}for(h=0,y=c.length;h<y;h++)for(i=c[h];i.n;){if(t){if(i.f){for(e=0,p=i.f.length;e<p;e++)if(i.f[e]==t){i.f.splice(e,1);break}i.f.length||delete i.f}for(o in i.n)if(i.n[u](o)&&i.n[o].f){for(a=i.n[o].f,e=0,p=a.length;e<p;e++)if(a[e]==t){a.splice(e,1);break}a.length||delete i.n[o].f}}else{delete i.f;for(o in i.n)i.n[u](o)&&i.n[o].f&&delete i.n[o].f}i=i.n}};t.once=function(n,i){var r=function(){i.apply(this,arguments);t.unbind(n,r)};return t.on(n,r)};t.version=o;t.toString=function(){return"You are running Eve "+o};typeof module!="undefined"&&module.exports?module.exports=t:n.eve=t}(this),function(){function vt(t,i,r,o,s,l){var g,v,et,a,at,kt,ti,nt,vt,dt,yt,k,ut,st,ht,gt,ft,ct;r=e(r);var it,ot,pt,ni,wt,bt,w=t.ms,p={},d={},b={};if(o){for(v=0,et=f.length;v<et;v++)if(g=f[v],g.el.id==i.id&&g.anim==t){g.percent!=r?(f.splice(v,1),pt=1):ot=g;i.attr(g.totalOrigin);break}}else o=+d;for(v=0,et=t.percents.length;v<et;v++){if(t.percents[v]==r||t.percents[v]>o*t.top){r=t.percents[v];wt=t.percents[v-1]||0;w=w/t.top*(r-wt);ni=t.percents[v+1];it=t.anim[r];break}o&&i.attr(t.anim[t.percents[v]])}if(!!it){if(ot)ot.initstatus=o,ot.start=new Date-ot.ms*o;else{for(a in it)if(it[h](a)&&(ci[h](a)||i.paper.customAttributes[h](a))){p[a]=i.attr(a);p[a]==null&&(p[a]=su[a]);d[a]=it[a];switch(ci[a]){case c:b[a]=(d[a]-p[a])/w;break;case"colour":p[a]=n.getRGB(p[a]);at=n.getRGB(d[a]);b[a]={r:(at.r-p[a].r)/w,g:(at.g-p[a].g)/w,b:(at.b-p[a].b)/w};break;case"path":for(kt=lt(p[a],d[a]),ti=kt[1],p[a]=kt[0],b[a]=[],v=0,et=p[a].length;v<et;v++)for(b[a][v]=[0],nt=1,vt=p[a][v].length;nt<vt;nt++)b[a][v][nt]=(ti[v][nt]-p[a][v][nt])/w;break;case"transform":if(dt=i._,yt=rf(dt[a],d[a]),yt)for(p[a]=yt.from,d[a]=yt.to,b[a]=[],b[a].real=!0,v=0,et=p[a].length;v<et;v++)for(b[a][v]=[p[a][v][0]],nt=1,vt=p[a][v].length;nt<vt;nt++)b[a][v][nt]=(d[a][v][nt]-p[a][v][nt])/w;else k=i.matrix||new rt,ut={_:{transform:dt.transform},getBBox:function(){return i.getBBox(1)}},p[a]=[k.a,k.b,k.c,k.d,k.e,k.f],tf(ut,d[a]),d[a]=ut._.transform,b[a]=[(ut.matrix.a-k.a)/w,(ut.matrix.b-k.b)/w,(ut.matrix.c-k.c)/w,(ut.matrix.d-k.d)/w,(ut.matrix.e-k.e)/w,(ut.matrix.e-k.f)/w];break;case"csv":if(st=y(it[a])[tt](fi),ht=y(p[a])[tt](fi),a=="clip-rect")for(p[a]=ht,b[a]=[],v=ht.length;v--;)b[a][v]=(st[v]-p[a][v])/w;d[a]=st;break;default:for(st=[][u](it[a]),ht=[][u](p[a]),b[a]=[],v=i.paper.customAttributes[a].length;v--;)b[a][v]=((st[v]||0)-(ht[v]||0))/w}}if(gt=it.easing,ft=n.easing_formulas[gt],ft||(ft=y(gt).match(ou),ft&&ft.length==5?(ct=ft,ft=function(n){return nu(n,+ct[1],+ct[2],+ct[3],+ct[4],w)}):ft=pu),bt=it.start||t.start||+new Date,g={anim:t,percent:r,timestamp:bt,start:bt+(t.del||0),status:0,initstatus:o||0,stop:!1,ms:w,easing:ft,from:p,diff:b,to:d,el:i,callback:it.callback,prev:wt,next:ni,repeat:l||t.times,origin:i.attr(),totalOrigin:s},f.push(g),o&&!ot&&!pt&&(g.stop=!0,g.start=new Date-w*o,f.length==1))return gi();pt&&(g.start=new Date-g.ms*o);f.length==1&&gr(gi)}eve("anim.start."+i.id,i,t)}}function it(n,t){var i=[],u={},r;if(this.ms=t,this.times=1,n){for(r in n)n[h](r)&&(u[e(r)]=n[r],i.push(e(r)));i.sort(vu)}this.anim=u;this.top=i[i.length-1];this.percents=i}function nu(n,t,i,r,u,f){function a(n,t){for(var r,u,f,s,i=n,l=0;l<8;l++){if(f=h(i)-n,k(f)<t)return i;if(s=(3*c*i+2*o)*i+e,k(s)<1e-6)break;i=i-f/s}if(r=0,u=1,i=n,i<r)return r;if(i>u)return u;while(r<u){if(f=h(i),k(f-n)<t)return i;n>f?r=i:u=i;i=(u-r)/2+r}return i}function v(n,t){var i=a(n,t);return((y*i+l)*i+s)*i}function h(n){return((c*n+o)*n+e)*n}var e=3*t,o=3*(r-t)-e,c=1-e-o,s=3*i,l=3*(u-i)-s,y=1-s-l;return v(n,1/(200*f))}function tr(){return this.x+st+this.y+st+this.width+" × "+this.height}function rt(n,t,i,r,u,f){n!=null?(this.a=+n,this.b=+t,this.c=+i,this.d=+r,this.e=+u,this.f=+f):(this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0)}function ir(n){for(var u=[],t,i=0,r=n.length;r-2>i;i+=2)t=[{x:+n[i],y:+n[i+1]},{x:+n[i],y:+n[i+1]},{x:+n[i+2],y:+n[i+3]},{x:+n[i+4],y:+n[i+5]}],r-4==i?(t[0]={x:+n[i-2],y:+n[i-1]},t[3]=t[2]):i&&(t[0]={x:+n[i-2],y:+n[i-1]}),u.push(["C",(-t[0].x+6*t[1].x+t[2].x)/6,(-t[0].y+6*t[1].y+t[2].y)/6,(t[1].x+6*t[2].x-t[3].x)/6,(t[1].y+6*t[2].y-t[3].y)/6,t[2].x,t[2].y]);return u}function yt(){return this.hex}function v(n,t,i){function r(){var o=Array.prototype.slice.call(arguments,0),u=o.join("␀"),f=r.cache=r.cache||{},e=r.count=r.count||[];return f[h](u)?(tu(e,u),i?i(f[u]):f[u]):(e.length>=1e3&&delete f[e.shift()],e.push(u),f[u]=n[s](t,o),i?i(f[u]):f[u])}return r}function tu(n,t){for(var i=0,r=n.length;i<r;i++)if(n[i]===t)return n.push(n.splice(i,1)[0])}function n(t){var i,r;return n.is(t,"function")?ui?t():eve.on("DOMload",t):n.is(t,w)?n._engine.create[s](n,t.splice(0,3+n.is(t[0],c))).add(t):(i=Array.prototype.slice.call(arguments,0),n.is(i[i.length-1],"function"))?(r=i.pop(),ui?r.call(n._engine.create[s](n,i)):eve.on("DOMload",function(){r.call(n._engine.create[s](n,i))})):n._engine.create[s](n,arguments)}var bt,kt,wu,du,at,wi,et,br,d,ot,b,ri;n.version="2.0.1";n.eve=eve;var ui,fi=/[, ]+/,iu={circle:1,rect:1,path:1,ellipse:1,text:1,image:1},ru=/\{(\d+)\}/g,h="hasOwnProperty",t={doc:document,win:window},ei={was:Object.prototype[h].call(t.win,"Raphael"),is:t.win.Raphael},rr=function(){this.ca=this.customAttributes={}},o,s="apply",u="concat",oi="createTouch"in t.doc,g="",st=" ",y=String,tt="split",ur="click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[tt](st),si={mousedown:"touchstart",mousemove:"touchmove",mouseup:"touchend"},pt=y.prototype.toLowerCase,i=Math,l=i.max,nt=i.min,k=i.abs,a=i.pow,p=i.PI,c="number",wt="string",w="array",uu=Object.prototype.toString,hf=n._ISURL=/^url\(['"]?([^\)]+?)['"]?\)$/i,fu=/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,eu={NaN:1,Infinity:1,"-Infinity":1},ou=/^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,hi=i.round,e=parseFloat,ut=parseInt,fr=y.prototype.toUpperCase,su=n._availableAttrs={"arrow-end":"none","arrow-start":"none",blur:0,"clip-rect":"0 0 1e9 1e9",cursor:"default",cx:0,cy:0,fill:"#fff","fill-opacity":1,font:'10px "Arial"',"font-family":'"Arial"',"font-size":"10","font-style":"normal","font-weight":400,gradient:0,height:0,href:"http://raphaeljs.com/","letter-spacing":0,opacity:1,path:"M0,0",r:0,rx:0,ry:0,src:"",stroke:"#000","stroke-dasharray":"","stroke-linecap":"butt","stroke-linejoin":"butt","stroke-miterlimit":0,"stroke-opacity":1,"stroke-width":1,target:"_blank","text-anchor":"middle",title:"Raphael",transform:"",width:0,x:0,y:0},ci=n._availableAnimAttrs={blur:c,"clip-rect":"csv",cx:c,cy:c,fill:"colour","fill-opacity":c,"font-size":c,height:c,opacity:c,path:"path",r:c,rx:c,ry:c,stroke:"colour","stroke-opacity":c,"stroke-width":c,transform:"transform",width:c,x:c,y:c},li=/\s*,\s*/,hu={hs:1,rg:1},cu=/,?([achlmqrstvxz]),?/gi,lu=/([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,au=/([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,er=/(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,cf=n._radial_gradient=/^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,ht={},lf=function(n,t){return n.key-t.key},vu=function(n,t){return e(n)-e(t)},yu=function(){},pu=function(n){return n},ai=n._rectPath=function(n,t,i,r,u){return u?[["M",n+u,t],["l",i-u*2,0],["a",u,u,0,0,1,u,u],["l",0,r-u*2],["a",u,u,0,0,1,-u,u],["l",u*2-i,0],["a",u,u,0,0,1,-u,-u],["l",0,u*2-r],["a",u,u,0,0,1,u,-u],["z"]]:[["M",n,t],["l",i,0],["l",0,r],["l",-i,0],["z"]]},or=function(n,t,i,r){return r==null&&(r=i),[["M",n,t],["m",0,-r],["a",i,r,0,1,1,0,2*r],["a",i,r,0,1,1,0,-2*r],["z"]]},vi=n._getPath={path:function(n){return n.attr("path")},circle:function(n){var t=n.attrs;return or(t.cx,t.cy,t.r)},ellipse:function(n){var t=n.attrs;return or(t.cx,t.cy,t.rx,t.ry)},rect:function(n){var t=n.attrs;return ai(t.x,t.y,t.width,t.height,t.r)},image:function(n){var t=n.attrs;return ai(t.x,t.y,t.width,t.height)},text:function(n){var t=n._getBBox();return ai(t.x,t.y,t.width,t.height)}},sr=n.mapPath=function(n,t){if(!t)return n;var f,e,u,i,o,s,r;for(n=lt(n),u=0,o=n.length;u<o;u++)for(r=n[u],i=1,s=r.length;i<s;i+=2)f=t.x(r[i],r[i+1]),e=t.y(r[i],r[i+1]),r[i]=f,r[i+1]=e;return n};if(n._g=t,n.type=t.win.SVGAngle||t.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1")?"SVG":"VML",n.type=="VML"){if(bt=t.doc.createElement("div"),bt.innerHTML='<v:shape adj="1"/>',kt=bt.firstChild,kt.style.behavior="url(#default#VML)",!kt||typeof kt.adj!="object")return n.type=g;bt=null}n.svg=!(n.vml=n.type=="VML");n._Paper=rr;n.fn=o=rr.prototype=n.prototype;n._id=0;n._oid=0;n.is=function(n,t){return(t=pt.call(t),t=="finite")?!eu[h](+n):t=="array"?n instanceof Array:t=="null"&&n===null||t==typeof n&&n!==null||t=="object"&&n===Object(n)||t=="array"&&Array.isArray&&Array.isArray(n)||uu.call(n).slice(8,-1).toLowerCase()==t};n.angle=function(t,r,u,f,e,o){if(e==null){var s=t-u,h=r-f;return!s&&!h?0:(180+i.atan2(-h,-s)*180/p+360)%360}return n.angle(t,r,e,o)-n.angle(u,f,e,o)};n.rad=function(n){return n%360*p/180};n.deg=function(n){return n*180/p%360};n.snapTo=function(t,i,r){var f,u;if(r=n.is(r,"finite")?r:10,n.is(t,w)){for(f=t.length;f--;)if(k(t[f]-i)<=r)return t[f]}else{if(t=+t,u=i%t,u<r)return i-u;if(u>t-r)return i-u+t}return i};wu=n.createUUID=function(n,t){return function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(n,t).toUpperCase()}}(/[xy]/g,function(n){var t=i.random()*16|0,r=n=="x"?t:t&3|8;return r.toString(16)});n.setWindow=function(i){eve("setWindow",n,t.win,i);t.win=i;t.doc=t.win.document;n._engine.initWin&&n._engine.initWin(t.win)};var dt=function(i){var e,u,f,o,r;if(n.vml){e=/^\s+|\s+$/g;try{f=new ActiveXObject("htmlfile");f.write("<body>");f.close();u=f.body}catch(s){u=createPopup().document.body}o=u.createTextRange();dt=v(function(n){try{u.style.color=y(n).replace(e,g);var t=o.queryCommandValue("ForeColor");return t=(t&255)<<16|t&65280|(t&16711680)>>>16,"#"+("000000"+t.toString(16)).slice(-6)}catch(i){return"none"}})}else r=t.doc.createElement("i"),r.title="Raphaël Colour Picker",r.style.display="none",t.doc.body.appendChild(r),dt=v(function(n){return r.style.color=n,t.doc.defaultView.getComputedStyle(r,g).getPropertyValue("color")});return dt(i)},bu=function(){return"hsb("+[this.h,this.s,this.b]+")"},ku=function(){return"hsl("+[this.h,this.s,this.l]+")"},hr=function(){return this.hex},cr=function(t,i,r){if(i==null&&n.is(t,"object")&&"r"in t&&"g"in t&&"b"in t&&(r=t.b,i=t.g,t=t.r),i==null&&n.is(t,wt)){var u=n.getRGB(t);t=u.r;i=u.g;r=u.b}return(t>1||i>1||r>1)&&(t/=255,i/=255,r/=255),[t,i,r]},lr=function(t,i,r,u){t*=255;i*=255;r*=255;var f={r:t,g:i,b:r,hex:n.rgb(t,i,r),toString:hr};return n.is(u,"finite")&&(f.opacity=u),f};n.color=function(t){var i;return n.is(t,"object")&&"h"in t&&"s"in t&&"b"in t?(i=n.hsb2rgb(t),t.r=i.r,t.g=i.g,t.b=i.b,t.hex=i.hex):n.is(t,"object")&&"h"in t&&"s"in t&&"l"in t?(i=n.hsl2rgb(t),t.r=i.r,t.g=i.g,t.b=i.b,t.hex=i.hex):(n.is(t,"string")&&(t=n.getRGB(t)),n.is(t,"object")&&"r"in t&&"g"in t&&"b"in t?(i=n.rgb2hsl(t),t.h=i.h,t.s=i.s,t.l=i.l,i=n.rgb2hsb(t),t.v=i.b):(t={hex:"none"},t.r=t.g=t.b=t.h=t.s=t.v=t.l=-1)),t.toString=hr,t};n.hsb2rgb=function(n,t,i,r){this.is(n,"object")&&"h"in n&&"s"in n&&"b"in n&&(i=n.b,t=n.s,n=n.h,r=n.o);n*=360;var e,o,s,f,u;return n=n%360/60,u=i*t,f=u*(1-k(n%2-1)),e=o=s=i-u,n=~~n,e+=[u,f,0,0,f,u][n],o+=[f,u,u,f,0,0][n],s+=[0,0,f,u,u,f][n],lr(e,o,s,r)};n.hsl2rgb=function(n,t,i,r){this.is(n,"object")&&"h"in n&&"s"in n&&"l"in n&&(i=n.l,t=n.s,n=n.h);(n>1||t>1||i>1)&&(n/=360,t/=100,i/=100);n*=360;var e,o,s,f,u;return n=n%360/60,u=2*t*(i<.5?i:1-i),f=u*(1-k(n%2-1)),e=o=s=i-u/2,n=~~n,e+=[u,f,0,0,f,u][n],o+=[f,u,u,f,0,0][n],s+=[0,0,f,u,u,f][n],lr(e,o,s,r)};n.rgb2hsb=function(n,t,i){i=cr(n,t,i);n=i[0];t=i[1];i=i[2];var f,e,u,r;return u=l(n,t,i),r=u-nt(n,t,i),f=r==0?null:u==n?(t-i)/r:u==t?(i-n)/r+2:(n-t)/r+4,f=(f+360)%6/6,e=r==0?0:r/u,{h:f,s:e,b:u,toString:bu}};n.rgb2hsl=function(n,t,i){i=cr(n,t,i);n=i[0];t=i[1];i=i[2];var e,s,u,f,o,r;return f=l(n,t,i),o=nt(n,t,i),r=f-o,e=r==0?null:f==n?(t-i)/r:f==t?(i-n)/r+2:(n-t)/r+4,e=(e+360)%6/6,u=(f+o)/2,s=r==0?0:u<.5?r/(2*u):r/(2-2*u),{h:e,s:s,l:u,toString:ku}};n._path2string=function(){return this.join(",").replace(cu,"$1")};du=n._preload=function(n,i){var r=t.doc.createElement("img");r.style.cssText="position:absolute;left:-9999em;top:-9999em";r.onload=function(){i.call(this);this.onload=null;t.doc.body.removeChild(this)};r.onerror=function(){t.doc.body.removeChild(this)};t.doc.body.appendChild(r);r.src=n};n.getRGB=v(function(t){if(!t||!!((t=y(t)).indexOf("-")+1))return{r:-1,g:-1,b:-1,hex:"none",error:1,toString:yt};if(t=="none")return{r:-1,g:-1,b:-1,hex:"none",toString:yt};hu[h](t.toLowerCase().substring(0,2))||t.charAt()=="#"||(t=dt(t));var u,f,o,s,c,i,r=t.match(fu);return r?(r[2]&&(o=ut(r[2].substring(5),16),f=ut(r[2].substring(3,5),16),u=ut(r[2].substring(1,3),16)),r[3]&&(o=ut((c=r[3].charAt(3))+c,16),f=ut((c=r[3].charAt(2))+c,16),u=ut((c=r[3].charAt(1))+c,16)),r[4]&&(i=r[4][tt](li),u=e(i[0]),i[0].slice(-1)=="%"&&(u*=2.55),f=e(i[1]),i[1].slice(-1)=="%"&&(f*=2.55),o=e(i[2]),i[2].slice(-1)=="%"&&(o*=2.55),r[1].toLowerCase().slice(0,4)=="rgba"&&(s=e(i[3])),i[3]&&i[3].slice(-1)=="%"&&(s/=100)),r[5])?(i=r[5][tt](li),u=e(i[0]),i[0].slice(-1)=="%"&&(u*=2.55),f=e(i[1]),i[1].slice(-1)=="%"&&(f*=2.55),o=e(i[2]),i[2].slice(-1)=="%"&&(o*=2.55),(i[0].slice(-3)=="deg"||i[0].slice(-1)=="°")&&(u/=360),r[1].toLowerCase().slice(0,4)=="hsba"&&(s=e(i[3])),i[3]&&i[3].slice(-1)=="%"&&(s/=100),n.hsb2rgb(u,f,o,s)):r[6]?(i=r[6][tt](li),u=e(i[0]),i[0].slice(-1)=="%"&&(u*=2.55),f=e(i[1]),i[1].slice(-1)=="%"&&(f*=2.55),o=e(i[2]),i[2].slice(-1)=="%"&&(o*=2.55),(i[0].slice(-3)=="deg"||i[0].slice(-1)=="°")&&(u/=360),r[1].toLowerCase().slice(0,4)=="hsla"&&(s=e(i[3])),i[3]&&i[3].slice(-1)=="%"&&(s/=100),n.hsl2rgb(u,f,o,s)):(r={r:u,g:f,b:o,toString:yt},r.hex="#"+(16777216|o|f<<8|u<<16).toString(16).slice(1),n.is(s,"finite")&&(r.opacity=s),r):{r:-1,g:-1,b:-1,hex:"none",error:1,toString:yt}},n);n.hsb=v(function(t,i,r){return n.hsb2rgb(t,i,r).hex});n.hsl=v(function(t,i,r){return n.hsl2rgb(t,i,r).hex});n.rgb=v(function(n,t,i){return"#"+(16777216|i|t<<8|n<<16).toString(16).slice(1)});n.getColor=function(n){var t=this.getColor.start=this.getColor.start||{h:0,s:1,b:n||.75},i=this.hsb2rgb(t.h,t.s,t.b);return t.h+=.075,t.h>1&&(t.h=0,t.s-=.2,t.s<=0&&(this.getColor.start={h:0,s:1,b:t.b})),i.hex};n.getColor.reset=function(){delete this.start};n.parsePathString=v(function(t){if(!t)return null;var r={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0},i=[];return n.is(t,w)&&n.is(t[0],w)&&(i=ct(t)),i.length||y(t).replace(lu,function(n,t,f){var e=[],o=t.toLowerCase();if(f.replace(er,function(n,t){t&&e.push(+t)}),o=="m"&&e.length>2&&(i.push([t][u](e.splice(0,2))),o="l",t=t=="m"?"l":"L"),o=="r")i.push([t][u](e));else while(e.length>=r[o])if(i.push([t][u](e.splice(0,r[o]))),!r[o])break}),i.toString=n._path2string,i});n.parseTransformString=v(function(t){if(!t)return null;var i=[];return n.is(t,w)&&n.is(t[0],w)&&(i=ct(t)),i.length||y(t).replace(au,function(n,t,r){var f=[],e=pt.call(t);r.replace(er,function(n,t){t&&f.push(+t)});i.push([t][u](f))}),i.toString=n._path2string,i});n.findDotsAtSegment=function(n,t,r,u,f,e,o,s,h){var c=1-h,k=a(c,3),d=a(c,2),l=h*h,g=l*h,tt=k*n+d*3*h*r+c*3*h*h*f+g*o,it=k*t+d*3*h*u+c*3*h*h*e+g*s,v=n+2*h*(r-n)+l*(f-2*r+n),y=t+2*h*(u-t)+l*(e-2*u+t),w=r+2*h*(f-r)+l*(o-2*f+r),b=u+2*h*(e-u)+l*(s-2*e+u),rt=c*n+h*r,ut=c*t+h*u,ft=c*f+h*o,et=c*e+h*s,nt=90-i.atan2(v-w,y-b)*180/p;return(v>w||y<b)&&(nt+=180),{x:tt,y:it,m:{x:v,y:y},n:{x:w,y:b},start:{x:rt,y:ut},end:{x:ft,y:et},alpha:nt}};n._removedFactory=function(n){return function(){throw new Error("Raphaël: you are calling to method “"+n+"” of removed object");}};var ar=v(function(n){var h,v,f,c,a;if(!n)return{x:0,y:0,width:0,height:0};n=lt(n);var e=0,o=0,i=[],r=[],t;for(h=0,v=n.length;h<v;h++)t=n[h],t[0]=="M"?(e=t[1],o=t[2],i.push(e),r.push(o)):(f=nf(e,o,t[1],t[2],t[3],t[4],t[5],t[6]),i=i[u](f.min.x,f.max.x),r=r[u](f.min.y,f.max.y),e=t[5],o=t[6]);return c=nt[s](0,i),a=nt[s](0,r),{x:c,y:a,width:l[s](0,i)-c,height:l[s](0,r)-a}},null,function(n){return{x:n.x,y:n.y,width:n.width,height:n.height}}),ct=function(t){var u=[],i,f,r,e;for(n.is(t,w)&&n.is(t&&t[0],w)||(t=n.parsePathString(t)),i=0,f=t.length;i<f;i++)for(u[i]=[],r=0,e=t[i].length;r<e;r++)u[i][r]=t[i][r];return u.toString=n._path2string,u},gu=n._pathToRelative=v(function(t){var r,y,u,i,s,p,h,b,c;n.is(t,w)&&n.is(t&&t[0],w)||(t=n.parsePathString(t));var f=[],o=0,e=0,l=0,a=0,v=0;for(t[0][0]=="M"&&(o=t[0][1],e=t[0][2],l=o,a=e,v++,f.push(["M",o,e])),r=v,y=t.length;r<y;r++){if(u=f[r]=[],i=t[r],i[0]!=pt.call(i[0])){u[0]=pt.call(i[0]);switch(u[0]){case"a":u[1]=i[1];u[2]=i[2];u[3]=i[3];u[4]=i[4];u[5]=i[5];u[6]=+(i[6]-o).toFixed(3);u[7]=+(i[7]-e).toFixed(3);break;case"v":u[1]=+(i[1]-e).toFixed(3);break;case"m":l=i[1];a=i[2];default:for(s=1,p=i.length;s<p;s++)u[s]=+(i[s]-(s%2?o:e)).toFixed(3)}}else for(u=f[r]=[],i[0]=="m"&&(l=i[1]+o,a=i[2]+e),h=0,b=i.length;h<b;h++)f[r][h]=i[h];c=f[r].length;switch(f[r][0]){case"z":o=l;e=a;break;case"h":o+=+f[r][c-1];break;case"v":e+=+f[r][c-1];break;default:o+=+f[r][c-2];e+=+f[r][c-1]}}return f.toString=n._path2string,f},0,ct),vr=n._pathToAbsolute=v(function(t){var i,r,v,b,h,o,y,c,k;if(n.is(t,w)&&n.is(t&&t[0],w)||(t=n.parsePathString(t)),!t||!t.length)return[["M",0,0]];var s=[],f=0,e=0,l=0,a=0,p=0;for(t[0][0]=="M"&&(f=+t[0][1],e=+t[0][2],l=f,a=e,p++,s[0]=["M",f,e]),v=p,b=t.length;v<b;v++){if(s.push(i=[]),r=t[v],r[0]!=fr.call(r[0])){i[0]=fr.call(r[0]);switch(i[0]){case"A":i[1]=r[1];i[2]=r[2];i[3]=r[3];i[4]=r[4];i[5]=r[5];i[6]=+(r[6]+f);i[7]=+(r[7]+e);break;case"V":i[1]=+r[1]+e;break;case"H":i[1]=+r[1]+f;break;case"R":for(h=[f,e][u](r.slice(1)),o=2,y=h.length;o<y;o++)h[o]=+h[o]+f,h[++o]=+h[o]+e;s.pop();s=s[u](ir(h));break;case"M":l=+r[1]+f;a=+r[2]+e;default:for(o=1,y=r.length;o<y;o++)i[o]=+r[o]+(o%2?f:e)}}else if(r[0]=="R")h=[f,e][u](r.slice(1)),s.pop(),s=s[u](ir(h)),i=["R"][u](r.slice(-2));else for(c=0,k=r.length;c<k;c++)i[c]=r[c];switch(i[0]){case"Z":f=l;e=a;break;case"H":f=i[1];break;case"V":e=i[1];break;case"M":l=i[i.length-2];a=i[i.length-1];default:f=i[i.length-2];e=i[i.length-1]}}return s.toString=n._path2string,s},null,ct),gt=function(n,t,i,r){return[n,t,i,r,i,r]},yr=function(n,t,i,r,u,f){var e=1/3,o=2/3;return[e*n+o*i,e*t+o*r,e*u+o*i,e*f+o*r,u,f]},pr=function(n,t,r,f,e,o,s,h,c,l){var at=p*120/180,et=p/180*(+e||0),w=[],nt,ot=v(function(n,t,r){var u=n*i.cos(r)-t*i.sin(r),f=n*i.sin(r)+t*i.cos(r);return{x:u,y:f}}),st,lt,b,gt;if(l)y=l[0],a=l[1],ut=l[2],ft=l[3];else{nt=ot(n,t,-et);n=nt.x;t=nt.y;nt=ot(h,c,-et);h=nt.x;c=nt.y;var oi=i.cos(p/180*e),si=i.sin(p/180*e),d=(n-h)/2,g=(t-c)/2,rt=d*d/(r*r)+g*g/(f*f);rt>1&&(rt=i.sqrt(rt),r=rt*r,f=rt*f);var ht=r*r,ct=f*f,vt=(o==s?-1:1)*i.sqrt(k((ht*ct-ht*g*g-ct*d*d)/(ht*g*g+ct*d*d))),ut=vt*r*g/f+(n+h)/2,ft=vt*-f*d/r+(t+c)/2,y=i.asin(((t-ft)/f).toFixed(9)),a=i.asin(((c-ft)/f).toFixed(9));y=n<ut?p-y:y;a=h<ut?p-a:a;y<0&&(y=p*2+y);a<0&&(a=p*2+a);s&&y>a&&(y=y-p*2);!s&&a>y&&(a=a-p*2)}if(st=a-y,k(st)>at){var ni=a,ti=h,ii=c;a=y+at*(s&&a>y?1:-1);h=ut+r*i.cos(a);c=ft+f*i.sin(a);w=pr(h,c,r,f,e,0,s,ti,ii,[a,ni,ut,ft])}st=a-y;var ri=i.cos(y),ui=i.sin(y),fi=i.cos(a),ei=i.sin(a),yt=i.tan(st/4),pt=4/3*r*yt,wt=4/3*f*yt,bt=[n,t],it=[n+pt*ui,t-wt*ri],kt=[h+pt*ei,c-wt*fi],dt=[h,c];if(it[0]=2*bt[0]-it[0],it[1]=2*bt[1]-it[1],l)return[it,kt,dt][u](w);for(w=[it,kt,dt][u](w).join()[tt](","),lt=[],b=0,gt=w.length;b<gt;b++)lt[b]=b%2?ot(w[b-1],w[b],et).y:ot(w[b],w[b+1],et).x;return lt},ni=function(n,t,i,r,u,f,e,o,s){var h=1-s;return{x:a(h,3)*n+a(h,2)*3*s*i+h*3*s*s*u+a(s,3)*e,y:a(h,3)*t+a(h,2)*3*s*r+h*3*s*s*f+a(s,3)*o}},nf=v(function(n,t,r,u,f,e,o,h){var p=f-2*r+n-(o-2*f+r),c=2*(r-n)-2*(f-r),d=n-r,v=(-c+i.sqrt(c*c-4*p*d))/2/p,y=(-c-i.sqrt(c*c-4*p*d))/2/p,w=[t,h],b=[n,o],a;return k(v)>"1e12"&&(v=.5),k(y)>"1e12"&&(y=.5),v>0&&v<1&&(a=ni(n,t,r,u,f,e,o,h,v),b.push(a.x),w.push(a.y)),y>0&&y<1&&(a=ni(n,t,r,u,f,e,o,h,y),b.push(a.x),w.push(a.y)),p=e-2*u+t-(h-2*e+u),c=2*(u-t)-2*(e-u),d=t-u,v=(-c+i.sqrt(c*c-4*p*d))/2/p,y=(-c-i.sqrt(c*c-4*p*d))/2/p,k(v)>"1e12"&&(v=.5),k(y)>"1e12"&&(y=.5),v>0&&v<1&&(a=ni(n,t,r,u,f,e,o,h,v),b.push(a.x),w.push(a.y)),y>0&&y<1&&(a=ni(n,t,r,u,f,e,o,h,y),b.push(a.x),w.push(a.y)),{min:{x:nt[s](0,b),y:nt[s](0,w)},max:{x:l[s](0,b),y:l[s](0,w)}}}),lt=n._path2curve=v(function(n,t){for(var f=vr(n),i=t&&vr(t),o={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},h={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},w=function(n,t){var i,r;if(!n)return["C",t.x,t.y,t.x,t.y,t.x,t.y];n[0]in{T:1,Q:1}||(t.qx=t.qy=null);switch(n[0]){case"M":t.X=n[1];t.Y=n[2];break;case"A":n=["C"][u](pr[s](0,[t.x,t.y][u](n.slice(1))));break;case"S":i=t.x+(t.x-(t.bx||t.x));r=t.y+(t.y-(t.by||t.y));n=["C",i,r][u](n.slice(1));break;case"T":t.qx=t.x+(t.x-(t.qx||t.x));t.qy=t.y+(t.y-(t.qy||t.y));n=["C"][u](yr(t.x,t.y,t.qx,t.qy,n[1],n[2]));break;case"Q":t.qx=n[1];t.qy=n[2];n=["C"][u](yr(t.x,t.y,n[1],n[2],n[3],n[4]));break;case"L":n=["C"][u](gt(t.x,t.y,n[1],n[2]));break;case"H":n=["C"][u](gt(t.x,t.y,n[1],t.y));break;case"V":n=["C"][u](gt(t.x,t.y,t.x,n[1]));break;case"Z":n=["C"][u](gt(t.x,t.y,t.X,t.Y))}return n},b=function(n,t){if(n[t].length>7){n[t].shift();for(var r=n[t];r.length;)n.splice(t++,0,["C"][u](r.splice(0,6)));n.splice(t,1);v=l(f.length,i&&i.length||0)}},k=function(n,t,r,u,e){n&&t&&n[e][0]=="M"&&t[e][0]!="M"&&(t.splice(e,0,["M",u.x,u.y]),r.bx=0,r.by=0,r.x=n[e][1],r.y=n[e][2],v=l(f.length,i&&i.length||0))},r=0,v=l(f.length,i&&i.length||0);r<v;r++){f[r]=w(f[r],o);b(f,r);i&&(i[r]=w(i[r],h));i&&b(i,r);k(f,i,o,h,r);k(i,f,h,o,r);var c=f[r],a=i&&i[r],y=c.length,p=i&&a.length;o.x=c[y-2];o.y=c[y-1];o.bx=e(c[y-4])||o.x;o.by=e(c[y-3])||o.y;h.bx=i&&(e(a[p-4])||h.x);h.by=i&&(e(a[p-3])||h.y);h.x=i&&a[p-2];h.y=i&&a[p-1]}return i?[f,i]:f},null,ct),af=n._parseDots=v(function(t){for(var r=[],f,h,c,o,u,l,i=0,s=t.length;i<s;i++){if(f={},h=t[i].match(/^([^:]*):?([\d\.]*)/),f.color=n.getRGB(h[1]),f.color.error)return null;f.color=f.color.hex;h[2]&&(f.offset=h[2]+"%");r.push(f)}for(i=1,s=r.length-1;i<s;i++)if(!r[i].offset){for(c=e(r[i-1].offset||0),o=0,u=i+1;u<s;u++)if(r[u].offset){o=r[u].offset;break}for(o||(o=100,u=s),o=e(o),l=(o-c)/(u-i+1);i<u;i++)c+=l,r[i].offset=c+"%"}return r}),ti=n._tear=function(n,t){n==t.top&&(t.top=n.prev);n==t.bottom&&(t.bottom=n.next);n.next&&(n.next.prev=n.prev);n.prev&&(n.prev.next=n.next)},vf=n._tofront=function(n,t){t.top!==n&&(ti(n,t),n.next=null,n.prev=t.top,t.top.next=n,t.top=n)},yf=n._toback=function(n,t){t.bottom!==n&&(ti(n,t),n.next=t.bottom,n.prev=null,t.bottom.prev=n,t.bottom=n)},pf=n._insertafter=function(n,t,i){ti(n,i);t==i.top&&(i.top=n);t.next&&(t.next.prev=n);n.next=t.next;n.prev=t;t.next=n},wf=n._insertbefore=function(n,t,i){ti(n,i);t==i.bottom&&(i.bottom=n);t.prev&&(t.prev.next=n);n.prev=t.prev;t.prev=n;n.next=t},tf=n._extractTransform=function(t,i){var b,tt;if(i==null)return t._.transform;i=y(i).replace(/\.{3}|\u2026/g,t._.transform||g);var a=n.parseTransformString(i),v=0,d=0,nt=0,p=1,w=1,e=t._,u=new rt;if(e.transform=a||[],a)for(b=0,tt=a.length;b<tt;b++){var r=a[b],o=r.length,l=y(r[0]).toLowerCase(),k=r[0]!=l,s=k?u.invert():0,it,ut,h,c,f;l=="t"&&o==3?k?(it=s.x(0,0),ut=s.y(0,0),h=s.x(r[1],r[2]),c=s.y(r[1],r[2]),u.translate(h-it,c-ut)):u.translate(r[1],r[2]):l=="r"?o==2?(f=f||t.getBBox(1),u.rotate(r[1],f.x+f.width/2,f.y+f.height/2),v+=r[1]):o==4&&(k?(h=s.x(r[2],r[3]),c=s.y(r[2],r[3]),u.rotate(r[1],h,c)):u.rotate(r[1],r[2],r[3]),v+=r[1]):l=="s"?o==2||o==3?(f=f||t.getBBox(1),u.scale(r[1],r[o-1],f.x+f.width/2,f.y+f.height/2),p*=r[1],w*=r[o-1]):o==5&&(k?(h=s.x(r[3],r[4]),c=s.y(r[3],r[4]),u.scale(r[1],r[2],h,c)):u.scale(r[1],r[2],r[3],r[4]),p*=r[1],w*=r[2]):l=="m"&&o==7&&u.add(r[1],r[2],r[3],r[4],r[5],r[6]);e.dirtyT=1;t.matrix=u}t.matrix=u;e.sx=p;e.sy=w;e.deg=v;e.dx=d=u.e;e.dy=nt=u.f;p==1&&w==1&&!v&&e.bbox?(e.bbox.x+=+d,e.bbox.y+=+nt):e.dirtyT=1},wr=function(n){var t=n[0];switch(t.toLowerCase()){case"t":return[t,0,0];case"m":return[t,1,0,0,1,0,0];case"r":return n.length==4?[t,0,n[2],n[3]]:[t,0];case"s":return n.length==5?[t,1,1,n[3],n[4]]:n.length==3?[t,1,1]:[t,1]}},rf=n._equaliseTransform=function(t,i){i=y(i).replace(/\.{3}|\u2026/g,t);t=n.parseTransformString(t)||[];i=n.parseTransformString(i)||[];for(var c=l(t.length,i.length),o=[],s=[],u=0,f,h,r,e;u<c;u++){if(r=t[u]||wr(i[u]),e=i[u]||wr(r),r[0]!=e[0]||r[0].toLowerCase()=="r"&&(r[2]!=e[2]||r[3]!=e[3])||r[0].toLowerCase()=="s"&&(r[3]!=e[3]||r[4]!=e[4]))return;for(o[u]=[],s[u]=[],f=0,h=l(r.length,e.length);f<h;f++)f in r&&(o[u][f]=r[f]),f in e&&(s[u][f]=e[f])}return{from:o,to:s}};n._getContainer=function(i,r,u,f){var e;return e=f==null&&!n.is(i,"object")?t.doc.getElementById(i):i,e!=null?e.tagName?r==null?{container:e,width:e.style.pixelWidth||e.offsetWidth,height:e.style.pixelHeight||e.offsetHeight}:{container:e,width:r,height:u}:{container:1,x:i,y:r,width:u,height:f}:void 0};n.pathToRelative=gu;n._engine={};n.path2curve=lt;n.matrix=function(n,t,i,r,u,f){return new rt(n,t,i,r,u,f)},function(t){function u(n){var t=i.sqrt(r(n));n[0]&&(n[0]/=t);n[1]&&(n[1]/=t)}function r(n){return n[0]*n[0]+n[1]*n[1]}t.add=function(n,t,i,r,u,f){var e=[[],[],[]],a=[[this.a,this.c,this.e],[this.b,this.d,this.f],[0,0,1]],l=[[n,i,u],[t,r,f],[0,0,1]],o,s,h,c;for(n&&n instanceof rt&&(l=[[n.a,n.c,n.e],[n.b,n.d,n.f],[0,0,1]]),o=0;o<3;o++)for(s=0;s<3;s++){for(c=0,h=0;h<3;h++)c+=a[o][h]*l[h][s];e[o][s]=c}this.a=e[0][0];this.b=e[1][0];this.c=e[0][1];this.d=e[1][1];this.e=e[0][2];this.f=e[1][2]};t.invert=function(){var n=this,t=n.a*n.d-n.b*n.c;return new rt(n.d/t,-n.b/t,-n.c/t,n.a/t,(n.c*n.f-n.d*n.e)/t,(n.b*n.e-n.a*n.f)/t)};t.clone=function(){return new rt(this.a,this.b,this.c,this.d,this.e,this.f)};t.translate=function(n,t){this.add(1,0,0,1,n,t)};t.scale=function(n,t,i,r){t==null&&(t=n);(i||r)&&this.add(1,0,0,1,i,r);this.add(n,0,0,t,0,0);(i||r)&&this.add(1,0,0,1,-i,-r)};t.rotate=function(t,r,u){t=n.rad(t);r=r||0;u=u||0;var f=+i.cos(t).toFixed(9),e=+i.sin(t).toFixed(9);this.add(f,e,-e,f,r,u);this.add(1,0,0,1,-r,-u)};t.x=function(n,t){return n*this.a+t*this.c+this.e};t.y=function(n,t){return n*this.b+t*this.d+this.f};t.get=function(n){return+this[y.fromCharCode(97+n)].toFixed(4)};t.toString=function(){return n.svg?"matrix("+[this.get(0),this.get(1),this.get(2),this.get(3),this.get(4),this.get(5)].join()+")":[this.get(0),this.get(2),this.get(1),this.get(3),0,0].join()};t.toFilter=function(){return"progid:DXImageTransform.Microsoft.Matrix(M11="+this.get(0)+", M12="+this.get(2)+", M21="+this.get(1)+", M22="+this.get(3)+", Dx="+this.get(4)+", Dy="+this.get(5)+", sizingmethod='auto expand')"};t.offset=function(){return[this.e.toFixed(4),this.f.toFixed(4)]};t.split=function(){var t={},f,e,o;return t.dx=this.e,t.dy=this.f,f=[[this.a,this.c],[this.b,this.d]],t.scalex=i.sqrt(r(f[0])),u(f[0]),t.shear=f[0][0]*f[1][0]+f[0][1]*f[1][1],f[1]=[f[1][0]-f[0][0]*t.shear,f[1][1]-f[0][1]*t.shear],t.scaley=i.sqrt(r(f[1])),u(f[1]),t.shear/=t.scaley,e=-f[0][1],o=f[1][1],o<0?(t.rotate=n.deg(i.acos(o)),e<0&&(t.rotate=360-t.rotate)):t.rotate=n.deg(i.asin(e)),t.isSimple=!+t.shear.toFixed(9)&&(t.scalex.toFixed(9)==t.scaley.toFixed(9)||!t.rotate),t.isSuperSimple=!+t.shear.toFixed(9)&&t.scalex.toFixed(9)==t.scaley.toFixed(9)&&!t.rotate,t.noRotation=!+t.shear.toFixed(9)&&!t.rotate,t};t.toTransformString=function(n){var t=n||this[tt]();return t.isSimple?(t.scalex=+t.scalex.toFixed(4),t.scaley=+t.scaley.toFixed(4),t.rotate=+t.rotate.toFixed(4),(t.dx&&t.dy?"t"+[t.dx,t.dy]:g)+(t.scalex!=1||t.scaley!=1?"s"+[t.scalex,t.scaley,0,0]:g)+(t.rotate?"r"+[t.rotate,0,0]:g)):"m"+[this.get(0),this.get(1),this.get(2),this.get(3),this.get(4),this.get(5)]}}(rt.prototype);at=navigator.userAgent.match(/Version\/(.*?)\s/)||navigator.userAgent.match(/Chrome\/(\d+)/);o.safari=navigator.vendor=="Apple Computer, Inc."&&(at&&at[1]<4||navigator.platform.slice(0,2)=="iP")||navigator.vendor=="Google Inc."&&at&&at[1]<8?function(){var n=this.rect(-99,-99,this.width+99,this.height+99).attr({stroke:"none"});setTimeout(function(){n.remove()})}:yu;var uf=function(){this.returnValue=!1},ff=function(){return this.originalEvent.preventDefault()},ef=function(){this.cancelBubble=!0},of=function(){return this.originalEvent.stopPropagation()},sf=function(){return t.doc.addEventListener?function(n,i,r,u){var f=oi&&si[i]?si[i]:i,e=function(f){var c=t.doc.documentElement.scrollTop||t.doc.body.scrollTop,l=t.doc.documentElement.scrollLeft||t.doc.body.scrollLeft,a=f.clientX+l,v=f.clientY+c,e,o,s;if(oi&&si[h](i))for(e=0,o=f.targetTouches&&f.targetTouches.length;e<o;e++)if(f.targetTouches[e].target==n){s=f;f=f.targetTouches[e];f.originalEvent=s;f.preventDefault=ff;f.stopPropagation=of;break}return r.call(u,f,a,v)};return n.addEventListener(f,e,!1),function(){return n.removeEventListener(f,e,!1),!0}}:t.doc.attachEvent?function(n,i,r,u){var f=function(n){n=n||t.win.event;var i=t.doc.documentElement.scrollTop||t.doc.body.scrollTop,f=t.doc.documentElement.scrollLeft||t.doc.body.scrollLeft,e=n.clientX+f,o=n.clientY+i;return n.preventDefault=n.preventDefault||uf,n.stopPropagation=n.stopPropagation||ef,r.call(u,n,e,o)};return n.attachEvent("on"+i,f),function(){return n.detachEvent("on"+i,f),!0}}:void 0}(),ft=[],yi=function(n){for(var u=n.clientX,f=n.clientY,a=t.doc.documentElement.scrollTop||t.doc.body.scrollTop,v=t.doc.documentElement.scrollLeft||t.doc.body.scrollLeft,i,c=ft.length,o,e;c--;){if(i=ft[c],oi){for(o=n.touches.length;o--;)if(e=n.touches[o],e.identifier==i.el._drag.id){u=e.clientX;f=e.clientY;(n.originalEvent?n.originalEvent:n).preventDefault();break}}else n.preventDefault();var r=i.el.node,s,l=r.nextSibling,h=r.parentNode,y=r.style.display;t.win.opera&&h.removeChild(r);r.style.display="none";s=i.el.paper.getElementByPoint(u,f);r.style.display=y;t.win.opera&&(l?h.insertBefore(r,l):h.appendChild(r));s&&eve("drag.over."+i.el.id,i.el,s);u+=v;f+=a;eve("drag.move."+i.el.id,i.move_scope||i.el,u-i.el._drag.x,f-i.el._drag.y,u,f,n)}},pi=function(t){n.unmousemove(yi).unmouseup(pi);for(var r=ft.length,i;r--;)i=ft[r],i.el._drag={},eve("drag.end."+i.el.id,i.end_scope||i.start_scope||i.move_scope||i.el,t);ft=[]},r=n.el={};for(wi=ur.length;wi--;)(function(i){n[i]=r[i]=function(r,u){return n.is(r,"function")&&(this.events=this.events||[],this.events.push({name:i,f:r,unbind:sf(this.shape||this.node||t.doc,i,r,u||this)})),this};n["un"+i]=r["un"+i]=function(n){for(var t=this.events,r=t.length;r--;)if(t[r].name==i&&t[r].f==n)return t[r].unbind(),t.splice(r,1),!t.length&&delete this.events,this;return this}})(ur[wi]);r.data=function(t,i){var u=ht[this.id]=ht[this.id]||{},r;if(arguments.length==1){if(n.is(t,"object")){for(r in t)t[h](r)&&this.data(r,t[r]);return this}return eve("data.get."+this.id,this,u[t],t),u[t]}return u[t]=i,eve("data.set."+this.id,this,i,t),this};r.removeData=function(n){return n==null?ht[this.id]={}:ht[this.id]&&delete ht[this.id][n],this};r.hover=function(n,t,i,r){return this.mouseover(n,i).mouseout(t,r||i)};r.unhover=function(n,t){return this.unmouseover(n).unmouseout(t)};et=[];r.drag=function(i,r,u,f,e,o){function s(s){(s.originalEvent||s).preventDefault();var h=t.doc.documentElement.scrollTop||t.doc.body.scrollTop,c=t.doc.documentElement.scrollLeft||t.doc.body.scrollLeft;this._drag.x=s.clientX+c;this._drag.y=s.clientY+h;this._drag.id=s.identifier;!ft.length&&n.mousemove(yi).mouseup(pi);ft.push({el:this,move_scope:f,start_scope:e,end_scope:o});r&&eve.on("drag.start."+this.id,r);i&&eve.on("drag.move."+this.id,i);u&&eve.on("drag.end."+this.id,u);eve("drag.start."+this.id,e||f||this,s.clientX+c,s.clientY+h,s)}return this._drag={},et.push({el:this,start:s}),this.mousedown(s),this};r.onDragOver=function(n){n?eve.on("drag.over."+this.id,n):eve.unbind("drag.over."+this.id)};r.undrag=function(){for(var t=et.length;t--;)et[t].el==this&&(this.unmousedown(et[t].start),et.splice(t,1),eve.unbind("drag.*."+this.id));et.length||n.unmousemove(yi).unmouseup(pi)};o.circle=function(t,i,r){var u=n._engine.circle(this,t||0,i||0,r||0);return this.__set__&&this.__set__.push(u),u};o.rect=function(t,i,r,u,f){var e=n._engine.rect(this,t||0,i||0,r||0,u||0,f||0);return this.__set__&&this.__set__.push(e),e};o.ellipse=function(t,i,r,u){var f=n._engine.ellipse(this,t||0,i||0,r||0,u||0);return this.__set__&&this.__set__.push(f),f};o.path=function(t){!t||n.is(t,wt)||n.is(t[0],w)||(t+=g);var i=n._engine.path(n.format[s](n,arguments),this);return this.__set__&&this.__set__.push(i),i};o.image=function(t,i,r,u,f){var e=n._engine.image(this,t||"about:blank",i||0,r||0,u||0,f||0);return this.__set__&&this.__set__.push(e),e};o.text=function(t,i,r){var u=n._engine.text(this,t||0,i||0,y(r));return this.__set__&&this.__set__.push(u),u};o.set=function(t){n.is(t,"array")||(t=Array.prototype.splice.call(arguments,0,arguments.length));var i=new ot(t);return this.__set__&&this.__set__.push(i),i};o.setStart=function(n){this.__set__=n||this.set()};o.setFinish=function(){var n=this.__set__;return delete this.__set__,n};o.setSize=function(t,i){return n._engine.setSize.call(this,t,i)};o.setViewBox=function(t,i,r,u,f){return n._engine.setViewBox.call(this,t,i,r,u,f)};o.top=o.bottom=null;o.raphael=n;br=function(n){var u=n.getBoundingClientRect(),f=n.ownerDocument,i=f.body,r=f.documentElement,e=r.clientTop||i.clientTop||0,o=r.clientLeft||i.clientLeft||0,s=u.top+(t.win.pageYOffset||r.scrollTop||i.scrollTop)-e,h=u.left+(t.win.pageXOffset||r.scrollLeft||i.scrollLeft)-o;return{y:s,x:h}};o.getElementByPoint=function(n,i){var o=this,f=o.canvas,r=t.doc.elementFromPoint(n,i),s,u,e;if(t.win.opera&&r.tagName=="svg"&&(s=br(f),u=f.createSVGRect(),u.x=n-s.x,u.y=i-s.y,u.width=u.height=1,e=f.getIntersectionList(u,null),e.length&&(r=e[e.length-1])),!r)return null;while(r.parentNode&&r!=f.parentNode&&!r.raphael)r=r.parentNode;return r==o.canvas.parentNode&&(r=f),r=r&&r.raphael?o.getById(r.raphaelid):null,r};o.getById=function(n){for(var t=this.bottom;t;){if(t.id==n)return t;t=t.next}return null};o.forEach=function(n,t){for(var i=this.bottom;i;){if(n.call(t,i)===!1)return this;i=i.next}return this};r.getBBox=function(n){if(this.removed)return{};var t=this._;return n?((t.dirty||!t.bboxwt)&&(this.realPath=vi[this.type](this),t.bboxwt=ar(this.realPath),t.bboxwt.toString=tr,t.dirty=0),t.bboxwt):((t.dirty||t.dirtyT||!t.bbox)&&((t.dirty||!this.realPath)&&(t.bboxwt=0,this.realPath=vi[this.type](this)),t.bbox=ar(sr(this.realPath,this.matrix)),t.bbox.toString=tr,t.dirty=t.dirtyT=0),t.bbox)};r.clone=function(){if(this.removed)return null;var n=this.paper[this.type]().attr(this.attr());return this.__set__&&this.__set__.push(n),n};r.glow=function(n){var r;if(this.type=="text")return null;n=n||{};var t={width:(n.width||10)+(+this.attr("stroke-width")||1),fill:n.fill||!1,opacity:n.opacity||.5,offsetx:n.offsetx||0,offsety:n.offsety||0,color:n.color||"#000"},u=t.width/2,f=this.paper,e=f.set(),i=this.realPath||vi[this.type](this);for(i=this.matrix?sr(i,this.matrix):i,r=1;r<u+1;r++)e.push(f.path(i).attr({stroke:t.color,fill:t.fill?t.color:"none","stroke-linejoin":"round","stroke-linecap":"round","stroke-width":+(t.width/u*r).toFixed(3),opacity:+(t.opacity/u).toFixed(3)}));return e.insertBefore(this).translate(t.offsetx,t.offsety)};var bi={},ii=function(t,i,r,u,f,e,o,s,h){var p=0,v=100,w=[t,i,r,u,f,e,o,s].join(),c=bi[w],b,y,k,l;for(c||(bi[w]=c={data:[]}),c.timer&&clearTimeout(c.timer),c.timer=setTimeout(function(){delete bi[w]},2e3),h==null||c.precision||(k=ii(t,i,r,u,f,e,o,s),c.precision=~~k*10,c.data=[]),v=c.precision||v,l=0;l<v+1;l++){if(c.data[l*v]?y=c.data[l*v]:(y=n.findDotsAtSegment(t,i,r,u,f,e,o,s,l/v),c.data[l*v]=y),l&&(p+=a(a(b.x-y.x,2)+a(b.y-y.y,2),.5)),h!=null&&p>=h)return y;b=y}if(h==null)return p},ki=function(t,i){return function(r,u,f){var y,p;r=lt(r);var s,h,e,a,c="",v={},o,l=0;for(y=0,p=r.length;y<p;y++){if(e=r[y],e[0]=="M")s=+e[1],h=+e[2];else{if(a=ii(s,h,e[1],e[2],e[3],e[4],e[5],e[6]),l+a>u){if(i&&!v.start){if(o=ii(s,h,e[1],e[2],e[3],e[4],e[5],e[6],u-l),c+=["C"+o.start.x,o.start.y,o.m.x,o.m.y,o.x,o.y],f)return c;v.start=c;c=["M"+o.x,o.y+"C"+o.n.x,o.n.y,o.end.x,o.end.y,e[5],e[6]].join();l+=a;s=+e[5];h=+e[6];continue}if(!t&&!i)return o=ii(s,h,e[1],e[2],e[3],e[4],e[5],e[6],u-l),{x:o.x,y:o.y,alpha:o.alpha}}l+=a;s=+e[5];h=+e[6]}c+=e.shift()+e}return v.end=c,o=t?l:i?v:n.findDotsAtSegment(s,h,e[0],e[1],e[2],e[3],e[4],e[5],1),o.alpha&&(o={x:o.x,y:o.y,alpha:o.alpha}),o}},kr=ki(1),dr=ki(),di=ki(0,1);n.getTotalLength=kr;n.getPointAtLength=dr;n.getSubpath=function(n,t,i){if(this.getTotalLength(n)-i<1e-6)return di(n,t).end;var r=di(n,i,1);return t?di(r,t).end:r};r.getTotalLength=function(){if(this.type=="path")return this.node.getTotalLength?this.node.getTotalLength():kr(this.attrs.path)};r.getPointAtLength=function(n){if(this.type=="path")return dr(this.attrs.path,n)};r.getSubpath=function(t,i){if(this.type=="path")return n.getSubpath(this.attrs.path,t,i)};d=n.easing_formulas={linear:function(n){return n},"<":function(n){return a(n,1.7)},">":function(n){return a(n,.48)},"<>":function(n){var r=.48-n/1.04,u=i.sqrt(.1734+r*r),f=u-r,o=a(k(f),1/3)*(f<0?-1:1),e=-u-r,s=a(k(e),1/3)*(e<0?-1:1),t=o+s+.5;return(1-t)*3*t*t+t*t*t},backIn:function(n){var t=1.70158;return n*n*((t+1)*n-t)},backOut:function(n){n=n-1;var t=1.70158;return n*n*((t+1)*n+t)+1},elastic:function(n){return n==!!n?n:a(2,-10*n)*i.sin((n-.075)*2*p/.3)+1},bounce:function(n){var r=7.5625,t=2.75,i;return n<1/t?i=r*n*n:n<2/t?(n-=1.5/t,i=r*n*n+.75):n<2.5/t?(n-=2.25/t,i=r*n*n+.9375):(n-=2.625/t,i=r*n*n+.984375),i}};d.easeIn=d["ease-in"]=d["<"];d.easeOut=d["ease-out"]=d[">"];d.easeInOut=d["ease-in-out"]=d["<>"];d["back-in"]=d.backIn;d["back-out"]=d.backOut;var f=[],gr=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n){setTimeout(n,16)},gi=function(){for(var ut=+new Date,w=0,t,v,i,r,d,l,g,p,rt;w<f.length;w++)if(t=f[w],!t.el.removed&&!t.paused){var b=ut-t.start,s=t.ms,ft=t.easing,o=t.from,a=t.diff,nt=t.to,et=t.t,y=t.el,tt={},e,it={},k;if(t.initstatus?(b=(t.initstatus*t.anim.top-t.prev)/(t.percent-t.prev)*s,t.status=t.initstatus,delete t.initstatus,t.stop&&f.splice(w--,1)):t.status=(t.prev+(t.percent-t.prev)*(b/s))/t.anim.top,!(b<0))if(b<s){v=ft(b/s);for(i in o)if(o[h](i)){switch(ci[i]){case c:e=+o[i]+v*s*a[i];break;case"colour":e="rgb("+[nr(hi(o[i].r+v*s*a[i].r)),nr(hi(o[i].g+v*s*a[i].g)),nr(hi(o[i].b+v*s*a[i].b))].join(",")+")";break;case"path":for(e=[],r=0,d=o[i].length;r<d;r++){for(e[r]=[o[i][r][0]],l=1,g=o[i][r].length;l<g;l++)e[r][l]=+o[i][r][l]+v*s*a[i][r][l];e[r]=e[r].join(st)}e=e.join(st);break;case"transform":if(a[i].real)for(e=[],r=0,d=o[i].length;r<d;r++)for(e[r]=[o[i][r][0]],l=1,g=o[i][r].length;l<g;l++)e[r][l]=o[i][r][l]+v*s*a[i][r][l];else p=function(n){return+o[i][n]+v*s*a[i][n]},e=[["m",p(0),p(1),p(2),p(3),p(4),p(5)]];break;case"csv":if(i=="clip-rect")for(e=[],r=4;r--;)e[r]=+o[i][r]+v*s*a[i][r];break;default:for(rt=[][u](o[i]),e=[],r=y.paper.customAttributes[i].length;r--;)e[r]=+rt[r]+v*s*a[i][r]}tt[i]=e}y.attr(tt),function(n,t,i){setTimeout(function(){eve("anim.frame."+n,t,i)})}(y.id,y,t.anim)}else{if(function(t,i,r){setTimeout(function(){eve("anim.frame."+i.id,i,r);eve("anim.finish."+i.id,i,r);n.is(t,"function")&&t.call(i)})}(t.callback,y,t.anim),y.attr(nt),f.splice(w--,1),t.repeat>1&&!t.next){for(k in nt)nt[h](k)&&(it[k]=t.totalOrigin[k]);t.el.attr(it);vt(t.anim,t.el,t.anim.percents[0],null,t.totalOrigin,t.repeat-1)}t.next&&!t.stop&&vt(t.anim,t.el,t.next,null,t.totalOrigin,t.repeat)}}n.svg&&y&&y.paper&&y.paper.safari();f.length&&gr(gi)},nr=function(n){return n>255?255:n<0?0:n};r.animateWith=function(t,i,r,u,f,e){var o=r?n.animation(r,u,f,e):i,s=t.status(i);return this.animate(o).status(o,s*i.ms/o.ms)};r.onAnimation=function(n){return n?eve.on("anim.frame."+this.id,n):eve.unbind("anim.frame."+this.id),this};it.prototype.delay=function(n){var t=new it(this.anim,this.ms);return t.times=this.times,t.del=+n||0,t};it.prototype.repeat=function(n){var t=new it(this.anim,this.ms);return t.del=this.del,t.times=i.floor(l(n,0))||1,t};n.animation=function(t,i,r,u){if(t instanceof it)return t;(n.is(r,"function")||!r)&&(u=u||r||null,r=null);t=Object(t);i=+i||0;var o={},s,f;for(f in t)t[h](f)&&e(f)!=f&&e(f)+"%"!=f&&(s=!0,o[f]=t[f]);return s?(r&&(o.easing=r),u&&(o.callback=u),new it({100:o},i)):new it(t,i)};r.animate=function(t,i,r,u){var f=this,e;return f.removed?(u&&u.call(f),f):(e=t instanceof it?t:n.animation(t,i,r,u),vt(e,f,e.percents[0],null,f.attr()),f)};r.setTime=function(n,t){return n&&t!=null&&this.status(n,nt(t,n.ms)/n.ms),this};r.status=function(n,t){var u=[],r=0,e,i;if(t!=null)return vt(n,this,-1,nt(t,1)),this;for(e=f.length;r<e;r++)if(i=f[r],i.el.id==this.id&&(!n||i.anim==n)){if(n)return i.status;u.push({anim:i.anim,status:i.status})}return n?0:u};r.pause=function(n){for(var t=0;t<f.length;t++)f[t].el.id!=this.id||n&&f[t].anim!=n||eve("anim.pause."+this.id,this,f[t].anim)===!1||(f[t].paused=!0);return this};r.resume=function(n){for(var i,t=0;t<f.length;t++)f[t].el.id!=this.id||n&&f[t].anim!=n||(i=f[t],eve("anim.resume."+this.id,this,i.anim)!==!1&&(delete i.paused,this.status(i.anim,i.status)));return this};r.stop=function(n){for(var t=0;t<f.length;t++)f[t].el.id!=this.id||n&&f[t].anim!=n||eve("anim.stop."+this.id,this,f[t].anim)===!1||f.splice(t--,1);return this};r.toString=function(){return"Raphaël’s object"};ot=function(n){if(this.items=[],this.length=0,this.type="set",n)for(var t=0,i=n.length;t<i;t++)n[t]&&(n[t].constructor==r.constructor||n[t].constructor==ot)&&(this[this.items.length]=this.items[this.items.length]=n[t],this.length++)};b=ot.prototype;b.push=function(){for(var n,i,t=0,u=arguments.length;t<u;t++)n=arguments[t],n&&(n.constructor==r.constructor||n.constructor==ot)&&(i=this.items.length,this[i]=this.items[i]=n,this.length++);return this};b.pop=function(){return this.length&&delete this[this.length--],this.items.pop()};b.forEach=function(n,t){for(var i=0,r=this.items.length;i<r;i++)if(n.call(t,this.items[i],i)===!1)return this;return this};for(ri in r)r[h](ri)&&(b[ri]=function(n){return function(){var t=arguments;return this.forEach(function(i){i[n][s](i,t)})}}(ri));b.attr=function(t,i){var r,f,u,e;if(t&&n.is(t,w)&&n.is(t[0],"object"))for(r=0,f=t.length;r<f;r++)this.items[r].attr(t[r]);else for(u=0,e=this.items.length;u<e;u++)this.items[u].attr(t,i);return this};b.clear=function(){while(this.length)this.pop()};b.splice=function(n,t){var r;n=n<0?l(this.length+n,0):n;t=l(0,nt(this.length-n,t));for(var u=[],e=[],f=[],i=2;i<arguments.length;i++)f.push(arguments[i]);for(i=0;i<t;i++)e.push(this[n+i]);for(;i<this.length-n;i++)u.push(this[n+i]);for(r=f.length,i=0;i<r+u.length;i++)this.items[n+i]=this[n+i]=i<r?f[i]:u[i-r];for(i=this.items.length=this.length-=t-r;this[i];)delete this[i++];return new ot(e)};b.exclude=function(n){for(var t=0,i=this.length;t<i;t++)if(this[t]==n)return this.splice(t,1),!0};b.animate=function(t,i,r,u){var s;(n.is(r,"function")||!r)&&(u=r||null);var e=this.items.length,f=e,h,c=this,o;if(!e)return this;for(u&&(o=function(){--e||u.call(c)}),r=n.is(r,wt)?r:o,s=n.animation(t,i,r,o),h=this.items[--f].animate(s);f--;)this.items[f]&&!this.items[f].removed&&this.items[f].animateWith(h,s);return this};b.insertAfter=function(n){for(var t=this.items.length;t--;)this.items[t].insertAfter(n);return this};b.getBBox=function(){for(var t=[],i=[],u=[],f=[],n,r=this.items.length;r--;)this.items[r].removed||(n=this.items[r].getBBox(),t.push(n.x),i.push(n.y),u.push(n.x+n.width),f.push(n.y+n.height));return t=nt[s](0,t),i=nt[s](0,i),{x:t,y:i,width:l[s](0,u)-t,height:l[s](0,f)-i}};b.clone=function(n){n=new ot;for(var t=0,i=this.items.length;t<i;t++)n.push(this.items[t].clone());return n};b.toString=function(){return"Raphaël‘s set"};n.registerFont=function(n){var i,u,f,r,t,e;if(!n.face)return n;this.fonts=this.fonts||{};i={w:n.w,face:{},glyphs:{}};u=n.face["font-family"];for(f in n.face)n.face[h](f)&&(i.face[f]=n.face[f]);if(this.fonts[u]?this.fonts[u].push(i):this.fonts[u]=[i],!n.svg){i.face["units-per-em"]=ut(n.face["units-per-em"],10);for(r in n.glyphs)if(n.glyphs[h](r)&&(t=n.glyphs[r],i.glyphs[r]={w:t.w,k:{},d:t.d&&"M"+t.d.replace(/[mlcxtrv]/g,function(n){return{l:"L",c:"C",x:"z",t:"m",r:"l",v:"c"}[n]||"M"})+"z"},t.k))for(e in t.k)t[h](e)&&(i.glyphs[r].k[e]=t.k[e])}return n};o.getFont=function(t,i,r,u){var f,c,o,e,s,l;if(u=u||"normal",r=r||"normal",i=+i||{normal:400,bold:700,lighter:300,bolder:800}[i]||400,!!n.fonts){if(f=n.fonts[t],!f){c=new RegExp("(^|\\s)"+t.replace(/[^\w\d\s+!~.:_-]/g,g)+"(\\s|$)","i");for(o in n.fonts)if(n.fonts[h](o)&&c.test(o)){f=n.fonts[o];break}}if(f)for(s=0,l=f.length;s<l;s++)if(e=f[s],e.face["font-weight"]==i&&(e.face["font-style"]==r||!e.face["font-style"])&&e.face["font-stretch"]==u)break;return e}};o.print=function(t,i,r,u,f,e,o){var s,it,v,p;e=e||"middle";o=l(nt(o||0,1),-1);var w=this.set(),a=y(r)[tt](g),b=0,rt=g,h;if(n.is(u,r)&&(u=this.getFont(u)),u){h=(f||16)/u.face["units-per-em"];var c=u.face.bbox[tt](fi),k=+c[0],d=+c[1]+(e=="baseline"?c[3]-c[1]+ +u.face.descent:(c[3]-c[1])/2);for(s=0,it=a.length;s<it;s++)v=s&&u.glyphs[a[s-1]]||{},p=u.glyphs[a[s]],b+=s?(v.w||u.w)+(v.k&&v.k[a[s]]||0)+u.w*o:0,p&&p.d&&w.push(this.path(p.d).attr({fill:"#000",stroke:"none",transform:[["t",b*h,0]]}));w.transform(["...s",h,h,k,d,"t",(t-k)/h,(i-d)/h])}return w};o.add=function(t){if(n.is(t,"array"))for(var u=this.set(),r=0,f=t.length,i;r<f;r++)i=t[r]||{},iu[h](i.type)&&u.push(this[i.type]().attr(i));return u};n.format=function(t,i){var r=n.is(i,w)?[0][u](i):arguments;return t&&n.is(t,wt)&&r.length-1&&(t=t.replace(ru,function(n,t){return r[++t]==null?g:r[t]})),t||g};n.fullfill=function(){var n=/\{([^\}]+)\}/g,t=/(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g,i=function(n,i,r){var u=r;return i.replace(t,function(n,t,i,r,f){t=t||r;u&&(t in u&&(u=u[t]),typeof u=="function"&&f&&(u=u()))}),u=(u==null||u==r?n:u)+"",u};return function(t,r){return String(t).replace(n,function(n,t){return i(n,t,r)})}}();n.ninja=function(){return ei.was?t.win.Raphael=ei.is:delete Raphael,n};n.st=b,function(t,i,r){function u(){/in/.test(t.readyState)?setTimeout(u,9):n.eve("DOMload")}t.readyState==null&&t.addEventListener&&(t.addEventListener(i,r=function(){t.removeEventListener(i,r,!1);t.readyState="complete"},!1),t.readyState="loading");u()}(document,"DOMContentLoaded");ei.was?t.win.Raphael=n:Raphael=n;eve.on("DOMload",function(){ui=!0})}();window.Raphael.svg&&function(n){var i="hasOwnProperty",u=String,f=parseFloat,tt=parseInt,c=Math,k=c.max,p=c.abs,d=c.pow,l=/[, ]+/,w=n.eve,h="",a=" ",v="http://www.w3.org/1999/xlink",ft={block:"M5,0 0,2.5 5,5z",classic:"M5,0 0,2.5 5,5 3.5,3 3.5,2z",diamond:"M2.5,0 5,2.5 2.5,5 0,2.5z",open:"M6,1 1,3.5 6,6",oval:"M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"},e={},nt,y;n.toString=function(){return"Your browser supports SVG.\nYou are running Raphaël "+this.version};var t=function(r,f){if(f){typeof r=="string"&&(r=t(r));for(var e in f)f[i](e)&&(e.substring(0,6)=="xlink:"?r.setAttributeNS(v,e.substring(6),u(f[e])):r.setAttribute(e,u(f[e])))}else r=n._g.doc.createElementNS("http://www.w3.org/2000/svg",r),r.style&&(r.style.webkitTapHighlightColor="rgba(0,0,0,0)");return r},it=function(i,r){var w="linear",l=i.id+r,b=.5,o=.5,tt=i.node,it=i.paper,g=tt.style,a=n._g.doc.getElementById(l),v,e,nt,y,s,rt;if(!a){if(r=u(r).replace(n._radial_gradient,function(n,t,i){if(w="radial",t&&i){b=f(t);o=f(i);var r=(o>.5)*2-1;d(b-.5,2)+d(o-.5,2)>.25&&(o=c.sqrt(.25-d(b-.5,2))*r+.5)&&o!=.5&&(o=o.toFixed(5)-1e-5*r)}return h}),r=r.split(/\s*\-\s*/),w=="linear"){if(v=r.shift(),v=-f(v),isNaN(v))return null;e=[0,0,c.cos(n.rad(v)),c.sin(n.rad(v))];nt=1/(k(p(e[2]),p(e[3]))||1);e[2]*=nt;e[3]*=nt;e[2]<0&&(e[0]=-e[2],e[2]=0);e[3]<0&&(e[1]=-e[3],e[3]=0)}if(y=n._parseDots(r),!y)return null;if(l=l.replace(/[\(\)\s,\xb0#]/g,"_"),i.gradient&&l!=i.gradient.id&&(it.defs.removeChild(i.gradient),delete i.gradient),!i.gradient)for(a=t(w+"Gradient",{id:l}),i.gradient=a,t(a,w=="radial"?{fx:b,fy:o}:{x1:e[0],y1:e[1],x2:e[2],y2:e[3],gradientTransform:i.matrix.invert()}),it.defs.appendChild(a),s=0,rt=y.length;s<rt;s++)a.appendChild(t("stop",{offset:y[s].offset?y[s].offset:s?"100%":"0%","stop-color":y[s].color||"#fff"}))}return t(tt,{fill:"url(#"+l+")",opacity:1,"fill-opacity":1}),g.fill=h,g.opacity=1,g.fillOpacity=1,1},b=function(n){var i=n.getBBox(1);t(n.pattern,{patternTransform:n.matrix.invert()+" translate("+i.x+","+i.y+")"})},o=function(r,f,o){var b,k,g,tt,it,rt;if(r.type=="path"){for(var ut=u(f).toLowerCase().split("-"),ht=r.paper,s=o?"end":"start",ct=r.node,c=r.attrs,d=c["stroke-width"],et=ut.length,l="classic",p,w,ot,st,h,v=3,y=3,nt=5;et--;)switch(ut[et]){case"block":case"classic":case"oval":case"diamond":case"open":case"none":l=ut[et];break;case"wide":y=5;break;case"narrow":y=2;break;case"long":v=5;break;case"short":v=2}l=="open"?(v+=2,y+=2,nt+=2,ot=1,st=o?4:1,h={fill:"none",stroke:c.stroke}):(st=ot=v/2,h={fill:c.stroke,stroke:"none"});r._.arrows?o?(r._.arrows.endPath&&e[r._.arrows.endPath]--,r._.arrows.endMarker&&e[r._.arrows.endMarker]--):(r._.arrows.startPath&&e[r._.arrows.startPath]--,r._.arrows.startMarker&&e[r._.arrows.startMarker]--):r._.arrows={};l!="none"?(b="raphael-marker-"+l,k="raphael-marker-"+s+l+v+y,n._g.doc.getElementById(b)?e[b]++:(ht.defs.appendChild(t(t("path"),{"stroke-linecap":"round",d:ft[l],id:b})),e[b]=1),g=n._g.doc.getElementById(k),g?(e[k]++,tt=g.getElementsByTagName("use")[0]):(g=t(t("marker"),{id:k,markerHeight:y,markerWidth:v,orient:"auto",refX:st,refY:y/2}),tt=t(t("use"),{"xlink:href":"#"+b,transform:(o?" rotate(180 "+v/2+" "+y/2+") ":a)+"scale("+v/nt+","+y/nt+")","stroke-width":2/(v/nt+y/nt)}),g.appendChild(tt),ht.defs.appendChild(g),e[k]=1),t(tt,h),it=ot*(l!="diamond"&&l!="oval"),o?(p=r._.arrows.startdx*d||0,w=n.getTotalLength(c.path)-it*d):(p=it*d,w=n.getTotalLength(c.path)-(r._.arrows.enddx*d||0)),h={},h["marker-"+s]="url(#"+k+")",(w||p)&&(h.d=Raphael.getSubpath(c.path,p,w)),t(ct,h),r._.arrows[s+"Path"]=b,r._.arrows[s+"Marker"]=k,r._.arrows[s+"dx"]=it,r._.arrows[s+"Type"]=l,r._.arrows[s+"String"]=f):(o?(p=r._.arrows.startdx*d||0,w=n.getTotalLength(c.path)-p):(p=0,w=n.getTotalLength(c.path)-(r._.arrows.enddx*d||0)),r._.arrows[s+"Path"]&&t(ct,{d:Raphael.getSubpath(c.path,p,w)}),delete r._.arrows[s+"Path"],delete r._.arrows[s+"Marker"],delete r._.arrows[s+"dx"],delete r._.arrows[s+"Type"],delete r._.arrows[s+"String"]);for(h in e)e[i](h)&&!e[h]&&(rt=n._g.doc.getElementById(h),rt&&rt.parentNode.removeChild(rt))}},et={"":[0],none:[0],"-":[3,1],".":[1,1],"-.":[3,1,1,1],"-..":[3,1,1,1,1,1],". ":[1,3],"- ":[4,3],"--":[8,3],"- .":[4,3,1,3],"--.":[8,3,1,3],"--..":[8,3,1,3,1,3]},rt=function(n,i,r){if(i=et[u(i).toLowerCase()],i){for(var e=n.attrs["stroke-width"]||"1",s={round:e,square:e,butt:0}[n.attrs["stroke-linecap"]||r["stroke-linecap"]]||0,o=[],f=i.length;f--;)o[f]=i[f]*e+(f%2?1:-1)*s;t(n.node,{"stroke-dasharray":o.join(",")})}},g=function(r,f){var s=r.node,c=r.attrs,vt=s.style.visibility,a,e,d,ft,g,y,et,lt,st,ht,ct,w,nt,ut,at;s.style.visibility="hidden";for(a in f)if(f[i](a)){if(!n._availableAttrs[i](a))continue;e=f[a];c[a]=e;switch(a){case"blur":r.blur(e);break;case"href":case"title":case"target":d=s.parentNode;d.tagName.toLowerCase()!="a"&&(ft=t("a"),d.insertBefore(ft,s),ft.appendChild(s),d=ft);a=="target"&&e=="blank"?d.setAttributeNS(v,"show","new"):d.setAttributeNS(v,a,e);break;case"cursor":s.style.cursor=e;break;case"transform":r.transform(e);break;case"arrow-start":o(r,e);break;case"arrow-end":o(r,e,1);break;case"clip-rect":g=u(e).split(l);g.length==4&&(r.clip&&r.clip.parentNode.parentNode.removeChild(r.clip.parentNode),y=t("clipPath"),et=t("rect"),y.id=n.createUUID(),t(et,{x:g[0],y:g[1],width:g[2],height:g[3]}),y.appendChild(et),r.paper.defs.appendChild(y),t(s,{"clip-path":"url(#"+y.id+")"}),r.clip=et);e||(lt=s.getAttribute("clip-path"),lt&&(st=n._g.doc.getElementById(lt.replace(/(^url\(#|\)$)/g,h)),st&&st.parentNode.removeChild(st),t(s,{"clip-path":h}),delete r.clip));break;case"path":r.type=="path"&&(t(s,{d:e?c.path=n._pathToAbsolute(e):"M0,0"}),r._.dirty=1,r._.arrows&&("startString"in r._.arrows&&o(r,r._.arrows.startString),"endString"in r._.arrows&&o(r,r._.arrows.endString,1)));break;case"width":if(s.setAttribute(a,e),r._.dirty=1,c.fx)a="x",e=c.x;else break;case"x":c.fx&&(e=-c.x-(c.width||0));case"rx":if(a=="rx"&&r.type=="rect")break;case"cx":s.setAttribute(a,e);r.pattern&&b(r);r._.dirty=1;break;case"height":if(s.setAttribute(a,e),r._.dirty=1,c.fy)a="y",e=c.y;else break;case"y":c.fy&&(e=-c.y-(c.height||0));case"ry":if(a=="ry"&&r.type=="rect")break;case"cy":s.setAttribute(a,e);r.pattern&&b(r);r._.dirty=1;break;case"r":r.type=="rect"?t(s,{rx:e,ry:e}):s.setAttribute(a,e);r._.dirty=1;break;case"src":r.type=="image"&&s.setAttributeNS(v,"href",e);break;case"stroke-width":(r._.sx!=1||r._.sy!=1)&&(e/=k(p(r._.sx),p(r._.sy))||1);r.paper._vbSize&&(e*=r.paper._vbSize);s.setAttribute(a,e);c["stroke-dasharray"]&&rt(r,c["stroke-dasharray"],f);r._.arrows&&("startString"in r._.arrows&&o(r,r._.arrows.startString),"endString"in r._.arrows&&o(r,r._.arrows.endString,1));break;case"stroke-dasharray":rt(r,e,f);break;case"fill":if(ht=u(e).match(n._ISURL),ht){y=t("pattern");ct=t("image");y.id=n.createUUID();t(y,{x:0,y:0,patternUnits:"userSpaceOnUse",height:1,width:1});t(ct,{x:0,y:0,"xlink:href":ht[1]});y.appendChild(ct),function(i){n._preload(ht[1],function(){var n=this.offsetWidth,u=this.offsetHeight;t(i,{width:n,height:u});t(ct,{width:n,height:u});r.paper.safari()})}(y);r.paper.defs.appendChild(y);s.style.fill="url(#"+y.id+")";t(s,{fill:"url(#"+y.id+")"});r.pattern=y;r.pattern&&b(r);break}if(w=n.getRGB(e),w.error){if((r.type=="circle"||r.type=="ellipse"||u(e).charAt()!="r")&&it(r,e)){("opacity"in c||"fill-opacity"in c)&&(nt=n._g.doc.getElementById(s.getAttribute("fill").replace(/^url\(#|\)$/g,h)),nt&&(ut=nt.getElementsByTagName("stop"),t(ut[ut.length-1],{"stop-opacity":("opacity"in c?c.opacity:1)*("fill-opacity"in c?c["fill-opacity"]:1)})));c.gradient=e;c.fill="none";break}}else delete f.gradient,delete c.gradient,!n.is(c.opacity,"undefined")&&n.is(f.opacity,"undefined")&&t(s,{opacity:c.opacity}),!n.is(c["fill-opacity"],"undefined")&&n.is(f["fill-opacity"],"undefined")&&t(s,{"fill-opacity":c["fill-opacity"]});w[i]("opacity")&&t(s,{"fill-opacity":w.opacity>1?w.opacity/100:w.opacity});case"stroke":w=n.getRGB(e);s.setAttribute(a,w.hex);a=="stroke"&&w[i]("opacity")&&t(s,{"stroke-opacity":w.opacity>1?w.opacity/100:w.opacity});a=="stroke"&&r._.arrows&&("startString"in r._.arrows&&o(r,r._.arrows.startString),"endString"in r._.arrows&&o(r,r._.arrows.endString,1));break;case"gradient":(r.type=="circle"||r.type=="ellipse"||u(e).charAt()!="r")&&it(r,e);break;case"opacity":c.gradient&&!c[i]("stroke-opacity")&&t(s,{"stroke-opacity":e>1?e/100:e});case"fill-opacity":if(c.gradient){nt=n._g.doc.getElementById(s.getAttribute("fill").replace(/^url\(#|\)$/g,h));nt&&(ut=nt.getElementsByTagName("stop"),t(ut[ut.length-1],{"stop-opacity":e}));break}default:a=="font-size"&&(e=tt(e,10)+"px");at=a.replace(/(\-.)/g,function(n){return n.substring(1).toUpperCase()});s.style[at]=e;r._.dirty=1;s.setAttribute(a,e)}}ot(r,f);s.style.visibility=vt},ut=1.2,ot=function(r,f){var y,s,l,e,a,p,v;if(r.type=="text"&&!!(f[i]("text")||f[i]("font")||f[i]("font-size")||f[i]("x")||f[i]("y"))){var c=r.attrs,o=r.node,w=o.firstChild?tt(n._g.doc.defaultView.getComputedStyle(o.firstChild,h).getPropertyValue("font-size"),10):10;if(f[i]("text")){for(c.text=f.text;o.firstChild;)o.removeChild(o.firstChild);for(y=u(f.text).split("\n"),s=[],e=0,a=y.length;e<a;e++)l=t("tspan"),e&&t(l,{dy:w*ut,x:c.x}),l.appendChild(n._g.doc.createTextNode(y[e])),o.appendChild(l),s[e]=l}else for(s=o.getElementsByTagName("tspan"),e=0,a=s.length;e<a;e++)e?t(s[e],{dy:w*ut,x:c.x}):t(s[0],{dy:0});t(o,{x:c.x,y:c.y});r._.dirty=1;p=r._getBBox();v=c.y-(p.y+p.height/2);v&&n.is(v,"finite")&&t(s[0],{dy:v})}},s=function(t,i){this[0]=this.node=t;t.raphael=!0;this.id=n._oid++;t.raphaelid=this.id;this.matrix=n.matrix();this.realPath=null;this.paper=i;this.attrs=this.attrs||{};this._={transform:[],sx:1,sy:1,deg:0,dx:0,dy:0,dirty:1};!i.bottom&&(i.bottom=this);this.prev=i.top;i.top&&(i.top.next=this);i.top=this;this.next=null},r=n.el;s.prototype=r;r.constructor=s;n._engine.path=function(n,i){var u=t("path"),r;return i.canvas&&i.canvas.appendChild(u),r=new s(u,i),r.type="path",g(r,{fill:"none",stroke:"#000",path:n}),r};r.rotate=function(n,t,i){if(this.removed)return this;if(n=u(n).split(l),n.length-1&&(t=f(n[1]),i=f(n[2])),n=f(n[0]),i==null&&(t=i),t==null||i==null){var r=this.getBBox(1);t=r.x+r.width/2;i=r.y+r.height/2}return this.transform(this._.transform.concat([["r",n,t,i]])),this};r.scale=function(n,t,i,r){if(this.removed)return this;if(n=u(n).split(l),n.length-1&&(t=f(n[1]),i=f(n[2]),r=f(n[3])),n=f(n[0]),t==null&&(t=n),r==null&&(i=r),i==null||r==null)var e=this.getBBox(1);return i=i==null?e.x+e.width/2:i,r=r==null?e.y+e.height/2:r,this.transform(this._.transform.concat([["s",n,t,i,r]])),this};r.translate=function(n,t){return this.removed?this:(n=u(n).split(l),n.length-1&&(t=f(n[1])),n=f(n[0])||0,t=+t||0,this.transform(this._.transform.concat([["t",n,t]])),this)};r.transform=function(r){var u=this._,f;return r==null?u.transform:(n._extractTransform(this,r),this.clip&&t(this.clip,{transform:this.matrix.invert()}),this.pattern&&b(this),this.node&&t(this.node,{transform:this.matrix}),(u.sx!=1||u.sy!=1)&&(f=this.attrs[i]("stroke-width")?this.attrs["stroke-width"]:1,this.attr({"stroke-width":f})),this)};r.hide=function(){return this.removed||this.paper.safari(this.node.style.display="none"),this};r.show=function(){return this.removed||this.paper.safari(this.node.style.display=""),this};r.remove=function(){var t,i;if(!this.removed){t=this.paper;t.__set__&&t.__set__.exclude(this);w.unbind("*.*."+this.id);this.gradient&&t.defs.removeChild(this.gradient);n._tear(this,t);this.node.parentNode.removeChild(this.node);for(i in this)this[i]=typeof this[i]=="function"?n._removedFactory(i):null;this.removed=!0}};r._getBBox=function(){var t,n;this.node.style.display=="none"&&(this.show(),t=!0);n={};try{n=this.node.getBBox()}catch(i){}finally{n=n||{}}return t&&this.hide(),n};r.attr=function(t,r){var e,c,a,s,o,h,f,u,v,y;if(this.removed)return this;if(t==null){e={};for(c in this.attrs)this.attrs[i](c)&&(e[c]=this.attrs[c]);return e.gradient&&e.fill=="none"&&(e.fill=e.gradient)&&delete e.gradient,e.transform=this._.transform,e}if(r==null&&n.is(t,"string")){if(t=="fill"&&this.attrs.fill=="none"&&this.attrs.gradient)return this.attrs.gradient;if(t=="transform")return this._.transform;for(a=t.split(l),s={},o=0,h=a.length;o<h;o++)t=a[o],s[t]=t in this.attrs?this.attrs[t]:n.is(this.paper.customAttributes[t],"function")?this.paper.customAttributes[t].def:n._availableAttrs[t];return h-1?s:s[a[0]]}if(r==null&&n.is(t,"array")){for(s={},o=0,h=t.length;o<h;o++)s[t[o]]=this.attr(t[o]);return s}r!=null?(f={},f[t]=r):t!=null&&n.is(t,"object")&&(f=t);for(u in f)w("attr."+u+"."+this.id,this,f[u]);for(u in this.paper.customAttributes)if(this.paper.customAttributes[i](u)&&f[i](u)&&n.is(this.paper.customAttributes[u],"function")){v=this.paper.customAttributes[u].apply(this,[].concat(f[u]));this.attrs[u]=f[u];for(y in v)v[i](y)&&(f[y]=v[y])}return g(this,f),this};r.toFront=function(){if(this.removed)return this;this.node.parentNode.tagName.toLowerCase()=="a"?this.node.parentNode.parentNode.appendChild(this.node.parentNode):this.node.parentNode.appendChild(this.node);var t=this.paper;return t.top!=this&&n._tofront(this,t),this};r.toBack=function(){var t,i;return this.removed?this:(t=this.node.parentNode,t.tagName.toLowerCase()=="a"?t.parentNode.insertBefore(this.node.parentNode,this.node.parentNode.parentNode.firstChild):t.firstChild!=this.node&&t.insertBefore(this.node,this.node.parentNode.firstChild),n._toback(this,this.paper),i=this.paper,this)};r.insertAfter=function(t){if(this.removed)return this;var i=t.node||t[t.length-1].node;return i.nextSibling?i.parentNode.insertBefore(this.node,i.nextSibling):i.parentNode.appendChild(this.node),n._insertafter(this,t,this.paper),this};r.insertBefore=function(t){if(this.removed)return this;var i=t.node||t[0].node;return i.parentNode.insertBefore(this.node,i),n._insertbefore(this,t,this.paper),this};r.blur=function(i){var r=this,u,f;+i!=0?(u=t("filter"),f=t("feGaussianBlur"),r.attrs.blur=i,u.id=n.createUUID(),t(f,{stdDeviation:+i||1.5}),u.appendChild(f),r.paper.defs.appendChild(u),r._blur=u,t(r.node,{filter:"url(#"+u.id+")"})):(r._blur&&(r._blur.parentNode.removeChild(r._blur),delete r._blur,delete r.attrs.blur),r.node.removeAttribute("filter"))};n._engine.circle=function(n,i,r,u){var e=t("circle"),f;return n.canvas&&n.canvas.appendChild(e),f=new s(e,n),f.attrs={cx:i,cy:r,r:u,fill:"none",stroke:"#000"},f.type="circle",t(e,f.attrs),f};n._engine.rect=function(n,i,r,u,f,e){var h=t("rect"),o;return n.canvas&&n.canvas.appendChild(h),o=new s(h,n),o.attrs={x:i,y:r,width:u,height:f,r:e||0,rx:e||0,ry:e||0,fill:"none",stroke:"#000"},o.type="rect",t(h,o.attrs),o};n._engine.ellipse=function(n,i,r,u,f){var o=t("ellipse"),e;return n.canvas&&n.canvas.appendChild(o),e=new s(o,n),e.attrs={cx:i,cy:r,rx:u,ry:f,fill:"none",stroke:"#000"},e.type="ellipse",t(o,e.attrs),e};n._engine.image=function(n,i,r,u,f,e){var o=t("image"),h;return t(o,{x:r,y:u,width:f,height:e,preserveAspectRatio:"none"}),o.setAttributeNS(v,"href",i),n.canvas&&n.canvas.appendChild(o),h=new s(o,n),h.attrs={x:r,y:u,width:f,height:e,src:i},h.type="image",h};n._engine.text=function(i,r,u,f){var o=t("text"),e;return i.canvas&&i.canvas.appendChild(o),e=new s(o,i),e.attrs={x:r,y:u,"text-anchor":"middle",text:f,font:n._availableAttrs.font,stroke:"none",fill:"#000"},e.type="text",g(e,e.attrs),e};n._engine.setSize=function(n,t){return this.width=n||this.width,this.height=t||this.height,this.canvas.setAttribute("width",this.width),this.canvas.setAttribute("height",this.height),this._viewBox&&this.setViewBox.apply(this,this._viewBox),this};n._engine.create=function(){var u=n._getContainer.apply(0,arguments),i=u&&u.container,o=u.x,s=u.y,f=u.width,e=u.height,r,h,c;if(!i)throw new Error("SVG container not found.");return r=t("svg"),h="overflow:hidden;",o=o||0,s=s||0,f=f||512,e=e||342,t(r,{height:e,version:1.1,width:f,xmlns:"http://www.w3.org/2000/svg"}),i==1?(r.style.cssText=h+"position:absolute;left:"+o+"px;top:"+s+"px",n._g.doc.body.appendChild(r),c=1):(r.style.cssText=h+"position:relative",i.firstChild?i.insertBefore(r,i.firstChild):i.appendChild(r)),i=new n._Paper,i.width=f,i.height=e,i.canvas=r,i.clear(),i._left=i._top=0,c&&(i.renderfix=function(){}),i.renderfix(),i};n._engine.setViewBox=function(n,i,r,u,f){w("setViewBox",this,this._viewBox,[n,i,r,u,f]);var o=k(r/this.width,u/this.height),e=this.top,c=f?"meet":"xMinYMin",s,h;for(n==null?(this._vbSize&&(o=1),delete this._vbSize,s="0 0 "+this.width+a+this.height):(this._vbSize=o,s=n+a+i+a+r+a+u),t(this.canvas,{viewBox:s,preserveAspectRatio:c});o&&e;)h="stroke-width"in e.attrs?e.attrs["stroke-width"]:1,e.attr({"stroke-width":h}),e._.dirty=1,e._.dirtyT=1,e=e.prev;return this._viewBox=[n,i,r,u,!!f],this};n.prototype.renderfix=function(){var n=this.canvas,r=n.style,u=n.getScreenCTM()||n.createSVGMatrix(),t=-u.e%1,i=-u.f%1;(t||i)&&(t&&(this._left=(this._left+t)%1,r.left=this._left+"px"),i&&(this._top=(this._top+i)%1,r.top=this._top+"px"))};n.prototype.clear=function(){n.eve("clear",this);for(var i=this.canvas;i.firstChild;)i.removeChild(i.firstChild);this.bottom=this.top=null;(this.desc=t("desc")).appendChild(n._g.doc.createTextNode("Created with Raphaël "+n.version));i.appendChild(this.desc);i.appendChild(this.defs=t("defs"))};n.prototype.remove=function(){w("remove",this);this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas);for(var t in this)this[t]=typeof this[t]=="function"?n._removedFactory(t):null};nt=n.st;for(y in r)r[i](y)&&!nt[i](y)&&(nt[y]=function(n){return function(){var t=arguments;return this.forEach(function(i){i[n].apply(i,t)})}}(y))}(window.Raphael);window.Raphael.vml&&function(n){var h="hasOwnProperty",i=String,f=parseFloat,c=Math,e=c.round,k=c.max,g=c.min,p=c.abs,l="fill",a=/[, ]+/,ut=n.eve,ft=" progid:DXImageTransform.Microsoft",o=" ",u="",nt={M:"m",L:"l",C:"c",Z:"x",m:"t",l:"r",c:"v",z:"x"},et=/([clmz]),?([^clmz]*)/gi,ot=/ progid:\S+Blur\([^\)]+\)/g,st=/-?[^,\s-]+/g,tt="position:absolute;left:0;top:0;width:1px;height:1px",t=21600,ht={path:1,rect:1,image:1},ct={circle:1,ellipse:1},lt=function(r){var l=/[ahqstv]/ig,a=n._pathToAbsolute,v,c,y,f,s,w,h,p;if(i(r).match(l)&&(a=n._path2curve),l=/[clmz]/g,a==n._pathToAbsolute&&!i(r).match(l))return i(r).replace(et,function(n,i,r){var u=[],o=i.toLowerCase()=="m",f=nt[i];return r.replace(st,function(n){o&&u.length==2&&(f+=u+nt[i=="m"?"l":"L"],u=[]);u.push(e(n*t))}),f+u});for(c=a(r),v=[],s=0,w=c.length;s<w;s++){for(y=c[s],f=c[s][0].toLowerCase(),f=="z"&&(f="x"),h=1,p=y.length;h<p;h++)f+=e(y[h]*t)+(h!=p-1?",":u);v.push(f)}return v.join(o)},it=function(t,i,r){var u=n.matrix();return u.rotate(-t,.5,.5),{dx:u.x(i,r),dy:u.y(i,r)}},w=function(n,i,r,u,f,e){var v=n._,k=n.matrix,h=v.fillpos,c=n.node,y=c.style,w=1,b="",d=t/i,g=t/r,a,s;y.visibility="hidden";!i||!r||(c.coordsize=p(d)+o+p(g),y.rotation=e*(i*r<0?-1:1),e&&(a=it(e,u,f),u=a.dx,f=a.dy),i<0&&(b+="x"),r<0&&(b+=" y")&&(w=-1),y.flip=b,c.coordorigin=u*-d+o+f*-g,(h||v.fillsize)&&(s=c.getElementsByTagName(l),s=s&&s[0],c.removeChild(s),h&&(a=it(e,k.x(h[0],h[1]),k.y(h[0],h[1])),s.position=a.dx*w+o+a.dy*w),v.fillsize&&(s.size=v.fillsize[0]*p(i)+o+v.fillsize[1]*p(r)),c.appendChild(s)),y.visibility="visible")},s,d,y;n.toString=function(){return"Your browser doesn’t support SVG. Falling down to VML.\nYou are running Raphaël "+this.version};var rt=function(n,t,r){for(var u=i(t).toLowerCase().split("-"),o=r?"end":"start",f=u.length,s="classic",h="medium",c="medium",e;f--;)switch(u[f]){case"block":case"classic":case"oval":case"diamond":case"open":case"none":s=u[f];break;case"wide":case"narrow":c=u[f];break;case"long":case"short":h=u[f]}e=n.node.getElementsByTagName("stroke")[0];e[o+"arrow"]=s;e[o+"arrowlength"]=h;e[o+"arrowwidth"]=c},v=function(r,c){var yt,nt,ot,ut,ft,y,si,pt,st,tt,d,dt,gt,et,ni,vt,ri,bt,hi;r.attrs=r.attrs||{};var b=r.node,v=r.attrs,it=b.style,ui=ht[r.type]&&(c.x!=v.x||c.y!=v.y||c.width!=v.width||c.height!=v.height||c.cx!=v.cx||c.cy!=v.cy||c.rx!=v.rx||c.ry!=v.ry||c.r!=v.r),ci=ct[r.type]&&(v.cx!=c.cx||v.cy!=c.cy||v.r!=c.r||v.rx!=c.rx||v.ry!=c.ry),p=r;for(yt in c)c[h](yt)&&(v[yt]=c[yt]);if(ui&&(v.path=n._getPath[r.type](r),r._.dirty=1),c.href&&(b.href=c.href),c.title&&(b.title=c.title),c.target&&(b.target=c.target),c.cursor&&(it.cursor=c.cursor),"blur"in c&&r.blur(c.blur),(c.path&&r.type=="path"||ui)&&(b.path=lt(~i(v.path).toLowerCase().indexOf("r")?n._pathToAbsolute(v.path):v.path),r.type=="image"&&(r._.fillpos=[v.x,v.y],r._.fillsize=[v.width,v.height],w(r,1,1,0,0,0))),"transform"in c&&r.transform(c.transform),ci){var kt=+v.cx,fi=+v.cy,ei=+v.rx||+v.r||0,oi=+v.ry||+v.r||0;b.path=n.format("ar{0},{1},{2},{3},{4},{1},{4},{1}x",e((kt-ei)*t),e((fi-oi)*t),e((kt+ei)*t),e((fi+oi)*t),e(kt*t))}if("clip-rect"in c&&(nt=i(c["clip-rect"]).split(a),nt.length==4&&(nt[2]=+nt[2]+ +nt[0],nt[3]=+nt[3]+ +nt[1],ot=b.clipRect||n._g.doc.createElement("div"),ut=ot.style,ut.clip=n.format("rect({1}px {2}px {3}px {0}px)",nt),b.clipRect||(ut.position="absolute",ut.top=0,ut.left=0,ut.width=r.paper.width+"px",ut.height=r.paper.height+"px",b.parentNode.insertBefore(ot,b),ot.appendChild(b),b.clipRect=ot)),c["clip-rect"]||b.clipRect&&(b.clipRect.style.clip="auto")),r.textpath&&(ft=r.textpath.style,c.font&&(ft.font=c.font),c["font-family"]&&(ft.fontFamily='"'+c["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g,u)+'"'),c["font-size"]&&(ft.fontSize=c["font-size"]),c["font-weight"]&&(ft.fontWeight=c["font-weight"]),c["font-style"]&&(ft.fontStyle=c["font-style"])),"arrow-start"in c&&rt(p,c["arrow-start"]),"arrow-end"in c&&rt(p,c["arrow-end"],1),(c.opacity!=null||c["stroke-width"]!=null||c.fill!=null||c.src!=null||c.stroke!=null||c["stroke-width"]!=null||c["stroke-opacity"]!=null||c["fill-opacity"]!=null||c["stroke-dasharray"]!=null||c["stroke-miterlimit"]!=null||c["stroke-linejoin"]!=null||c["stroke-linecap"]!=null)&&(y=b.getElementsByTagName(l),si=!1,y=y&&y[0],!y&&(si=y=s(l)),r.type=="image"&&c.src&&(y.src=c.src),c.fill&&(y.on=!0),(y.on==null||c.fill=="none"||c.fill===null)&&(y.on=!1),y.on&&c.fill&&(pt=i(c.fill).match(n._ISURL),pt?(y.parentNode==b&&b.removeChild(y),y.rotate=!0,y.src=pt[1],y.type="tile",st=r.getBBox(1),y.position=st.x+o+st.y,r._.fillpos=[st.x,st.y],n._preload(pt[1],function(){r._.fillsize=[this.offsetWidth,this.offsetHeight]})):(y.color=n.getRGB(c.fill).hex,y.src=u,y.type="solid",n.getRGB(c.fill).error&&(p.type in{circle:1,ellipse:1}||i(c.fill).charAt()!="r")&&at(p,c.fill,y)&&(v.fill="none",v.gradient=c.fill,y.rotate=!1))),("fill-opacity"in c||"opacity"in c)&&(tt=((+v["fill-opacity"]+1||2)-1)*((+v.opacity+1||2)-1)*((+n.getRGB(c.fill).o+1||2)-1),tt=g(k(tt,0),1),y.opacity=tt,y.src&&(y.color="none")),b.appendChild(y),d=b.getElementsByTagName("stroke")&&b.getElementsByTagName("stroke")[0],dt=!1,d||(dt=d=s("stroke")),(c.stroke&&c.stroke!="none"||c["stroke-width"]||c["stroke-opacity"]!=null||c["stroke-dasharray"]||c["stroke-miterlimit"]||c["stroke-linejoin"]||c["stroke-linecap"])&&(d.on=!0),(c.stroke=="none"||c.stroke===null||d.on==null||c.stroke==0||c["stroke-width"]==0)&&(d.on=!1),gt=n.getRGB(c.stroke),d.on&&c.stroke&&(d.color=gt.hex),tt=((+v["stroke-opacity"]+1||2)-1)*((+v.opacity+1||2)-1)*((+gt.o+1||2)-1),et=(f(c["stroke-width"])||1)*.75,tt=g(k(tt,0),1),c["stroke-width"]==null&&(et=v["stroke-width"]),c["stroke-width"]&&(d.weight=et),et&&et<1&&(tt*=et)&&(d.weight=1),d.opacity=tt,c["stroke-linejoin"]&&(d.joinstyle=c["stroke-linejoin"]||"miter"),d.miterlimit=c["stroke-miterlimit"]||8,c["stroke-linecap"]&&(d.endcap=c["stroke-linecap"]=="butt"?"flat":c["stroke-linecap"]=="square"?"square":"round"),c["stroke-dasharray"]&&(ni={"-":"shortdash",".":"shortdot","-.":"shortdashdot","-..":"shortdashdotdot",". ":"dot","- ":"dash","--":"longdash","- .":"dashdot","--.":"longdashdot","--..":"longdashdotdot"},d.dashstyle=ni[h](c["stroke-dasharray"])?ni[c["stroke-dasharray"]]:u),dt&&b.appendChild(d)),p.type=="text"){p.paper.canvas.style.display=u;var ti=p.paper.span,ii=100,wt=v.font&&v.font.match(/\d+(?:\.\d*)?(?=px)/);for(it=ti.style,v.font&&(it.font=v.font),v["font-family"]&&(it.fontFamily=v["font-family"]),v["font-weight"]&&(it.fontWeight=v["font-weight"]),v["font-style"]&&(it.fontStyle=v["font-style"]),wt=f(v["font-size"]||wt&&wt[0])||10,it.fontSize=wt*ii+"px",p.textpath.string&&(ti.innerHTML=i(p.textpath.string).replace(/</g,"&#60;").replace(/&/g,"&#38;").replace(/\n/g,"<br>")),vt=ti.getBoundingClientRect(),p.W=v.w=(vt.right-vt.left)/ii,p.H=v.h=(vt.bottom-vt.top)/ii,p.X=v.x,p.Y=v.y+p.H/2,(("x"in c)||("y"in c))&&(p.path.v=n.format("m{0},{1}l{2},{1}",e(v.x*t),e(v.y*t),e(v.x*t)+1)),ri=["x","y","text","font","font-family","font-weight","font-style","font-size"],bt=0,hi=ri.length;bt<hi;bt++)if(ri[bt]in c){p._.dirty=1;break}switch(v["text-anchor"]){case"start":p.textpath.style["v-text-align"]="left";p.bbx=p.W/2;break;case"end":p.textpath.style["v-text-align"]="right";p.bbx=-p.W/2;break;default:p.textpath.style["v-text-align"]="center";p.bbx=0}p.textpath.style["v-text-kern"]=!0}},at=function(t,r,e){var l,s,a,h,w;t.attrs=t.attrs||{};var b=t.attrs,v=Math.pow,y="linear",p=".5 .5";if((t.attrs.gradient=r,r=i(r).replace(n._radial_gradient,function(n,t,i){return y="radial",t&&i&&(t=f(t),i=f(i),v(t-.5,2)+v(i-.5,2)>.25&&(i=c.sqrt(.25-v(t-.5,2))*((i>.5)*2-1)+.5),p=t+o+i),u}),r=r.split(/\s*\-\s*/),y=="linear"&&(l=r.shift(),l=-f(l),isNaN(l)))||(s=n._parseDots(r),!s))return null;if(t=t.shape||t.node,s.length){for(t.removeChild(e),e.on=!0,e.method="none",e.color=s[0].color,e.color2=s[s.length-1].color,a=[],h=0,w=s.length;h<w;h++)s[h].offset&&a.push(s[h].offset+o+s[h].color);e.colors=a.length?a.join():"0% "+e.color;y=="radial"?(e.type="gradientTitle",e.focus="100%",e.focussize="0 0",e.focusposition=p,e.angle=0):(e.type="gradient",e.angle=(270-l)%360);t.appendChild(e)}return 1},b=function(t,i){this[0]=this.node=t;t.raphael=!0;this.id=n._oid++;t.raphaelid=this.id;this.X=0;this.Y=0;this.attrs={};this.paper=i;this.matrix=n.matrix();this._={transform:[],sx:1,sy:1,dx:0,dy:0,deg:0,dirty:1,dirtyT:1};!i.bottom&&(i.bottom=this);this.prev=i.top;i.top&&(i.top.next=this);i.top=this;this.next=null},r=n.el;b.prototype=r;r.constructor=b;r.transform=function(r){var e,a,l;if(r==null)return this._.transform;e=this.paper._viewBoxShift;a=e?"s"+[e.scale,e.scale]+"-1-1t"+[e.dx,e.dy]:u;e&&(l=r=i(r).replace(/\.{3}|\u2026/g,this._.transform||u));n._extractTransform(this,a+r);var s=this.matrix.clone(),h=this.skew,c=this.node,f,v=~i(this.attrs.fill).indexOf("-"),d=!i(this.attrs.fill).indexOf("url(");if(s.translate(-.5,-.5),d||v||this.type=="image")if(h.matrix="1 0 0 1",h.offset="0 0",f=s.split(),v&&f.noRotation||!f.isSimple){c.style.filter=s.toFilter();var y=this.getBBox(),p=this.getBBox(1),b=y.x-p.x,k=y.y-p.y;c.coordorigin=b*-t+o+k*-t;w(this,1,1,b,k,0)}else c.style.filter=u,w(this,f.scalex,f.scaley,f.dx,f.dy,f.rotate);else c.style.filter=u,h.matrix=i(s),h.offset=s.offset();return l&&(this._.transform=l),this};r.rotate=function(n,t,r){if(this.removed)return this;if(n!=null){if(n=i(n).split(a),n.length-1&&(t=f(n[1]),r=f(n[2])),n=f(n[0]),r==null&&(t=r),t==null||r==null){var u=this.getBBox(1);t=u.x+u.width/2;r=u.y+u.height/2}return this._.dirtyT=1,this.transform(this._.transform.concat([["r",n,t,r]])),this}};r.translate=function(n,t){return this.removed?this:(n=i(n).split(a),n.length-1&&(t=f(n[1])),n=f(n[0])||0,t=+t||0,this._.bbox&&(this._.bbox.x+=n,this._.bbox.y+=t),this.transform(this._.transform.concat([["t",n,t]])),this)};r.scale=function(n,t,r,u){if(this.removed)return this;if(n=i(n).split(a),n.length-1&&(t=f(n[1]),r=f(n[2]),u=f(n[3]),isNaN(r)&&(r=null),isNaN(u)&&(u=null)),n=f(n[0]),t==null&&(t=n),u==null&&(r=u),r==null||u==null)var e=this.getBBox(1);return r=r==null?e.x+e.width/2:r,u=u==null?e.y+e.height/2:u,this.transform(this._.transform.concat([["s",n,t,r,u]])),this._.dirtyT=1,this};r.hide=function(){return this.removed||(this.node.style.display="none"),this};r.show=function(){return this.removed||(this.node.style.display=u),this};r._getBBox=function(){return this.removed?{}:{x:this.X+(this.bbx||0)-this.W/2,y:this.Y-this.H,width:this.W,height:this.H}};r.remove=function(){if(!this.removed){this.paper.__set__&&this.paper.__set__.exclude(this);n.eve.unbind("*.*."+this.id);n._tear(this,this.paper);this.node.parentNode.removeChild(this.node);this.shape&&this.shape.parentNode.removeChild(this.shape);for(var t in this)this[t]=typeof this[t]=="function"?n._removedFactory(t):null;this.removed=!0}};r.attr=function(t,i){var f,c,y,o,e,s,r,u,p,w;if(this.removed)return this;if(t==null){f={};for(c in this.attrs)this.attrs[h](c)&&(f[c]=this.attrs[c]);return f.gradient&&f.fill=="none"&&(f.fill=f.gradient)&&delete f.gradient,f.transform=this._.transform,f}if(i==null&&n.is(t,"string")){if(t==l&&this.attrs.fill=="none"&&this.attrs.gradient)return this.attrs.gradient;for(y=t.split(a),o={},e=0,s=y.length;e<s;e++)t=y[e],o[t]=t in this.attrs?this.attrs[t]:n.is(this.paper.customAttributes[t],"function")?this.paper.customAttributes[t].def:n._availableAttrs[t];return s-1?o:o[y[0]]}if(this.attrs&&i==null&&n.is(t,"array")){for(o={},e=0,s=t.length;e<s;e++)o[t[e]]=this.attr(t[e]);return o}i!=null&&(r={},r[t]=i);i==null&&n.is(t,"object")&&(r=t);for(u in r)ut("attr."+u+"."+this.id,this,r[u]);if(r){for(u in this.paper.customAttributes)if(this.paper.customAttributes[h](u)&&r[h](u)&&n.is(this.paper.customAttributes[u],"function")){p=this.paper.customAttributes[u].apply(this,[].concat(r[u]));this.attrs[u]=r[u];for(w in p)p[h](w)&&(r[w]=p[w])}r.text&&this.type=="text"&&(this.textpath.string=r.text);v(this,r)}return this};r.toFront=function(){return this.removed||this.node.parentNode.appendChild(this.node),this.paper&&this.paper.top!=this&&n._tofront(this,this.paper),this};r.toBack=function(){return this.removed?this:(this.node.parentNode.firstChild!=this.node&&(this.node.parentNode.insertBefore(this.node,this.node.parentNode.firstChild),n._toback(this,this.paper)),this)};r.insertAfter=function(t){return this.removed?this:(t.constructor==n.st.constructor&&(t=t[t.length-1]),t.node.nextSibling?t.node.parentNode.insertBefore(this.node,t.node.nextSibling):t.node.parentNode.appendChild(this.node),n._insertafter(this,t,this.paper),this)};r.insertBefore=function(t){return this.removed?this:(t.constructor==n.st.constructor&&(t=t[0]),t.node.parentNode.insertBefore(this.node,t.node),n._insertbefore(this,t,this.paper),this)};r.blur=function(t){var i=this.node.runtimeStyle,r=i.filter;r=r.replace(ot,u);+t!=0?(this.attrs.blur=t,i.filter=r+o+ft+".Blur(pixelradius="+(+t||1.5)+")",i.margin=n.format("-{0}px 0 0 -{0}px",e(+t||1.5))):(i.filter=r,i.margin=0,delete this.attrs.blur)};n._engine.path=function(n,i){var f=s("shape"),r,h,e;return f.style.cssText=tt,f.coordsize=t+o+t,f.coordorigin=i.coordorigin,r=new b(f,i),h={fill:"none",stroke:"#000"},n&&(h.path=n),r.type="path",r.path=[],r.Path=u,v(r,h),i.canvas.appendChild(f),e=s("skew"),e.on=!0,f.appendChild(e),r.skew=e,r.transform(u),r};n._engine.rect=function(t,i,r,u,f,e){var h=n._rectPath(i,r,u,f,e),o=t.path(h),s=o.attrs;return o.X=s.x=i,o.Y=s.y=r,o.W=s.width=u,o.H=s.height=f,s.r=e,s.path=h,o.type="rect",o};n._engine.ellipse=function(n,t,i,r,u){var f=n.path(),e=f.attrs;return f.X=t-r,f.Y=i-u,f.W=r*2,f.H=u*2,f.type="ellipse",v(f,{cx:t,cy:i,rx:r,ry:u}),f};n._engine.circle=function(n,t,i,r){var u=n.path(),f=u.attrs;return u.X=t-r,u.Y=i-r,u.W=u.H=r*2,u.type="circle",v(u,{cx:t,cy:i,r:r}),u};n._engine.image=function(t,i,r,u,f,e){var a=n._rectPath(r,u,f,e),o=t.path(a).attr({stroke:"none"}),s=o.attrs,c=o.node,h=c.getElementsByTagName(l)[0];return s.src=i,o.X=s.x=r,o.Y=s.y=u,o.W=s.width=f,o.H=s.height=e,s.path=a,o.type="image",h.parentNode==c&&c.removeChild(h),h.rotate=!0,h.src=i,h.type="tile",o._.fillpos=[r,u],o._.fillsize=[f,e],c.appendChild(h),w(o,1,1,0,0,0),o};n._engine.text=function(r,f,h,c){var a=s("shape"),y=s("path"),p=s("textpath"),l,k,w;return f=f||0,h=h||0,c=c||"",y.v=n.format("m{0},{1}l{2},{1}",e(f*t),e(h*t),e(f*t)+1),y.textpathok=!0,p.string=i(c),p.on=!0,a.style.cssText=tt,a.coordsize=t+o+t,a.coordorigin="0 0",l=new b(a,r),k={fill:"#000",stroke:"none",font:n._availableAttrs.font,text:c},l.shape=a,l.path=y,l.textpath=p,l.type="text",l.attrs.text=i(c),l.attrs.x=f,l.attrs.y=h,l.attrs.w=1,l.attrs.h=1,v(l,k),a.appendChild(p),a.appendChild(y),r.canvas.appendChild(a),w=s("skew"),w.on=!0,a.appendChild(w),l.skew=w,l.transform(u),l};n._engine.setSize=function(t,i){var r=this.canvas.style;return this.width=t,this.height=i,t==+t&&(t+="px"),i==+i&&(i+="px"),r.width=t,r.height=i,r.clip="rect(0 "+t+" "+i+" 0)",this._viewBox&&n._engine.setViewBox.apply(this,this._viewBox),this};n._engine.setViewBox=function(t,i,r,u,f){n.eve("setViewBox",this,this._viewBox,[t,i,r,u,f]);var e=this.width,o=this.height,c=1/k(r/e,u/o),s,h;return f&&(s=o/u,h=e/r,r*s<e&&(t-=(e-r*s)/2/s),u*h<o&&(i-=(o-u*h)/2/h)),this._viewBox=[t,i,r,u,!!f],this._viewBoxShift={dx:-t,dy:-i,scale:c},this.forEach(function(n){n.transform("...")}),this};n._engine.initWin=function(n){var t=n.document;t.createStyleSheet().addRule(".rvml","behavior:url(#default#VML)");try{t.namespaces.rvml||t.namespaces.add("rvml","urn:schemas-microsoft-com:vml");s=function(n){return t.createElement("<rvml:"+n+' class="rvml">')}}catch(i){s=function(n){return t.createElement("<"+n+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}};n._engine.initWin(n._g.win);n._engine.create=function(){var e=n._getContainer.apply(0,arguments),f=e.container,r=e.height,u=e.width,c=e.x,l=e.y;if(!f)throw new Error("VML container not found.");var i=new n._Paper,s=i.canvas=n._g.doc.createElement("div"),h=s.style;return c=c||0,l=l||0,u=u||512,r=r||342,i.width=u,i.height=r,u==+u&&(u+="px"),r==+r&&(r+="px"),i.coordsize=t*1e3+o+t*1e3,i.coordorigin="0 0",i.span=n._g.doc.createElement("span"),i.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;",s.appendChild(i.span),h.cssText=n.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden",u,r),f==1?(n._g.doc.body.appendChild(s),h.left=c+"px",h.top=l+"px",h.position="absolute"):f.firstChild?f.insertBefore(s,f.firstChild):f.appendChild(s),i.renderfix=function(){},i};n.prototype.clear=function(){n.eve("clear",this);this.canvas.innerHTML=u;this.span=n._g.doc.createElement("span");this.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";this.canvas.appendChild(this.span);this.bottom=this.top=null};n.prototype.remove=function(){n.eve("remove",this);this.canvas.parentNode.removeChild(this.canvas);for(var t in this)this[t]=typeof this[t]=="function"?n._removedFactory(t):null;return!0};d=n.st;for(y in r)r[h](y)&&!d[h](y)&&(d[y]=function(n){return function(){var t=arguments;return this.forEach(function(i){i[n].apply(i,t)})}}(y))}(window.Raphael);var smtbMouseBehavior=base2.Base.extend({boardWrapper:null,constructor:function(){},initialize:function(n){this.boardWrapper=n},remove:function(){this.boardWrapper=null},getSquareCoords:function(n){var t=this.boardWrapper.boardRenderer;if(t.visibleCols!=8||t.visibleRows!=8||n.button!=0)return null;var u=this.mouseCoords(n),h=t.boardTable.rows[1].cells[1],o=$(h).offset(),i=Math.floor((u.x-o.left)/t.squareSize)+1,r=8-Math.floor((u.y-o.top)/t.squareSize),s=$("#dragdrop_left_top").offset(),f=Math.floor((u.x-s.left)/t.squareSize),e=8-Math.floor((u.y-s.top)/t.squareSize);return(t.gui.flipped&&(i=9-i,r=9-r),i<1||i>8||r<1||r>8)?f<0||f>1||e<3||e>8?null:{x:f==0?"i":"j",y:e}:{x:this.boardWrapper.board.letters[i],y:r}},mouseCoords:function(n){if(n.pageX||n.pageY)return{x:n.pageX,y:n.pageY};var t=document.body;return{x:n.clientX+t.scrollLeft-t.clientLeft,y:n.clientY+t.scrollTop-t.clientTop}},getMouseOffset:function(n){return{x:Math.floor(n/2),y:Math.floor(n/2)}}}),smtbDragPiecesBehavior=smtbMouseBehavior.extend({dragObject:null,dragFromCoords:null,mouseOffset:null,dropTargets:[],_boardPosition:null,initialize:function(n){this.base(n);$(this.boardWrapper).mousedown(this,this.onMouseDown);$(this.boardWrapper).mousemove(this,_.throttle(this.onMouseMove,23));$(document).mouseup(this,this.onMouseUp)},remove:function(){$(this.boardWrapper).unbind("mousedown");$(this.boardWrapper).unbind("mousemove");$(document).unbind("mouseup",this.onMouseUp);this.base()},onDrag:function(){return!0},onDrop:function(){return!0},onMovePiece:function(){},_addDropTarget:function(n){this.dropTargets.push(n)},onMouseMove:function(n){var i=n.data,f;if(!i.dragObject)return!0;var e=i.mouseCoords(n),u=this.boardRenderer.squareSize,r=15,t={y:e.y-u/2-i._boardPosition.top-r,x:e.x-u/2-i._boardPosition.left-r};return t.y<-34||t.y>356||t.x<-34||t.x>482?!1:(f=i.dragObject.style,f.top=t.y+r+"px",f.left=t.x+r-(u>61?2:0)+"px",!0)},onMouseDown:function(n){var t=n.data,s=this.boardRenderer.gui,e,u,i,r;if(s.BoardDisabled)return!1;if(e=t.getSquareCoords(n),e==null)return!0;if((u=t.premoveFromCoords,t.dragFromCoords=u?{x:u.x,y:u.y}:e,t.premoveFromCoords=null,t.dragFromCoords==null)||(i=s.getGUISquare(t.dragFromCoords.x,t.dragFromCoords.y).children[0],!i)||!t.onDrag(t.dragFromCoords))return!1;var h=t.mouseCoords(n),o=this.boardRenderer.squareSize,f=15;return t._boardPosition=$(this.boardRenderer.boardTable.rows[0].cells[0]).offset(),r={y:h.y-t._boardPosition.top-f,x:h.x-t._boardPosition.left-f},t.mouseOffset={x:r.x%o,y:r.y%o},i.style.position="absolute",i.style.top=r.y-t.mouseOffset.y+f+"px",i.style.left=r.x-t.mouseOffset.x+f-(o>61?2:0)+"px",t.dragObject=i,$(t.dragObject).addClass("dragging"),!0},onMouseUp:function(n){var t=n.data,u=t.boardWrapper,e=u.boardRenderer.gui,i,r,f;if(e.BoardDisabled)return!1;if(t.dragObject==null)return!0;if(i=t.getSquareCoords(n),!$(t.dragObject.parentNode).hasClass("start"))t.onDrop(i);if(r=t.dragFromCoords,i!=null&&r!=null&&!(i.x==r.x&&i.y==r.y)){t.onMovePiece(r,i);PubSub.publish("update-fen");history.state?history.state.currentFen?history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:u.boardRenderer.board.currentFEN(!0)},null,location.pathname):(f=history.state,history.pushState({probe:f.probe,tree:f.tree,currentFen:u.boardRenderer.board.currentFEN(!0)},null,location.pathname)):history.pushState({probe:null,tree:null,currentFen:u.boardRenderer.board.currentFEN(!0)},null,location.pathname)}return t.dragObject&&(t.dragObject.style.position="static",t.dragObject.style.top="auto",t.dragObject.style.left="auto",$(t.dragObject).removeClass("dragging")),$(t.dragObject.parentNode).hasClass("start")||(t.dropTargets=[],t.dragObject=null,$(".start").removeClass("start")),!0}}),smtbSetupPositionBehavior=smtbDragPiecesBehavior.extend({pieceSelector:null,selectorDragObject:null,justShifted:!1,deletedDown:!1,constructor:function(n){this.base();this.pieceSelector=n;var t=["king","queen","bishop","knight","rook","pawn"],i=["white","black"];for(color in i)for(piece in t)$(this.pieceSelector).append('<div style="width: 50px; border: 1px solid transparent; float: left;"><div style="float:left;" class="piece '+i[color].charAt(0)+t[piece]+'" data-name="'+t[piece]+'" data-color="'+i[color]+'"><\/div><\/div>'),t[piece]=="pawn"&&i[color]=="white"&&$(this.pieceSelector).append('<div class="clear"><\/div>');$(this.pieceSelector).append("")},initialize:function(n){this.base(n);var t=this.boardWrapper.mouseBehavior;$("#board-shift-left").mousedown(t,t.shiftAllLeft);$("#board-shift-up").mousedown(t,t.shiftAllUp);$("#board-shift-down").mousedown(t,t.shiftAllDown);$("#board-shift-right").mousedown(t,t.shiftAllRight);n.onBoardDraw=this.setupRemoveButtons;n.onBoardDraw()},remove:function(){this.boardWrapper.onBoardDraw=null;this.base()},setupRemoveButtons:function(){var n=this.mouseBehavior;$(this).find(".piece:not([data-dragdrop]):visible").each(function(){if(this.childNodes[0]&&this.childNodes[0].className=="remove-piece")this.childNodes[0]&&this.childNodes[0].className=="remove-piece"&&this.childNodes[0].style.display=="none"&&!this.parentNode.className.match(/start/)&&(this.childNodes[0].style.display="");else{var t=document.createElement("a");t.className="remove-piece";t.setAttribute("href","javascript:void(0);");$(t).mousedown(n,n.onRemoveButtonMouseDown);$(this).append($(t))}});$("#cancel-select").mousedown(n,n.onCancelSelectMouseDown)},onRemoveButtonMouseDown:function(n){var t,i,r;return(n.which==1||n.which==2)&&(t=n.handleObj.data,t&&(i=t.getSquareCoords(n),t.removePiece(i.x,i.y)),PubSub.publish("update-fen")),history.state?history.state.currentFen?history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname):(r=history.state,history.pushState({probe:r.probe,tree:r.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname)):history.pushState({probe:null,tree:null,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname),n.data.deletedDown=!0,!1},onCancelSelectMouseDown:function(n){if(n.which==1||n.which==2){var t=n.handleObj.data;t&&t.dragObject&&(t.dragObject=null,$(".start").removeClass("start"),t.onDrop())}return!1},shiftAllLeft:function(n){var o=n.data,h,e,f,i,u,s;if(o.justShifted)return!1;o.justShifted=!0;var c=n.data.boardWrapper,t=n.data.boardWrapper.board,r=n.data.boardWrapper.board.squares;for(i=t.pieces.length-1;i>=0;i--)h=t.pieces[i],e=h.square,e&&(t.pieces[i].square=e.x=="a"?r.h[e.y]:r[t.letters[t.letter[e.x]-1]][e.y]);for(f=0;f<t.pieces.length;f++)t.pieces[f].square&&(r[t.pieces[f].square.x][t.pieces[f].square.y].piece=t.pieces[f]);for(i=1;i<t.letters.length;i++)for(u=1;u<t.numbers.length;u++)r[t.letters[i]][t.numbers[u]].piece&&r[t.letters[i]][t.numbers[u]].piece.square.x!=r[t.letters[i]][t.numbers[u]].x&&r[t.letters[i]][t.numbers[u]].piece.square.y==r[t.letters[i]][t.numbers[u]].y&&(r[t.letters[i]][t.numbers[u]].piece=null);c.boardRenderer.gui.drawBoardPosition();history.state?history.state.currentFen?history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname):(s=history.state,history.pushState({probe:s.probe,tree:s.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname)):history.pushState({probe:null,tree:null,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname);PubSub.publish("update-fen");o.justShifted=!1},shiftAllUp:function(n){var o=n.data,h,e,f,i,u,s;if(o.justShifted)return!1;o.justShifted=!0;var c=n.data.boardWrapper,t=n.data.boardWrapper.board,r=n.data.boardWrapper.board.squares;for(i=t.pieces.length-1;i>=0;i--)h=t.pieces[i],e=h.square,e&&(t.pieces[i].square=e.y==8?r[e.x][1]:r[e.x][e.y+1]);for(f=0;f<t.pieces.length;f++)t.pieces[f].square&&(r[t.pieces[f].square.x][t.pieces[f].square.y].piece=t.pieces[f]);for(i=1;i<t.letters.length;i++)for(u=1;u<t.numbers.length;u++)r[t.letters[i]][t.numbers[u]].piece&&r[t.letters[i]][t.numbers[u]].piece.square.x==r[t.letters[i]][t.numbers[u]].x&&r[t.letters[i]][t.numbers[u]].piece.square.y!=r[t.letters[i]][t.numbers[u]].y&&(r[t.letters[i]][t.numbers[u]].piece=null);c.boardRenderer.gui.drawBoardPosition();history.state?history.state.currentFen?history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname):(s=history.state,history.pushState({probe:s.probe,tree:s.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname)):history.pushState({probe:null,tree:null,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname);PubSub.publish("update-fen");o.justShifted=!1},shiftAllDown:function(n){var o=n.data,h,e,f,i,u,s;if(o.justShifted)return!1;o.justShifted=!0;var c=n.data.boardWrapper,t=n.data.boardWrapper.board,r=n.data.boardWrapper.board.squares;for(i=t.pieces.length-1;i>=0;i--)h=t.pieces[i],e=h.square,e&&(t.pieces[i].square=e.y==1?r[e.x][8]:r[e.x][e.y-1]);for(f=0;f<t.pieces.length;f++)t.pieces[f].square&&(r[t.pieces[f].square.x][t.pieces[f].square.y].piece=t.pieces[f]);for(i=1;i<t.letters.length;i++)for(u=1;u<t.numbers.length;u++)r[t.letters[i]][t.numbers[u]].piece&&r[t.letters[i]][t.numbers[u]].piece.square.x==r[t.letters[i]][t.numbers[u]].x&&r[t.letters[i]][t.numbers[u]].piece.square.y!=r[t.letters[i]][t.numbers[u]].y&&(r[t.letters[i]][t.numbers[u]].piece=null);c.boardRenderer.gui.drawBoardPosition();history.state?history.state.currentFen?history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname):(s=history.state,history.pushState({probe:s.probe,tree:s.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname)):history.pushState({probe:null,tree:null,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname);PubSub.publish("update-fen");o.justShifted=!1},shiftAllRight:function(n){var o=n.data,h,e,f,i,u,s;if(o.justShifted)return!1;o.justShifted=!0;var c=n.data.boardWrapper,t=n.data.boardWrapper.board,r=n.data.boardWrapper.board.squares;for(i=t.pieces.length-1;i>=0;i--)h=t.pieces[i],e=h.square,e&&(t.pieces[i].square=e.x=="h"?r.a[e.y]:r[t.letters[t.letter[e.x]+1]][e.y]);for(f=0;f<t.pieces.length;f++)t.pieces[f].square&&(r[t.pieces[f].square.x][t.pieces[f].square.y].piece=t.pieces[f]);for(i=1;i<t.letters.length;i++)for(u=1;u<t.numbers.length;u++)r[t.letters[i]][t.numbers[u]].piece&&r[t.letters[i]][t.numbers[u]].piece.square.x!=r[t.letters[i]][t.numbers[u]].x&&r[t.letters[i]][t.numbers[u]].piece.square.y==r[t.letters[i]][t.numbers[u]].y&&(r[t.letters[i]][t.numbers[u]].piece=null);c.boardRenderer.gui.drawBoardPosition();history.state?history.state.currentFen?history.replaceState({probe:history.state.probe,tree:history.state.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname):(s=history.state,history.pushState({probe:s.probe,tree:s.tree,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname)):history.pushState({probe:null,tree:null,currentFen:n.data.boardWrapper.boardRenderer.board.currentFEN(!0)},null,location.pathname);PubSub.publish("update-fen");o.justShifted=!1},removePiece:function(n,t){return this.boardWrapper.board.removePiece(n,t),this.boardWrapper.boardRenderer.gui.drawBoardPosition(),!1},onDrag:function(n){var t=this,r=t.boardWrapper.boardRenderer.gui.getPieceElement(n.x,n.y),i=$(r).find(".remove-piece");return i&&i.hide(),$(this).find("td.white, td.black").each(function(){t.dropTargets.push(this)}),!0},onDrop:function(n){var i=this,r,t;return n?(r=i.boardWrapper.boardRenderer.gui.getPieceElement(n.x,n.y),t=$(r).find(".remove-piece"),t&&t.show()):i.boardWrapper.onBoardDraw(),this.base(n)},onMovePiece:function(n,t){var i=this.boardWrapper.board.squares,r=i[n.x][n.y].piece,e=i[t.x][t.y].piece,f,o,s,u;if(n.x!="i"&&n.x!="j"&&t.x!="i"&&t.x!="j")i[n.x][n.y].piece=e,i[t.x][t.y].piece=r,r.square=i[t.x][t.y],e&&(e.square=i[n.x][n.y]),i[n.x][n.y].piece&&(i[n.x][n.y].piece.square=null,i[n.x][n.y].piece=null);else if((n.x=="i"||n.x=="j")&&t.x!="i"&&t.x!="j")if(e){for(f=0;f<this.boardWrapper.board.pieces.length;f++)if(o=this.boardWrapper.board.pieces[f],s=this.boardWrapper.board.pieces[f].square,o==i[t.x][t.y].piece&&s==i[t.x][t.y].piece.square){this.boardWrapper.board.pieces.splice(this.boardWrapper.board.pieces.indexOf(this.boardWrapper.board.pieces[f]),1);this.removePiece(t.x,t.y);u=new boardPiece(r.name,r.color);i[t.x][t.y].piece=u;u.square=i[t.x][t.y];this.boardWrapper.boardRenderer.gui.addPiece(t.x,t.y,r.name,r.color);this.boardWrapper.board.pieces.push(u);break}}else u=new boardPiece(r.name,r.color),i[t.x][t.y].piece=u,u.square=i[t.x][t.y],this.boardWrapper.boardRenderer.gui.addPiece(t.x,t.y,r.name,r.color),this.boardWrapper.board.pieces.push(u);return this.boardWrapper.boardRenderer.gui.drawBoardPosition(),!1},onMouseDown:function(n){var i,t;return(window.getSelection().removeAllRanges(),i=n.data,this.dragFromCoords=i.getSquareCoords(n),this.dragFromCoords==null)?!0:(t=this.boardRenderer.gui.getGUISquare(this.dragFromCoords.x,this.dragFromCoords.y).children[0],!t)?!1:($(t).attr("data-original-z-index",t.style["z-index"]),t.style["z-index"]=5,this.base(n))},onMouseUp:function(n){var t=n.data,i=t.boardWrapper.boardRenderer.gui;return i.BoardDisabled?!1:t.dragObject==null?!0:(t.dragObject.style["z-index"]=$(t.selectorDragObject).attr("data-original-z-index"),$(t.dragObject).removeAttr("data-original-z-index"),this.base(n))}}),smtbTwoClickAndDragBehavior=smtbSetupPositionBehavior.extend({twoClicksDrag:!1,originalOnSelectStart:undefined,onMovePieceCalled:!0,initialize:function(n){this.base(n)},remove:function(){this.base()},onMouseMove:function(n){return this.base(n)},onMouseDown:function(n){var t=n.data,i=t.premoveFromCoords||t.dragFromCoords,r=t.getSquareCoords(n);return(i&&r&&(i.x=="i"||i.x=="j")&&(r.x=="i"||r.x=="j")&&(t.dragObject=null),t.dragObject)?!0:this.base(n)},onMouseUp:function(n){var t=n.data,o=t.boardWrapper,f=o.gui,r,e,i,u;return f&&f.BoardDisabled?!1:(r=t.getSquareCoords(n),t.deletedDown)?(t.deletedDown=!1,!0):t.dragObject==null?!0:(e=t.dragObject,i=t.premoveFromCoords||t.dragFromCoords,t.premoveFromCoords=null,!i)?!1:(t.isMadeMove=!1,r!=null)?(t.twoClicksDrag=!1,r.x==i.x&&r.y==i.y?(u=$(t.dragObject.parentNode),u.hasClass("start")?(u.removeClass("start"),t.isMadeMove=!0,this.base(n)):($(".start").removeClass("start"),u.addClass("start"),t.twoClicksDrag=!0,this.base(n))):$(t.dragObject).hasClass("dragging")?($(".start").removeClass("start"),this.base(n)):(i.x!="i"&&i.x!="j"&&$(t.dragObject.parentNode).removeClass("start"),t.isMadeMove=!0,this.base(n))):e?(t.twoClicksDrag&&$(".start").removeClass("start"),this.base(n)):!0},onBoardDraw:function(n){if(n)return!0;this.possibleMoveSquares=[];this.twoClicksDrag=!1;this.boardWrapper.gui.removeControlled()}});(function(n,t,i){"use strict";var r=typeof module=="object"&&typeof require=="function";r?module.exports=i(n,t):typeof define=="function"&&typeof define.amd=="object"?define(i):t[n]=i(n,t)})("PubSub",typeof window!="undefined"&&window||this,function(){"use strict";function f(n){return function(){throw n;}}function e(n,t,i){try{n(t,i)}catch(r){setTimeout(f(r),0)}}function i(t,i,r){var f=n[i],u,o;if(n.hasOwnProperty(i))for(u=0,o=f.length;u<o;u++)e(f[u].func,t,r)}function o(n,t){return function(){var r=String(n),u=r.lastIndexOf(".");for(i(n,n,t);u!==-1;)r=r.substr(0,u),u=r.lastIndexOf("."),i(n,r,t)}}function s(t){for(var i=String(t),r=n.hasOwnProperty(i),u=i.lastIndexOf(".");!r&&u!==-1;)i=i.substr(0,u),u=i.lastIndexOf("."),r=n.hasOwnProperty(i);return r}function r(n,t,i){var r=o(n,t),u=s(n);return u?(i===!0?r():setTimeout(r,0),!0):!1}var t={name:"PubSubJS",version:"1.3.2-dev"},n={},u=-1;return t.publish=function(n,t){return r(n,t,!1)},t.publishSync=function(n,t){return r(n,t,!0)},t.subscribe=function(t,i){n.hasOwnProperty(t)||(n[t]=[]);var r=String(++u);return n[t].push({token:r,func:i}),r},t.unsubscribe=function(t){var u=typeof t=="string",e=u?"token":"func",o=u?t:!0,f=!1,i,r;for(i in n)if(n.hasOwnProperty(i))for(r=n[i].length-1;r>=0;r--)if(n[i][r][e]===t&&(n[i].splice(r,1),f=o,u))return f;return f},t})