var DHTMLGoodies={};if(!String.trim)String.prototype.trim=function(){return this.replace(/^\s+|\s+$/,"")};var D_chessObjects=[],ChessWidgetEventFuncs={};DHTMLGoodies.ChessPgn=function(a){this.pgnTimeStamps={};this.gameDetails=[];this.cachedGameList={};this.numberOfGames={};this.serverFile="chess.php";this.ajaxObjects=[];a&&this.__setInitialProperties(a);this.objectIndex=D_chessObjects.length;D_chessObjects[this.objectIndex]=this};
DHTMLGoodies.ChessPgn.prototype={__setInitialProperties:function(a){if(a.pgnFile)this.pgnFile=a.pgnFile;if(a.serverFile)this.serverFile=a.serverFile},__getGameDetails:function(a,b,c){if(this.gameDetails[a]&&!c)this.__returnGameDetailsFromCache(a,b);else{var d=this.objectIndex,e=this.ajaxObjects.length;this.ajaxObjects[e]=new sack;this.ajaxObjects[e].method="GET";this.ajaxObjects[e].requestFile=this.serverFile;this.ajaxObjects[e].setVar("getGameDetails","1");this.ajaxObjects[e].setVar("pgnFile",this.pgnFile);
this.ajaxObjects[e].setVar("gameIndex",a);this.ajaxObjects[e].setVar("liveUpdateMode",c?"1":"0");if(!this.pgnTimeStamps[this.pgnFile+"_"+a]||!this.gameDetails[a])this.pgnTimeStamps[this.pgnFile+"_"+a]=0;this.ajaxObjects[e].setVar("timestamp",this.pgnTimeStamps[this.pgnFile+"_"+a]);this.ajaxObjects[e].onCompletion=function(){D_chessObjects[d].__returnGameDetails(a,e,b)};this.ajaxObjects[e].onError=function(){D_chessObjects[d].__ajaxError()};this.ajaxObjects[e].runAJAX()}},__isNumberOfGamesSet:function(){return this.numberOfGames[this.pgnFile]?
true:false},__getNumberOfGames:function(){return this.numberOfGames[this.pgnFile]},__getNumberOfGamesFromServer:function(a){if(this.numberOfGames[this.pgnFile])this.__returnNumberOfGamesFromCache(a);else{var b=this.objectIndex,c=this.ajaxObjects.length;this.ajaxObjects[c]=new sack;this.ajaxObjects[c].method="GET";this.ajaxObjects[c].requestFile=this.serverFile;this.ajaxObjects[c].setVar("getNumberOfGames","1");this.ajaxObjects[c].setVar("pgnFile",this.pgnFile);this.ajaxObjects[c].onCompletion=function(){D_chessObjects[b].__returnNumberOfGames(c,
a)};this.ajaxObjects[c].onError=function(){this.__ajaxError()};this.ajaxObjects[c].runAJAX()}},__returnNumberOfGames:function(a,b){this.numberOfGames[this.pgnFile]=this.ajaxObjects[a].response;eval(b+"("+this.ajaxObjects[a].response+")")},__returnNumberOfGamesFromCache:function(a){eval(a+"("+this.numberOfGames[this.pgnFile]+")")},__returnGameDetails:function(a,b,c){try{var d=eval("("+this.ajaxObjects[b].response+")");if(!d.result)d.result="*"}catch(e){self.status="Error in returned JSON string";return}if(d){this.gameDetails[a]=
d;this.__setPgnTimestamp(a);if(c.indexOf("(")>=0){c=c.replace(")","");eval(c+",this.gameDetails["+a+"])")}else eval(c+"(this.gameDetails["+a+"])")}else eval(c+"(false)")},__setPgnTimestamp:function(a){this.pgnTimeStamps[this.pgnFile+"_"+a]=Math.floor((new Date).getTime()/1E3)},__returnGameDetailsFromCache:function(a,b){if(b.indexOf("(")>=0){b=b.replace(")","");eval(b+",this.gameDetails["+a+"])")}else eval(b+"(this.gameDetails["+a+"])")},__getGameList:function(a){if(this.cachedGameList[this.pgnFile])this.__returnGameListFromCache(a);
else{var b=this.objectIndex,c=this.ajaxObjects.length;this.ajaxObjects[c]=new sack;this.ajaxObjects[c].method="GET";this.ajaxObjects[c].requestFile=this.serverFile;this.ajaxObjects[c].setVar("getGameList","1");this.ajaxObjects[c].setVar("pgnFile",this.pgnFile);this.ajaxObjects[c].onCompletion=function(){D_chessObjects[b].__returnGameList(c,a)};this.ajaxObjects[c].onError=function(){D_chessObjects[b].__ajaxError()};this.ajaxObjects[c].runAJAX()}},__returnGameList:function(a,b){this.cachedGameList[this.pgnFile]=
this.ajaxObjects[a].response;if(b.indexOf("(")>=0){b=b.replace(")","");eval(b+",this.ajaxObjects["+a+"].response)")}else eval(b+"(this.ajaxObjects["+a+"].response)")},__returnGameListFromCache:function(a){if(a.indexOf("(")>=0){a=a.replace(")","");eval(a+",this.cachedGameList[this.pgnFile])")}else eval(a+"(this.cachedGameList[this.pgnFile])")},__ajaxError:function(){alert("Could not complete ajax request for "+this.pgnFile)},__setPgnFile:function(a){this.gameList=[];this.gameDetails=[];this.pgnFile=
a}};
DHTMLGoodies.Chess=function(a){this.dataForLiveUpdate={};this.dragAndDropColor=false;this.eventElements=[];this.slideCoordinates=[];this.dragProperties={};this.animationSpeed=1;this.liveUpdateInterval=0;this.elMovesInTable=[];this.languageCode="en";this.officers={};this.officers.en=["B","R","Q","N","K"];this.officers.no=["L","T","D","S","K"];this.currentMoveNumber=1;this.divIndicators={};this.chessSet="alpha";this.squareSize=60;this.elMovesInTableMaxMovesPerTable=900;this.keyboardSupport=true;this.isOldMSIE=
navigator.userAgent.toLowerCase().match(/msie\s[0-6]/gi)?true:false;this.isMSIE=navigator.userAgent.toLowerCase().indexOf("msie")>=0?true:false;this.isOpera=navigator.userAgent.toLowerCase().indexOf("opera")>=0?true:false;this.isFirefox=navigator.userAgent.toLowerCase().indexOf("firefox")>=0?true:false;this.elGameAttributes={};this.stopAutoplayBeforeComments=false;this.displayPrefaceCommentWithInlineMoves=true;this.currentGameIndex=false;this.animationSetTimeout=13;this.insideVariation=false;this.indicateLastMove=
true;this.coordLastMove={};this.coordLastMove.from={};this.coordLastMove.to={};this.animate=true;this.cssPath="css/chess.css";this.parentRef=document.body;this.imageFolder="images/";this.flipBoardWhenBlackWins=this.flipBoardWhenBlackToStart=this.boardLabels=true;this.isBusy=this.animateNextMove=this.flipBoard=false;this.currentZIndex=2E4;this.lastMoveEnPassant=false;this.autoPlayDelayBetweenMoves=0.5;this.autoPlayActive=false;this.gameListProperties={};this.objectIndex=D_chessObjects.length;this.sound=
false;D_chessObjects[this.objectIndex]=this;a&&this.__setInitProps(a);this.pgnObject=new DHTMLGoodies.ChessPgn(a);this.__init()};
DHTMLGoodies.Chess.prototype={setAutoPlayDelayBetweenMoves:function(a){if(a<0.1)a=0.1;this.autoPlayDelayBetweenMoves=a},setDragAndDropColor:function(a){this.dragAndDropColor=a},setPgn:function(a){if(!(this.isBusy||this.autoPlayActive)){this.currentGameIndex=false;this.__clearGameDetails();this.__clearCurrentVariationVariables();this.pgnObject.__setPgnFile(a);this.__handleCallback("switchPgn")}},__displayActivePgnFileProperty:function(){if(this.elActivePgnFile)try{this.elActivePgnFile.innerHTML=this.pgnObject.pgnFile.replace(/^.*\/(.*)$/g,
"$1")}catch(a){}},setSquareSize:function(a){if(!(this.isBusy||this.autoPlayActive)){var b=this.currentMove,c=this.currentColor;this.squareSize=a;this.__clearBoard();if(this.currentGameIndex===false)this.__createDefaultPieces();else{this.parentRef.className="ChessBoardParentContainer"+a;try{this.parentRef.parentNode.className=" ChessBoardParentOfParentContainer"+a}catch(d){}this.pgnObject.gameDetails[this.currentGameIndex].fen?this.displayBoardByFen(this.pgnObject.gameDetails[this.currentGameIndex].fen,
this.parentRef):this.__createDefaultPieces();if(this.insideVariation)this.goToVariationMove(this.currentVariationMove,this.currentVariationColor,this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex);else{if(b==0)this.currentMove=0;b>0&&this.goToMove(b,c)}this.__createIndicators();this.__indicateLastMove()}}},setChessSet:function(a){if(!(this.isBusy||this.autoPlayActive)){this.chessSet=a;a=this.currentMove;var b=this.currentColor;this.__clearBoard();if(this.currentGameIndex===
false)this.__createDefaultPieces();else{this.pgnObject.gameDetails[this.currentGameIndex].fen?this.displayBoardByFen(this.pgnObject.gameDetails[this.currentGameIndex].fen,this.parentRef):this.__createDefaultPieces();if(this.insideVariation)this.goToVariationMove(this.currentVariationMove,this.currentVariationColor,this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex);else{if(a==0)this.currentMove=0;a>0&&this.goToMove(a,b)}}}},flip:function(){if(!(this.isBusy||this.autoPlayActive)){this.flipBoard=
this.flipBoard?false:true;var a=this.currentMove,b=this.currentColor;this.__clearBoard();if(this.currentGameIndex===false)this.__createDefaultPieces();else{this.pgnObject.gameDetails[this.currentGameIndex].fen?this.displayBoardByFen(this.pgnObject.gameDetails[this.currentGameIndex].fen,this.parentRef):this.__createDefaultPieces();if(this.insideVariation)this.goToVariationMove(this.currentVariationMove,this.currentVariationColor,this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex);
else{if(a==0)this.currentMove=0;a>0&&this.goToMove(a,b)}}}},getNextMove:function(){return this.__getNextMove().notation},getNextMoveGer:function(){var a=this.__getNextMove();a.notation=a.notation.replace(/N([a-h]*[1-8]*x*[a-h]+[1-8]+)/g,"S$1");a.notation=a.notation.replace(/B([a-h]*[1-8]*x*[a-h]+[1-8]+)/g,"L$1");a.notation=a.notation.replace(/R([a-h]*[1-8]*x*[a-h]+[1-8]+)/g,"T$1");a.notation=a.notation.replace(/Q([a-h]*[1-8]*x*[a-h]+[1-8]+)/g,"D$1");return a.notation},getResult:function(){if(this.currentGameIndex===
false)return false;if(!this.pgnObject.gameDetails[this.currentGameIndex].result)return false;return this.pgnObject.gameDetails[this.currentGameIndex].result.trim()},getPgnFile:function(){return this.pgnObject.pgnFile},getStartColor:function(){return this.whoToStartMove=="w"?"white":"black"},__init:function(){this.__loadCss(this.cssPath);this.__addSoundEffects();this.__addGeneralEvents();this.__createLiveUpdateHandler();this.__addKeyboardSupport()},setFlipBoardWhenBlackToStart:function(a){this.flipBoardWhenBlackToStart=
a},setFlipBoardWhenBlackWins:function(a){this.flipBoardWhenBlackWins=a},getCurrentFen:function(){},getCurrentGameIndex:function(){return this.currentGameIndex},showRandomGame:function(){if(this.pgnObject.__isNumberOfGamesSet()){var a=this.pgnObject.__getNumberOfGames();return this.showGame(Math.floor(Math.random()*a))}else this.pgnObject.__getNumberOfGamesFromServer("D_chessObjects["+this.objectIndex+"].__showRandomGame")},__showRandomGame:function(a){a&&this.showRandomGame()},showGame:function(a){this.__handleCallback("beforeGameLoad");
this.currentGameIndex=a;this.__clearCurrentVariationVariables();this.__clearDragProperties();var b=this.objectIndex;this.dataForLiveUpdate.liveUpdateGameIndexBefore=this.currentGameIndex;this.pgnObject.__getGameDetails(a,"D_chessObjects["+b+"].__showGame",false);return a},__addKeyboardSupport:function(){if(this.keyboardSupport){var a=this.objectIndex;document.documentElement.onkeydown=function(b){return D_chessObjects[a].__handleKeyboard(b)}}},__handleKeyboard:function(a){if(document.all)a=event;
if(a.keyCode==39||a.keyCode==102){this.move(1);return false}if(a.keyCode==37||a.keyCode==100){this.move(-1);return false}a.ctrlKey&&a.shiftKey&&a.keyCode==70&&this.flip()},__getNewGameData:function(){if(!(this.isBusy||this.autoPlayActive||this.isBusyWithLiveUpdate))if(this.currentGameIndex!==false){this.isBusyWithLiveUpdate=true;var a=this.__getLastMove();this.dataForLiveUpdate.moveAfterLiveUpdate=false;this.dataForLiveUpdate.moveAfterLiveUpdate=false;this.dataForLiveUpdate.lastMoveBeforeUpdate=this.__getLastPlayedMove();
this.dataForLiveUpdate.liveUpdateGameIndexBefore=this.currentGameIndex;if(this.currentMove==a.move&&this.currentColor==a.color)this.dataForLiveUpdate.moveAfterLiveUpdate=true;if(a.move==0)this.dataForLiveUpdate.moveAfterLiveUpdate=true;this.pgnObject.__getGameDetails(this.currentGameIndex,"D_chessObjects["+this.objectIndex+"].__receiveLiveGameUpdate",true)}},__receiveLiveGameUpdate:function(a){this.isBusyWithLiveUpdate=false;if(a)if(this.dataForLiveUpdate.liveUpdateGameIndexBefore==this.currentGameIndex){a=
this.__getLastMove();var b=this.__getLastPlayedMove();this.__displayGameDetails();if(b.move!=this.dataForLiveUpdate.lastMoveBeforeUpdate.move||b.color!=this.dataForLiveUpdate.lastMoveBeforeUpdate.color)this.dataForLiveUpdate.moveAfterLiveUpdate=false;if(b.move>a.move||b.move==a.move&&a.color=="white"&&b.color=="black"){this.__clearBoard();this.__createDefaultPieces();this.goToMove(a.move,a.color)}else this.goToMove(this.dataForLiveUpdate.lastMoveBeforeUpdate.move,this.dataForLiveUpdate.lastMoveBeforeUpdate.color);
this.__highlightActiveMove(this.currentMove,this.currentColor);this.dataForLiveUpdate.moveAfterLiveUpdate&&this.autoPlay()}},displayGameListInSelect:function(a){if(!(this.isBusy||this.autoPlayActive)){this.pgnObject.__getGameList("D_chessObjects["+this.objectIndex+'].__displayGameListInSelect("'+a+'")');this.__displayActivePgnFileProperty()}},__displayGameListInSelect:function(a,b){a=this.__getEl(a);a.setAttribute("objectIndex",this.objectIndex);a.onchange=this.__showGameFromSelect;this.__addEventEl(a);
a.options.length=0;try{var c=eval("("+b+")")}catch(d){alert(b)}for(var e in c)a.options[a.options.length]=new Option(c[e].white+" vs. "+c[e].black,e)},__showGameFromSelect:function(){var a=this.getAttribute("objectIndex");D_chessObjects[a].showGame(this.options[this.selectedIndex].value)},displayGameListInTable:function(a,b,c){if(!(this.isBusy||this.autoPlayActive)){if(b&&!this.__isArray(b))b=b.split(/,/g);a=this.__getEl(a);this.__clearTBodyRows(a);var d=this.objectIndex,e="";b||(b=["view","white",
"black","result"]);for(var f=0;f<b.length;f++){e=f==0?"[":e+",";e=e+'"'+b[f]+'"'}if(e)e+="]";if(c)this.gameListProperties=c;this.pgnObject.__getGameList("D_chessObjects["+d+'].__displayGameListInTable("'+a.id+'",'+e+")");this.__displayActivePgnFileProperty()}},__displayGameListInTable:function(a,b,c){a=this.__getEl(a);var d=this.objectIndex;try{var e=eval("("+c+")")}catch(f){alert(c)}a.deleteTHead();this.__clearTBodyRows(a);if(a.getElementsByTagName("tbody")[0]){(new Date).getTime();c="GameListOddRow";
for(var h="<tr><th>Nr.</th><th>Weiss</th><th>Schwarz</th><th>Erg.</th><tr>",g='<tr id="ChessGameList<ID>" class="<CLASSNAME>">',i=0;i<b.length;i++)for(i=0;i<b.length;i++)g=b[i]=="view"?g+'<td><a href="#" id="game<ID>" onclick="D_chessObjects['+d+'].showGame(<ID>);return false"><ID2>.</a></td>':g+'<td><a href="#" onclick="D_chessObjects['+d+'].showGame(<ID>);return false"><PROPERTY_'+b[i]+"></a></td>";g+="</tr>";for(var j in e){c=c=="GameListOddRow"?"GameListEvenRow":"GameListOddRow";d=g;d=g.replace(/<ID>/g,
j);d=d.replace(/<ID2>/g,j);d=d.replace(/<CLASSNAME>/g,c);i=this.gameListProperties.viewGameLink;if(i=="gameNumber")i=j/1+1+"";d=d.replace("<PROPERTY_view>",i);for(i=0;i<b.length;i++)d=d.replace("<PROPERTY_"+b[i]+">",e[j][b[i]]);h+=d}this.__replaceTbody(h,a);setFilterGrid("gameListTable",gamefilter);(new Date).getTime()}else alert("Your game list table is missing a <tbody> element. Please insert it")},__showGame:function(a){if(this.dataForLiveUpdate.liveUpdateGameIndexBefore==this.currentGameIndex){this.flipBoard=
false;this.stopAutoPlay();if(a.fen){this.__setWhoToMoveFromFen(a.fen);if(this.whoToStartMove=="b"&&this.flipBoardWhenBlackToStart)this.flipBoard=true;this.__clearBoard();this.displayBoardByFen(a.fen,this.parentRef)}else{this.__setWhoToMoveFromResult(a.fen);if(this.whoToStartMove=="b"&&this.flipBoardWhenBlackWins)this.flipBoard=true;this.__clearBoard();this.__createDefaultPieces()}this.currentMove=0;this.currentColor=this.whoToStartMove=="w";this.__clearDisplayedActiveMove();this.__highlightActiveGame();
this.__displayGameDetails();this.__handleCallback("startGame")}},__clearGameDetails:function(){this.__clearMoveDetails();for(var a in this.elGameAttributes)try{this.__getEl(this.elGameAttributes[a]).innerHTML=""}catch(b){}if(this.elPlayerNames)this.elPlayerNames.innerHTML=""},__displayGameDetails:function(){this.__clearGameDetails();this.__displayMoveDetails();var a=this.pgnObject.gameDetails[this.currentGameIndex];for(var b in this.elGameAttributes)if(a[b.toLowerCase()])try{this.__getEl(this.elGameAttributes[b]).innerHTML=
a[b.toLowerCase()]}catch(c){}if(this.elPlayerNames)this.elPlayerNames.innerHTML=this.pgnObject.gameDetails[this.currentGameIndex].white+" vs. "+this.pgnObject.gameDetails[this.currentGameIndex].black},__highlightActiveGame:function(){if(this.currentHighlightedGame)this.currentHighlightedGame.className=this.previousClassHighlighedGame;if(document.getElementById("ChessGameList"+this.currentGameIndex)){this.currentHighlightedGame=document.getElementById("ChessGameList"+this.currentGameIndex);if(this.currentHighlightedGame.className!=
"ActiveGameInTable")this.previousClassHighlighedGame=this.currentHighlightedGame.className;this.currentHighlightedGame.className="ActiveGameInTable"}},__clearMoveDetails:function(){if(this.elMovesInline)this.elMovesInline.innerHTML="";if(this.elMovesInTable)for(var a=0;a<this.elMovesInTable.length;a++)this.__clearTBodyRows(this.elMovesInTable[a])},__clearCurrentVariationVariables:function(){this.insideVariation=false;this.currentVariationMove=0;this.currentVariationColor="white";this.currentVariationMoveNumber=
false},__setStartVariationVariables:function(a,b,c){this.insideVariation={move:a,color:b,variationIndex:c};a=this.pgnObject.gameDetails[this.currentGameIndex].moves[a][b].variation[c];for(var d in a){this.currentVariationMoveNumber=d*2;this.currentVariationMove=d/1;this.currentVariationColor="white";if(!a[d].white){this.currentVariationMoveNumber++;this.currentVariationColor="black"}break}if(this.currentVariationColor=="black")this.currentVariationColor="white";else{this.currentVariationColor="black";
this.currentVariationMove--}},goToVariationMove:function(a,b,c,d,e){var f=c,h=d,g=a*2+(b=="black"?1:0);if(h=="black")h="white";else{h="black";f--}var i=this.animateNextMove;this.animateNextMove=false;if(this.insideVariation&&(this.insideVariation.move!=c||this.insideVariation.color!=d||this.insideVariation.variationIndex!=e)){this.goToMove(f,h);this.__clearCurrentVariationVariables();this.__setStartVariationVariables(c,d,e)}if(!this.insideVariation){this.goToMove(f,h);this.__setStartVariationVariables(c,
d,e)}if(this.insideVariation&&g<this.currentVariationMoveNumber){this.goToMove(f,h);this.__setStartVariationVariables(c,d,e)}this.animateNextMove=i;e=this.pgnObject.gameDetails[this.currentGameIndex].moves[c][d].variation[e];for(f=this.currentVariationMoveNumber;f<=g;f++){h=Math.floor(f/2);i=f%2==1?"black":"white";if(e[h][i]){this.__parseAMove(e[h][i],i);this.currentVariationMove=h;this.currentVariationColor=i;this.currentVariationMoveNumber=f}}this.currentVariationMoveNumber++;this.__indicateLastMove();
this.__highlightActiveVariationMove(a,b,c,d)},__getMoveDetailsForVariation:function(a,b,c){var d=this.objectIndex,e="";for(var f in a){var h=a[f],g="";for(var i in h){g=g?g+" ":"[";if(h[i].white){g=g+i+'. <a class="InlineVariationMove" href="#" id="InlineVariationMove_'+b+"_"+c+"_"+f+"_"+i+'_white" onclick="D_chessObjects['+d+"].goToVariationMove('"+i+"','white','"+b+"','"+c+"','"+f+"');return false\">"+this.__getAMoveInLanguage(h[i].white)+"</a>";if(h[i].black)g=g+' <a class="InlineVariationMove" href="#" id="InlineVariationMove_'+
b+"_"+c+"_"+f+"_"+i+'_black" onclick="D_chessObjects['+d+"].goToVariationMove('"+i+"','black','"+b+"','"+c+"','"+f+"');return false\">"+this.__getAMoveInLanguage(h[i].black)+"</a>"}else g=g+i+'... <a class="InlineVariationMove" href="#" id="InlineVariationMove_'+b+"_"+c+"_"+f+"_"+i+'_black" onclick="D_chessObjects['+d+"].goToVariationMove('"+i+"','black','"+b+"','"+c+"','"+f+"');return false\">"+this.__getAMoveInLanguage(h[i].black)+"</a>"}g+="] ";g=' <span class="InlineChessVariationBlock">'+g+"</span>";
e+=g}return e},__getClassNameOfInlineMove:function(a){var b="InlineChessMove_plainMove";if(a.indexOf("!")>=0)b="InlineChessMove_goodMove";if(a.indexOf("!!")>=0)b="InlineChessMove_veryGoodMove";if(a.indexOf("?")>=0)b="InlineChessMove_badMove";if(a.indexOf("??")>=0)b="InlineChessMove_veryBadMove";if(a.indexOf("!?")>=0)b="InlineChessMove_supriseMove";if(a.indexOf("?!")>=0)b="InlineChessMove_questionableMove";return b},__getAMoveInLanguage:function(a){if(this.languageCode=="en")return a;for(var b=0;b<
this.officers.en.length;b++)a=a.replace(this.officers.en[b],this.officers[this.languageCode][b]);return a},__displayMoveDetails:function(){this.__clearGameDetails();var a=this.pgnObject.gameDetails[this.currentGameIndex].moves,b=this.objectIndex;if(this.elMovesInline){var c="";if(this.pgnObject.gameDetails[this.currentGameIndex].prefaceComment&&this.displayPrefaceCommentWithInlineMoves)c=c+'<span class="InlineChessComment">'+this.pgnObject.gameDetails[this.currentGameIndex].prefaceComment+"</span> ";
for(var d in a){if(c)c+=" ";if(a[d].white){var e=this.__getClassNameOfInlineMove(a[d].white.move);c=c+d+'.<a class="'+e+'" id="InlineChessMove'+d+'white" href="#" onclick="D_chessObjects['+b+"].goToMove('"+d+"','white');return false\">"+this.__getAMoveInLanguage(a[d].white.move)+"</a>";if(a[d].white.comment)c=c+' <span class="InlineChessComment">'+a[d].white.comment+"</span> ";if(a[d].white.variation)c+=this.__getMoveDetailsForVariation(a[d].white.variation,d,"white");if(a[d].black){e=this.__getClassNameOfInlineMove(a[d].black.move);
c=c+' <a class="'+e+'" id="InlineChessMove'+d+'black" href="#" onclick="D_chessObjects['+b+"].goToMove('"+d+"','black');return false\">"+this.__getAMoveInLanguage(a[d].black.move)+"</a>";if(a[d].black.comment)c=c+' <span class="InlineChessComment">'+a[d].black.comment+"</span> ";if(a[d].black.variation)c+=this.__getMoveDetailsForVariation(a[d].black.variation,d,"black")}}else{e=this.__getClassNameOfInlineMove(a[d].black.move);c=c+d+' ...<a class="'+e+'" id="InlineChessMove'+d+'black" href="#" onclick="D_chessObjects['+
b+"].goToMove('"+d+"','black');return false\">"+this.__getAMoveInLanguage(a[d].black.move)+"</a>";if(a[d].black.comment)c=c+' <span class="InlineChessComment">'+a[d].black.comment+"</span> ";if(a[d].black.variation)c+=this.__getMoveDetailsForVariation(a[d].black.variation,d,"black")}}c=c+" "+this.pgnObject.gameDetails[this.currentGameIndex].result;this.elMovesInline.innerHTML=c}if(this.elMovesInTable[0])if(c=this.elMovesInTable[0].getElementsByTagName("TBODY")[0]){e=0;var f=1;for(d in a){if(f>this.elMovesInTableMaxMovesPerTable){e++;
f=1;c=this.elMovesInTable[e].getElementsByTagName("TBODY")[0]}var h=document.createElement("TR");c.appendChild(h);var g=document.createElement("TD");g.innerHTML=d;h.appendChild(g);if(a[d].white){g=document.createElement("TD");g.innerHTML='<a id="TableChessMove'+d+'white" href="#" onclick="D_chessObjects['+b+"].goToMove('"+d+"','white');return false\">"+this.__getAMoveInLanguage(a[d].white.move)+"</a>"}else{g=document.createElement("TD");g.innerHTML="..."}h.appendChild(g);if(a[d].black){g=document.createElement("TD");
g.innerHTML='<a id="TableChessMove'+d+'black" href="#" onclick="D_chessObjects['+b+"].goToMove('"+d+"','black');return false\">"+this.__getAMoveInLanguage(a[d].black.move)+"</a>";h.appendChild(g)}f++}}else alert("Cannot display moves inside a table because it is missing a <tbody> element")},__showGameLink:function(){var a=this.getAttribute("objectIndex");D_chessObjects[a].showGame(this.id.replace(/[^0-9]/g,""))},moveToStart:function(){if(!(this.currentGameIndex===false||this.isBusy))if(this.pgnObject.gameDetails[this.currentGameIndex].moves[1]){this.pgnObject.gameDetails[this.currentGameIndex].fen?
this.displayBoardByFen(this.pgnObject.gameDetails[this.currentGameIndex].fen,this.parentRef):this.__createDefaultPieces();if(this.insideVariation){var a=this.__getFirstVariationMove(this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex);this.goToVariationMove(a.move,a.color,this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex)}else{this.currentColor=this.currentMove=0;this.currentMoveNumber=1;a="white";this.pgnObject.gameDetails[this.currentGameIndex].moves[1].white||
(a="black");this.__highlightActiveMove(0,a);this.__displayActiveMove(1,a);this.__playSound("startGame")}}},moveToEnd:function(){if(!(this.currentGameIndex===false||this.isBusy))if(this.pgnObject.gameDetails[this.currentGameIndex].moves[1])if(this.insideVariation){var a=this.__getLastVariationMove(this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex);this.goToVariationMove(a.move,a.color,this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex)}else{a=
this.__getLastMove();this.goToMove(a.move,a.color)}},__getLastMove:function(){var a=this.pgnObject.gameDetails[this.currentGameIndex].moves,b=false;for(var c in a)b=c;if(b===false)return{move:0,color:"white"};c={};c.move=b;c.color=a[b].black?"black":"white";return c},__getFirstVariationMove:function(a,b,c){a=this.pgnObject.gameDetails[this.currentGameIndex].moves[a][b].variation[c];for(var d in a){lastMove=d;break}d={};d.move=lastMove;if(!lastMove)return"white";d.color=a[lastMove].black?"black":"white";
return d},__getLastVariationMove:function(a,b,c){a=this.pgnObject.gameDetails[this.currentGameIndex].moves[a][b].variation[c];for(var d in a)lastMove=d;d={};d.move=lastMove;if(!lastMove)return"white";d.color=a[lastMove].black?"black":"white";return d},move:function(a){if(!(this.currentGameIndex===false||this.isBusy))if(this.pgnObject.gameDetails[this.currentGameIndex].moves[1]){var b=Math.floor(Math.abs(a)/2),c=Math.abs(a)%2;if(this.insideVariation)var d=this.currentVariationColor,e=this.currentVariationMove;
else{d=this.currentColor;e=this.currentMove}if(a>0)if(c==1)if(d=="white")d="black";else{d="white";e++}if(a<0){b*=-1;if(c==1)if(d=="black")d="white";else{d="black";e--}}e+=b;if(this.insideVariation){if(e<=this.insideVariation.move){if(d=="white"&&this.insideVariation.color=="black")return;if(e<this.insideVariation.move)return}if(a>0)var f=this.__getLastVariationMove(this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex)}else{if(e<=0){this.moveToStart();this.__hideIndicators();
return}if(a>0)f=this.__getLastMove()}this.animateNextMove=false;if(this.animate&&a==1)this.animateNextMove=true;if(a>0)if(e>=f.move)if(e>f.move){e=f.move/1;d=f.color;this.animateNextMove=false;if(a==1)return}else{e=f.move/1;if(d=="black"&&f.color=="white"){d="white";this.animateNextMove=false}}if(this.insideVariation)a!=0&&this.goToVariationMove(e,d,this.insideVariation.move,this.insideVariation.color,this.insideVariation.variationIndex);else if(a!=0){if(a>0&&e==1&&d=="white"&&!this.pgnObject.gameDetails[this.currentGameIndex].moves[1].white)d=
"black";this.goToMove(e,d,a)}}},autoPlay:function(){if(!(this.autoPlayActive||this.currentGameIndex===false))if(this.pgnObject.gameDetails[this.currentGameIndex].moves[1]){this.autoPlayActive=true;var a=this.__getNextMove();this.__autoPlayStep(a.move,a.color)}},__autoPlayStep:function(a,b){if(this.insideVariation){var c=this.pgnObject.gameDetails[this.currentGameIndex].moves[this.insideVariation.move][this.insideVariation.color].variation[this.insideVariation.variationIndex];if(c[a]&&c[a][b])this.move(1);
else{this.stopAutoPlay();this.__handleCallback("stopAutoPlay")}}else if(this.pgnObject.gameDetails[this.currentGameIndex]&&this.pgnObject.gameDetails[this.currentGameIndex].moves[a]&&this.pgnObject.gameDetails[this.currentGameIndex].moves[a][b])this.move(1);else{this.stopAutoPlay();this.__handleCallback("stopAutoPlay")}},stopAutoPlay:function(){this.autoPlayActive=false},goToMove:function(a,b,c){if(this.currentGameIndex===false||this.isBusy||!a)this.__hideIndicators();else if(this.pgnObject.gameDetails[this.currentGameIndex].moves[1]){var d=
a*2+(b=="black"?1:0);if(d<this.currentMoveNumber||this.insideVariation){this.__clearBoard();this.pgnObject.gameDetails[this.currentGameIndex].fen?this.displayBoardByFen(this.pgnObject.gameDetails[this.currentGameIndex].fen,this.parentRef):this.__createDefaultPieces();this.currentColor=this.whoToStartMove}if(d!=this.currentMoveNumber-1){for(var e,f=this.currentMoveNumber;f<d;f++){e=f%2==1?"white":"black";var h=Math.ceil(f/2);if(f==d-1){this.__highlightActiveMove(h,e);this.__displayActiveMove(h,e)}this.pgnObject.gameDetails[this.currentGameIndex].moves[h]&&
this.pgnObject.gameDetails[this.currentGameIndex].moves[h][e]&&this.__parseAMove(this.pgnObject.gameDetails[this.currentGameIndex].moves[h][e].move,e)}d=true;if(c<0&&a==1){if(b=="white")d=false;if(b=="black"&&!this.pgnObject.gameDetails[this.currentGameIndex].moves[1].white)d=false}d&&this.__indicateLastMove();this.currentMoveNumber=a*2+(b=="black"?1:0);this.currentMove=a/1;this.currentColor=b;this.__clearCurrentVariationVariables();if(this.autoPlayActive&&!this.animate){this.__getNextMove();a=this.__getAutoPlayDelayBeforeNextMove();
this.stopAutoplayBeforeComments&&this.pgnObject.gameDetails[this.currentGameIndex].moves[this.currentMove][this.currentColor].comment?this.stopAutoPlay():setTimeout("D_chessObjects["+this.objectIndex+"].move(1)",a)}}}},__getAutoPlayDelayBeforeNextMove:function(){return this.autoplayDelayBeforeComments&&this.pgnObject.gameDetails[this.currentGameIndex].moves[this.currentMove][this.currentColor].comment?this.autoplayDelayBeforeComments*1E3:this.autoPlayDelayBetweenMoves*1E3},__highlightActiveMove:function(a,
b){if(this.currentHighlightInlineMove)try{var c=this.currentHighlightInlineMove.className.replace(" ActiveInlineChessMove","");c=c.replace(" ActiveInlineVariationChessMove","");c=c.trim();this.currentHighlightInlineMove.className=c}catch(d){}if(this.currentHighlightTableMove)try{this.currentHighlightTableMove.className=""}catch(e){}if(document.getElementById("InlineChessMove"+a+b)){this.currentHighlightInlineMove=document.getElementById("InlineChessMove"+a+b);this.currentHighlightInlineMove.className+=
" ActiveInlineChessMove";this.__autoScrollContainerInlineMove(this.currentHighlightInlineMove)}if(document.getElementById("TableChessMove"+a+b)){this.currentHighlightTableMove=document.getElementById("TableChessMove"+a+b);this.currentHighlightTableMove.className="ActiveTableChessMove";this.__autoScrollContainerTableMove(this.currentHighlightTableMove)}},__highlightActiveVariationMove:function(a,b){this.__highlightActiveMove(0,"white");var c="InlineVariationMove_"+this.insideVariation.move+"_"+this.insideVariation.color+
"_"+this.insideVariation.variationIndex+"_"+a+"_"+b;if(document.getElementById(c)){this.currentHighlightInlineMove=document.getElementById(c);this.currentHighlightInlineMove.className+=" ActiveInlineVariationChessMove";this.__autoScrollContainerInlineMove(this.currentHighlightInlineMove)}},__autoScrollContainerTableMove:function(a){try{var b=a.parentNode.parentNode;for(a=a.parentNode;b!=this.elMovesInTable[0]&&b.tagName.toLowerCase()!="body";)b=b.parentNode;var c=this.__getStyle(b,"overflow");if(c&&
(c!="auto"||c!="scroll")){b=b.parentNode;this.__getStyle(b,"overflow")}if(a.offsetTop>b.clientHeight+b.scrollTop-a.offsetHeight-2)b.scrollTop=a.offsetTop-b.clientHeight+a.offsetHeight+2}catch(d){}},__autoScrollContainerInlineMove:function(a){for(var b=a.parentNode;b!=this.elMovesInline;)b=b.parentNode;if(a.offsetTop>b.clientHeight+b.scrollTop-a.offsetHeight-2)b.scrollTop=a.offsetTop-b.clientHeight+a.offsetHeight+2},__clearDisplayedActiveMove:function(){if(this.elActiveMove)this.elActiveMove.innerHTML=
"";if(this.elActiveComment)this.elActiveComment.innerHTML=""},__displayActiveMove:function(a,b){if(this.elActiveMove){var c=this.__getAMoveInLanguage(this.pgnObject.gameDetails[this.currentGameIndex].moves[a][b].move);c=b=="black"?"... "+c:". "+c;c=a+c;this.elActiveMove.innerHTML=c}if(this.elActiveComment){c=this.pgnObject.gameDetails[this.currentGameIndex].moves[a][b];this.elActiveComment.innerHTML=c.comment?c.comment:""}},__getInfoByMoveString:function(a,b){a=a.replace(/[\#\+]/gi,"");if(a.length==
3&&a.match(/^[a-h][18][BRNQ]$/))a=a.substr(0,2)+"="+a.substr(2,1);var c=a.indexOf("x")>=0?true:false,d=a.indexOf("0")>=0?true:false;d||(d=a.indexOf("O")>=0?true:false);var e=a.substr(0,1).match(/[abcdefgh]/),f=a.substr(0,1).match(/[BKQNR]/g),h=a.match(/=/);if(e&&a.substr(a.length-1,1).match(/[BKQNR]/)){h=true;f=false}var g=false,i=a.match(/[0-9]/g);if(i&&i.length>1)g=i[0];if(h){e=true;f=false}if(f)e=false;i=false;var j=a.match(/[a-h]/g);if(j&&j.length>1)i=j[0];if(e){i=a.indexOf("x")>=0?a.replace(/^([a-h]).*$/,
"$1"):a.replace(/[^a-h]/g,"");g=a.replace(/[^0-9]/g,"");g=b=="black"?g/1+1:g/1-1}j={};j.fromFile=i;j.fromRank=g;j.castle=d;j.officer=f;j.pawnMove=e;j.capture=c;j.promote=h;return j},__parseAMove:function(a,b){this.lastMovePawnPromote=this.lastMoveEnPassant=false;this.currentlyParsedMove=a;var c=b=="white"?"black":"white";if(a.substr(a.length-1,1)=="=")a=a.substr(0,a.length-1);a=a.replace(/\-\/?\+/g,"");a=a.replace(/\+\/?\-/g,"");var d=this.__getInfoByMoveString(a);a=a.replace(/[\#\+!\?]/gi,"");if(!d.castle){var e=
a.replace(/=[BKQNR][+\#]?/g,"");e=e.replace(/[\#+]/g,"");e=e.substr(e.length-2,2)}if(d.pawnMove){a.replace(/[^0-9]/g,"");if(d.capture)f=this.__movePawnCapture(a,d.fromFile,b,true);else{var f=this.__movePawnForward(a,b);if(f||f==0)this.__movePieceToLocation(b,f,a)}if(d.promote){var h=this.pieces[b][f],g=a.replace(/[^NBRQ]/g,"").toLowerCase();this.__removePieceFromBoard(f,b);this.__createPieceByPromotion(h.file,h.rank,b,g);this.lastMovePawnPromote=true}}if(d.officer){f=a.substr(0,1).toLowerCase();d.capture&&
this.__removePieceFromBoard(this.__getPieceOnSquare(e,c),c);this.__moveOfficer(e,b,d.fromFile,d.fromRank,f)}if(d.castle){c=a.match(/\-/g);d=b=="white"?1:8;if(c.length>1){this.__moveOfficer("d"+d,b,"a",false,"r");this.__moveOfficer("c"+d,b,false,false,"k")}else{this.__moveOfficer("f"+d,b,"h",false,"r");this.__moveOfficer("g"+d,b,false,false,"k")}}},__createPieceByPromotion:function(a,b,c,d){c=c=="white"?"w":"b";col=this.__getColFromFile(a)+(8-b)*8;col--;a=document.createElement("div");a.style.width=
this.squareSize+"px";a.style.height=this.squareSize+"px";a.style.position="absolute";this.divBoard.appendChild(a);b=document.createElement("img");b.src=this.imageFolder+this.chessSet+this.squareSize+c+d.toLowerCase()+".png";a.appendChild(b);var e=this.__getBoardPosByCol(col);this.isOldMSIE&&!this.isOpera&&this.correctPng(b);a.style.left=e.x+"px";a.style.top=e.y+"px";if(this.animateNextMove)a.style.display="none";d=this.__addPieceToArray(c,d,col,a);this.__addEventToChessPiece(a,c,d);return d},__moveOfficer:function(a,
b,c,d,e){for(counter=0;counter<this.pieces[b].length;counter++){var f=this.pieces[b][counter];if(!(c&&f.file!=c))if(!(d&&f.rank!=d))if(f.pieceType==e)if(this.__canPieceMoveToSquare(b,counter/1,a)){this.__movePieceToLocation(b,counter,a);return}}},__canPieceMoveToSquare:function(a,b,c,d){b=this.pieces[a][b];if(!b.onBoard)return false;var e=this.__getColAndRowFromSquare(c),f=this.__getColFromFile(b.file),h=b.rank,g=Math.max(e.col,f)-Math.min(e.col,f),i=Math.max(e.row,h)-Math.min(e.row,h);if(b.pieceType==
"b"||b.pieceType=="q")if(g==i)if(!this.__occupiedSquaresBetween({col:e.col,row:e.row},{col:f,row:h})){if(d)return true;if(!this.__isMovingIntoCheckByMovingThisPiece(b,a,c))return true}if(b.pieceType=="r"||b.pieceType=="q")if(g==0||i==0)if(!this.__occupiedSquaresBetween({col:e.col,row:e.row},{col:f,row:h})){if(d)return true;if(!this.__isMovingIntoCheckByMovingThisPiece(b,a,c))return true}if(b.pieceType=="k")return true;if(b.pieceType=="n"){if(i==2&&g==1){if(d)return true;if(!this.__isMovingIntoCheckByMovingThisPiece(b,
a,c))return true}if(g==2&&i==1){if(d)return true;if(!this.__isMovingIntoCheckByMovingThisPiece(b,a,c))return true}}return false},__isMovingIntoCheckByMovingThisPiece:function(a,b,c){if(this.__isKingInCheck(b))return false;a.onBoard=false;var d=b=="white"?"black":"white",e=this.__getPieceOnSquare(c,d);if(e||e===0)this.pieces[d][e].onBoard=false;var f=this.__isKingInCheck(b);a.onBoard=true;if(f){var h=a.file,g=a.rank;a.file=c.substr(0,1);a.rank=c.substr(1,1);f=this.__isKingInCheck(b);a.file=h;a.rank=
g}if(e||e===0)this.pieces[d][e].onBoard=true;return f},__isKingInCheck:function(a){for(var b,c=0;c<this.pieces[a].length;c++)if(this.pieces[a][c].pieceType=="k"){b=this.pieces[a][c];break}this.__getColFromFile(b.file);a=a=="white"?"black":"white";for(c=0;c<this.pieces[a].length;c++){var d=this.pieces[a][c];if(d.onBoard)if(d.pieceType=="b"||d.pieceType=="q"||d.pieceType=="r")if(this.__canPieceMoveToSquare(a,c,b.file+b.rank,true))return true}return false},__occupiedSquaresBetween:function(a,b){for(var c=
this.__getSquaresBetween(a,b),d=0;d<c.length;d++){var e=this.__getPieceOnSquare(c[d],"white");if(e||e===0)return true;if((e=this.__getPieceOnSquare(c[d],"black"))||e===0)return true}return false},__getSquaresBetween:function(a,b){var c=[];if(a.row==b.row){var d=Math.min(a.col,b.col)+1,e=Math.max(a.col,b.col)-1;if(e<d==1)return false;for(d=d;d<=e;d++)c[c.length]=this.__getFileByCol(d)+""+b.row}else if(a.col==b.col){var f=this.__getFileByCol(a.col);d=Math.min(a.row,b.row)+1;e=Math.max(a.row,b.row)-
1;if(e<d==1)return false;for(d=d;d<=e;d++)c[c.length]=f+""+d}else{var h=1,g=1;if(a.col>b.col)h=-1;if(a.row>b.row)g=-1;d=Math.min(a.col,b.col);e=Math.max(a.col,b.col);e=e-d;for(d=1;d<e;d++){f=a.col+d*h;var i=a.row+d*g;f=this.__getFileByCol(f);c[c.length]=f+""+i}}return c},__movePawnForward:function(a,b){a=a.replace(/[^0-9a-h]/g,"");for(var c=a.replace(/[0-9]/g,""),d=a.replace(/[^0-9]/g,""),e=0;e<this.pieces[b].length;e++){var f=this.pieces[b][e];if(f.onBoard){var h=false;if(b=="white"&&f.rank<d)h=
true;if(b=="black"&&f.rank>d)h=true;var g=1;if(b=="white"){if(d==4)g=2;if(d-f.rank>g)h=false}if(b=="black"){if(d==5)g=2;if(f.rank-d>g)h=false}if(h){g=this.__getColFromFile(c);var i=this.__getColFromFile(f.file);if(this.__occupiedSquaresBetween({col:g,row:d},{col:i,row:f.rank}))h=false}if(f.pieceType=="p"&&f.file==c&&h)return e}}return false},__movePawnCapture:function(a,b,c,d){var e=c=="white"?"black":"white";a=a.replace(/.*?x([a-z][1-8]).*/g,"$1");var f=this.__getPieceOnSquare(a,e);b=this.__movePawn(b,
a,c,d);if(f||f===0)d&&this.__removePieceFromBoard(f,e);else{this.lastMoveEnPassant=true;f=a.substr(0,1);a=a.substr(1,1);if(c=="white")a--;else a++;a=f+""+a;(f=this.__getPieceOnSquare(a,e))&&d&&this.__removePieceFromBoard(f,e)}return b},__movePawn:function(a,b,c,d){var e=b.substr(1,1)/1;if(c=="white")e--;else e++;a=this.__getPieceOnSquare(a+e,c);d&&this.__movePieceToLocation(c,a,b);return a},__getPieceOnSquare:function(a,b){var c=a.substr(0,1),d=a.substr(1,1);for(no=0;no<this.pieces[b].length;no++){var e=
this.pieces[b][no];if(e.onBoard)if(e.file==c&&e.rank==d&&e.onBoard)return no}return false},__getSlideCoordinates:function(a,b){var c=Math.max(a.x,b.x)-Math.min(a.x,b.x),d=Math.max(a.y,b.y)-Math.min(a.y,b.y),e=22.5*this.animationSpeed;if(c>d){if(c==0)c=1;moveX=c/e;moveY=moveX*(d/c)}else{if(d==0)d=1;moveY=Math.ceil(d/e);moveX=moveY*(c/d)}c=1;if(b.x<a.x)c=-1;d=1;if(b.y<a.y)d=-1;e=[];moveX*=c;moveY*=d;for(var f=0;Math.abs(moveX)<1&&Math.abs(moveY)<1&&f<10;){moveX*=2;moveY*=2;f++}e[e.length]={x:a.x,y:a.y};
var h=false,g=false,i=false;if(d==0)i=true;if(c==0)g=true;for(f=0;!h;){if(moveX==0&&moveY==0)h=true;f++;if(f>400){alert("Infinite loop ("+moveX+","+moveY+")");return}a.x+=moveX;a.y+=moveY;if(d>0&&a.y>=b.y&&moveY!=0){i=true;a.y=b.y;a.x=b.x}else if(d<0&&a.y<=b.y&&moveY!=0){i=true;a.y=b.y;a.x=b.x}else if(c>0&&a.x>=b.x&&moveX!=0){g=true;a.x=b.x;a.y=b.y}else if(c<0&&a.x<=b.x&&moveX!=0){g=true;a.x=b.x;a.y=b.y}e[e.length]={x:Math.round(a.x),y:Math.round(a.y)};if(g||i)h=true}if(e.length<=2)e[e.length]={x:Math.round(a.x),
y:Math.round(a.y)};e.length<=2&&alert("Length of array: "+e.length);return e},__onAnimatedMoveComplete:function(){this.__handleCallback("moveComplete");var a=this.__getLastMove(),b=this.__getLastPlayedMove();this.__playSound();a.color==b.color&&a.move==b.move&&this.__handleCallback("afterLastMove")},__movePieceToLocation:function(a,b,c){c=this.__getBoardPosByNotation(c);var d=this.pieces[a][b].el;this.currentZIndex++;d.style.zIndex=this.currentZIndex;var e=this.__getBoardPosByNotation(this.pieces[a][b].file+
this.pieces[a][b].rank);this.coordLastMove.from.x=e.x;this.coordLastMove.from.y=e.y;this.coordLastMove.to.x=c.x;this.coordLastMove.to.y=c.y;if(this.animateNextMove){this.isBusy=true;e=d.style.left.replace("px","")/1;d=d.style.top.replace("px","")/1;var f=this.slideCoordinates.length;this.slideCoordinates[f]=this.__getSlideCoordinates({x:e,y:d},{x:c.x,y:c.y});this.__slideElement({coordIndex:f,coordStep:1},{x:c.x,y:c.y},b,a)}else{d.style.left=c.x+"px";d.style.top=c.y+"px"}this.__updatePieceRankFileByPosition(b,
a,{x:c.x,y:c.y})},__slideElement:function(a,b,c,d,e){var f=this.objectIndex,h=true;if(a.coordStep==this.slideCoordinates[a.coordIndex].length-1)h=false;this.pieces[d][c].el.style.left=this.slideCoordinates[a.coordIndex][a.coordStep].x+"px";this.pieces[d][c].el.style.top=this.slideCoordinates[a.coordIndex][a.coordStep].y+"px";if(h){c="{ coordIndex:"+a.coordIndex+",coordStep:"+(a.coordStep+1)+" },{ 'x':"+b.x+",'y':"+b.y+" },'"+c+"','"+d+"'";c=e?c+",'"+e+"'":c+",false";setTimeout("D_chessObjects["+f+
"].__slideElement("+c+")",this.animationSetTimeout)}else if(e)e!="sameSquare"?this.__handleCallback("wrongMove"):this.__playSound("move");else{this.slideCoordinates[a.coordIndex]=null;this.animateNextMove=false;this.__indicateLastMove();this.isBusy=false;e=d=="white"?"black":"white";b=this.__getNotationByBoardPos(b.x,b.y);if((a=this.__getPieceOnSquare(b,e))||a===0)this.__removePieceFromBoard(a,e);else if(this.lastMoveEnPassant){b=e=="black"?b.substr(0,1)+(b.substr(1,1)/1-1):b.substr(0,1)+(b.substr(1,
1)/1+1);a=this.__getPieceOnSquare(b,e);this.__removePieceFromBoard(a,e)}if(this.lastMovePawnPromote){a=this.__getPieceOnSquare(b,d);this.__removePieceFromBoard(a,d);a=this.__getPieceOnSquare(b,d);this.pieces[d][a].el.style.display="block"}b=true;if(this.pieces[d][c].pieceType=="k"){c=this.__getLastPlayedMove();if(c.moveString=="O-O"||c.moveString=="O-O-O"||c.moveString=="0-0"||c.moveString=="0-0-0")b=false}b&&this.__onAnimatedMoveComplete();if(this.autoPlayActive){c=this.__getNextMove();d=this.__getAutoPlayDelayBeforeNextMove();
this.stopAutoplayBeforeComments&&this.pgnObject.gameDetails[this.currentGameIndex].moves[this.currentMove][this.currentColor].comment?this.stopAutoPlay():setTimeout("D_chessObjects["+f+"].__autoPlayStep("+c.move+',"'+c.color+'")',d)}}},__removePieceFromBoard:function(a,b){if(!this.animateNextMove)try{this.pieces[b][a].onBoard=false;this.pieces[b][a].el.style.display="none"}catch(c){}},__updatePieceRankFileByPosition:function(a,b,c){var d=c.x/this.squareSize;c=c.y/this.squareSize;c=8-c;if(this.flipBoard){d=
7-d;c=9-c}d="abcdefgh".substr(d,1);this.pieces[b][a].file=d;this.pieces[b][a].rank=c},__indicateLastMove:function(){this.divIndicators.from.parentNode||this.__createIndicators();var a=this.divIndicators.from.style,b=this.divIndicators.to.style;if(this.indicateLastMove&&!this.animateNextMove){a.display="block";b.display="block"}else this.__hideIndicators();try{var c=this.__getStyle(this.divIndicators.to,"borderLeftWidth").replace("px","")/1}catch(d){c=2}c||(c=(this.divIndicators.from.offsetWidth-this.divIndicators.from.clientWidth)/
2);c=this.squareSize-c*2;if(this.coordLastMove.x||this.coordLastMove.y||this.coordLastMove.to.x||this.coordLastMove.to.y){a.left=this.coordLastMove.from.x+"px";a.top=this.coordLastMove.from.y+"px";a.width=c+"px";a.height=c+"px";b.left=this.coordLastMove.to.x+"px";b.top=this.coordLastMove.to.y+"px";b.width=c+"px";b.height=c+"px"}else this.__hideIndicators()},__hideIndicators:function(){this.divIndicators.from.style.display="none";this.divIndicators.to.style.display="none"},setBoardLabels:function(a){this.boardLabels=
a},displayBoardByFen:function(a,b){b=this.__getEl(b);b.innerHTML="";this.__createBoardDiv(b);this.__loadFen(a,this.divBoard);this.__hideIndicators()},__setWhoToMoveFromResult:function(){var a=this.pgnObject.gameDetails[this.currentGameIndex].result;a=a.trim();this.whoToStartMove=a=="0-1"?"b":"w"},__setWhoToMoveFromFen:function(a){try{this.whoToStartMove=a.split(/\s/g)[1].trim()}catch(b){alert("Unable to parse FEN string");return"w"}},__clearBoard:function(){this.parentRef.innerHTML="";this.__createBoardDiv();
this.divBoard.innerHTML="";this.__createSquares(this.divBoard);if(!this.whoToStartMove)this.whoToStartMove="w";this.currentMove=1;this.currentColor=this.whoToStartMove;this.currentMoveNumber=1},__createDefaultPieces:function(){this.__clearBoard();this.pieces=[];this.pieces.white=[];this.pieces.black=[];for(var a="rnbqkbnrpppppppp",b="b",c=0;c<a.length;c++){var d=a.substr(c,1),e=document.createElement("div");e.style.width=this.squareSize+"px";e.style.height=this.squareSize+"px";e.style.position="absolute";
this.divBoard.appendChild(e);if(this.isMSIE){var f=document.createElement("img");f.src=this.imageFolder+this.chessSet+this.squareSize+b+d.toLowerCase()+".png";e.appendChild(f);this.isOldMSIE&&!this.isOpera&&this.correctPng(f)}else e.style.backgroundImage='url("'+this.imageFolder+this.chessSet+this.squareSize+b+d.toLowerCase()+'.png")';f=this.__getBoardPosByCol(c);e.style.left=f.x+"px";e.style.top=f.y+"px";d=this.__addPieceToArray("b",d.toLowerCase(),c,e);this.__addEventToChessPiece(e,b,d)}a="pppppppprnbqkbnr";
b="w";for(c=0;c<a.length;c++){d=a.substr(c,1);e=document.createElement("div");e.style.width=this.squareSize+"px";e.style.height=this.squareSize+"px";e.style.position="absolute";this.divBoard.appendChild(e);if(this.isMSIE){f=document.createElement("img");f.src=this.imageFolder+this.chessSet+this.squareSize+b+d.toLowerCase()+".png";e.appendChild(f);this.isOldMSIE&&!this.isOpera&&this.correctPng(f)}else e.style.backgroundImage='url("'+this.imageFolder+this.chessSet+this.squareSize+b+d.toLowerCase()+
'.png")';f=this.__getBoardPosByCol(c+48);e.style.left=f.x+"px";e.style.top=f.y+"px";d=this.__addPieceToArray("w",d.toLowerCase(),c+48,e);this.__addEventToChessPiece(e,b,d)}},__addPieceToArray:function(a,b,c,d){if(a=="w")a="white";if(a=="b")a="black";var e=this.pieces[a].length;this.pieces[a][e]={};this.pieces[a][e].pieceType=b;b=this.__getRankFileByCol(63-c);this.pieces[a][e].file=b.file;this.pieces[a][e].rank=b.rank;this.pieces[a][e].el=d;this.pieces[a][e].onBoard=true;return e},__createBoardDiv:function(a){if(!a)a=
this.parentRef;var b=document.createElement("DIV");b.className="ChessBoard"+this.squareSize;b.style.position="relative";b.id=this.__getUniqueId();this.labelDivRef=b.id;var c=document.createElement("DIV");c.className="ChessBoardInner"+this.squareSize;c.style.width=this.squareSize*8+"px";c.style.height=this.squareSize*8+"px";this.divBoard=c;this.divBoard.onselectstart=function(){return false};this.__addEventEl(this.divBoard);this.boardFrame=document.createElement("DIV");this.boardFrame.className="ChessBoardFrame"+
this.squareSize;this.boardFrame.appendChild(c);b.appendChild(this.boardFrame);c.style.position="relative";c.style.left="0px";c.style.top="0px";a.appendChild(b);this.boardLabels&&this.__addBoardLabels(b);this.__createSquares(this.divBoard);this.__createIndicators();return c},__getUniqueId:function(){return("UID"+Math.random()+""+Math.random()).replace(/\./g,"")},showBoardLabels:function(){var a=this.__getEl(this.labelDivRef);this.boardLabels=true;this.__addBoardLabels(a)},hideBoardLabels:function(){this.boardLabels=
false;for(var a=this.__getEl(this.labelDivRef),b=a.getElementsByTagName("DIV"),c=0;c<b.length;c++)if(b[c].className.indexOf("ChessBoardLabel")>=0){a.removeChild(b[c]);c--}},__createSquares:function(a){currentBgColor=this.colorLightSquares;currentBgImg=this.bgImageLightSquares;currentClass="chessBoardSquare_light";var b=false,c=false;if(this.__isArray(this.bgImageLightSquares))b=true;if(this.__isArray(this.bgImageDarkSquares))c=true;for(no=1;no<=64;no++){var d=document.createElement("DIV");d.style.cssText=
"float:left;width:"+this.squareSize+"px;height:"+this.squareSize+"px";d.style.styleFloat="left";d.style.width=this.squareSize+"px";d.style.height=this.squareSize+"px";d.className=currentClass;if(currentBgColor)d.style.backgroundColor=currentBgColor;if(currentBgImg)d.style.backgroundImage="url('"+currentBgImg+"')";a.appendChild(d);val=(no+Math.floor(no/8))%2;if(val==0){currentBgColor=this.colorLightSquares;currentBgImg=this.bgImageLightSquares;currentBgImg=b?this.bgImageLightSquares[Math.floor(Math.random()*
this.bgImageLightSquares.length)]:this.bgImageLightSquares;currentClass="chessBoardSquare_light";currentClass=currentClass+" chessBoardSquare_light_no"+no%8}else{currentBgColor=this.colorDarkSquares;currentBgImg=c?this.bgImageDarkSquares[Math.floor(Math.random()*this.bgImageDarkSquares.length)]:this.bgImageDarkSquares;currentClass="chessBoardSquare_dark";currentClass=currentClass+" chessBoardSquare_dark_no"+no%8}}},__addBoardLabels:function(a){var b=this.__getStyle(this.divBoard,"borderLeftWidth").replace("px",
"")/1;try{var c=this.__getLeftPos(this.divBoard),d=this.__getLeftPos(this.boardFrame);b+=c-d}catch(e){}for(c=1;c<=8;c++){d=document.createElement("DIV");d.style.position="absolute";d.style.right=(8-c)*this.squareSize+b+"px";d.style.bottom="0px";d.innerHTML="abcdefgh".substr(c-1,1);d.style.textAlign="center";d.style.width=this.squareSize+"px";a.appendChild(d);d.className="ChessBoardLabel ChessBoardLabel"+this.squareSize;d.id="ChessBoardLabel_"+d.innerHTML;var f=document.createElement("DIV");f.style.position=
"absolute";f.style.left="0px";f.style.top=(8-c)*this.squareSize+b+"px";f.innerHTML=c;f.style.height=this.squareSize+"px";f.style.lineHeight=this.squareSize+"px";a.appendChild(f);f.className="ChessBoardLabel ChessBoardLabel"+this.squareSize;f.id="ChessBoardLabel_"+f.innerHTML;if(this.flipBoard){f.innerHTML=9-c;d.innerHTML="abcdefgh".substr(8-c,1)}}},__loadFen:function(a,b){this.__setWhoToMoveFromFen(a);var c=a.split(/\s/g)[0];this.pieces=[];this.pieces.white=[];this.pieces.black=[];for(var d=0,e=0;e<
c.length;e++){var f=c.substr(e,1);if(f.match(/[A-Z]/i)){var h=this.__getBoardPosByCol(d),g=document.createElement("DIV");g.style.position="absolute";g.style.left=h.x+"px";g.style.top=h.y+"px";if(f.match(/[A-Z]/))var i="w";if(f.match(/[a-z]/))i="b";h=document.createElement("IMG");h.src=this.imageFolder+this.chessSet+this.squareSize+i+f.toLowerCase()+".png";g.appendChild(h);g.className="ChessPiece"+this.squareSize;b.appendChild(g);var j=this.__addPieceToArray(i,f.toLowerCase(),d,g);this.__addEventToChessPiece(g,
i,j);d++;this.isOldMSIE&&!this.isOpera&&this.correctPng(h)}if(f.match(/[0-8]/))d+=f/1}},__addEventToChessPiece:function(a,b,c){var d=this.objectIndex;a.onmousedown=this.__moveDownOnChessPiece;a.onselectstart=this.__cancelEvent;a.ondragstart=this.__cancelEvent;this.__addEventEl(a);a.setAttribute("objectIndex",d);a.setAttribute("color",b);a.setAttribute("pieceIndex",c)},__getLastPlayedMove:function(){var a={};if(this.insideVariation){a.color=this.currentVariationColor;a.move=this.currentVariationMove;
try{a.moveString=this.pgnObject.gameDetails[this.currentGameIndex].moves[this.insideVariation.move][this.insideVariation.color].variation[this.insideVariation.variationIndex][this.currentVariationMove][this.currentVariationColor]}catch(b){}}else{a.color=this.currentColor;a.move=this.currentMove;try{a.moveString=this.pgnObject.gameDetails[this.currentGameIndex].moves[this.currentMove][this.currentColor].move}catch(c){}}return a},__getNextMove:function(){if(this.currentGameIndex===false)return{move:0,
color:"white"};var a={};if(this.insideVariation)var b=this.currentVariationMove,c=this.currentVariationColor;else{b=this.currentMove;c=this.currentColor}if(b==0){b=1;c="white";if(this.pgnObject.gameDetails[this.currentGameIndex].moves[1]){if(!this.insideVariation&&!this.pgnObject.gameDetails[this.currentGameIndex].moves[1].white)c="black"}else c="white"}else if(c=="black"){c="white";b++}else c="black";a.move=b;a.color=c;var d;try{d=this.insideVariation?this.pgnObject.gameDetails[this.currentGameIndex].moves[this.insideVariation.move][this.insideVariation.color].variation[this.insideVariation.variationIndex][b][c]:
this.pgnObject.gameDetails[this.currentGameIndex].moves[b][c].move}catch(e){return a}var f=this.__getSquareAndPieceByNotation(d,c),h=this.__getInfoByMoveString(d,c);a=h;a.notation=d;a.toSquare=f.square;a.pieceType=f.pieceType;if(h.pawnMove)a.pieceType="p";a.move=b;a.color=c;return a},__getSquareAndPieceByNotation:function(a,b){var c={};a=a.trim();a=a.replace(/[\+#]/g,"");if(a=="0-0"||a=="O-O"){c.pieceType="k";c.square=b=="white"?"g1":"g8";return c}if(a=="0-0-0"||a=="O-O-O"){c.pieceType="k";c.square=
b=="white"?"c1":"c8";return c}var d=a.replace(/[^BKQNR]/g,"");d||(d="p");d=d.toLowerCase();var e=a.replace(/=[BKQNR][+\#]?/g,"");e=e.replace(/[\#+]/g,"");c.square=e.substr(e.length-2,2);c.pieceType=d;return c},__getFileByCol:function(a){return"abcdefgh".substr(a-1,1)},__getColFromFile:function(a){return"abcdefgh".indexOf(a)+1},__getColAndRowFromSquare:function(a){var b=a.substr(0,1);a=a.substr(1,1)/1;b=this.__getColFromFile(b);var c={};c.col=b;c.row=a;return c},__getRankFileByCol:function(a){for(var b=
1;a>=8;){b++;a-=8}var c={};c.file="hgfedcba".substr(a,1);c.rank=b;return c},__getNotationByBoardPos:function(a,b){var c=a/this.squareSize,d=8-b/this.squareSize;if(this.flipBoard){c=7-c;d=9-d}c="abcdefgh".charAt(c);return c+d},__getBoardPosByNotation:function(a){a=a.replace(/[^0-9a-h]/g,"");var b=a.replace(/[^0-9]/gi,"")/1;a="abcdefgh".indexOf(a.replace(/[0-9]/gi,""))+1;a--;b=8-b;if(this.flipBoard){a=7-a;b=7-b}var c={};c.x=a*this.squareSize;c.y=b*this.squareSize;return c},__getBoardPosByCol:function(a){for(var b=
0;a>=8;){b++;a-=8}var c={};if(this.flipBoard){a=7-a;b=7-b}c.x=a*this.squareSize;c.y=b*this.squareSize;return c},__loadCss:function(a){var b=document.createElement("LINK");b.href=a+"?rand="+Math.random();b.rel="stylesheet";b.media="screen";b.type="text/css";document.getElementsByTagName("HEAD")[0].appendChild(b)},__createIndicators:function(){this.divIndicators.from=document.createElement("DIV");this.divIndicators.from.style.position="absolute";this.divIndicators.from.className="ChessMoveIndicator";
this.divBoard.appendChild(this.divIndicators.from);this.divIndicators.from.zIndex=9E6;this.divIndicators.to=document.createElement("DIV");this.divIndicators.to.className="ChessMoveIndicator";this.divIndicators.to.style.position="absolute";this.divBoard.appendChild(this.divIndicators.to);this.divIndicators.to.zIndex=9E6;this.divIndicators.to.style.width="100px";this.divIndicators.to.style.height="100px"},__handleCallback:function(a){var b="";switch(a){case "beforeGameLoad":b=this.callbackOnBeforeGameLoaded;
break;case "startGame":b=this.callbackOnGameLoaded;break;case "switchPgn":b=this.callbackOnSwitchPgn;break;case "stopAutoPlay":b=this.callbackOnStopAutoPlay;break;case "moveComplete":b=this.callbackOnMoveComplete;break;case "wrongMove":b=this.callbackOnWrongMove;break;case "correctMove":b=this.callbackOnCorrectMove;break;case "afterLastMove":b=this.callbackAfterLastMove;break}if(b){if(b.indexOf("(")==-1)b=b+"(this.pgnObject.gameDetails["+this.currentGameIndex+"])";eval(b)}},__getEl:function(a){if(typeof a==
"string"){if(document.getElementById(a))return document.getElementById(a);if(document.forms[a])return document.forms[a];if(document[a])return document[a];if(window[a])return window[a]}return a},__setInitProps:function(a){if(a.cssPath)this.cssPath=a.cssPath;if(a.imageFolder)this.imageFolder=a.imageFolder;if(a.squareSize)this.squareSize=a.squareSize;if(a.callbackOnGameLoaded)this.callbackOnGameLoaded=a.callbackOnGameLoaded;if(a.callbackBeforeComments)this.callbackBeforeComments=a.callbackBeforeComments;
if(a.callbackOnBeforeGameLoaded)this.callbackOnBeforeGameLoaded=a.callbackOnBeforeGameLoaded;if(a.callbackOnSwitchPgn)this.callbackOnSwitchPgn=a.callbackOnSwitchPgn;if(a.callbackOnStopAutoPlay)this.callbackOnStopAutoPlay=a.callbackOnStopAutoPlay;if(a.callbackOnWrongMove)this.callbackOnWrongMove=a.callbackOnWrongMove;if(a.callbackOnCorrectMove)this.callbackOnCorrectMove=a.callbackOnCorrectMove;if(a.callbackAfterLastMove)this.callbackAfterLastMove=a.callbackAfterLastMove;if(a.autoPlayDelayBetweenMoves)this.autoPlayDelayBetweenMoves=
a.autoPlayDelayBetweenMoves;if(a.animationSpeed)this.animationSpeed=a.animationSpeed;if(a.autoplayDelayBeforeComments)this.autoplayDelayBeforeComments=a.autoplayDelayBeforeComments;if(a.stopAutoplayBeforeComments||a.stopAutoplayBeforeComments===false)this.stopAutoplayBeforeComments=a.stopAutoplayBeforeComments;if(a.parentRef){this.parentRef=this.__getEl(a.parentRef);this.parentRef.className="ChessBoardParentContainer"+this.squareSize;try{this.parentRef.parentNode.className="ChessBoardParentOfParentContainer"+
this.squareSize}catch(b){}}if(a.boardLabels||a.boardLabels===false)this.boardLabels=a.boardLabels;if(a.flipBoardWhenBlackToStart||a.flipBoardWhenBlackToStart===false)this.flipBoardWhenBlackToStart=a.flipBoardWhenBlackToStart;if(a.chessSet)this.chessSet=a.chessSet;if(a.elMovesInline)this.elMovesInline=this.__getEl(a.elMovesInline);if(a.elMovesInTable)if(this.__isArray(a.elMovesInTable))for(var c=0;c<a.elMovesInTable.length;c++)this.elMovesInTable[c]=this.__getEl(a.elMovesInTable[c]);else this.elMovesInTable[0]=
this.__getEl(a.elMovesInTable);if(a.elPlayerNames)this.elPlayerNames=this.__getEl(a.elPlayerNames);if(a.elActiveMove)this.elActiveMove=this.__getEl(a.elActiveMove);if(a.elActivePgnFile)this.elActivePgnFile=this.__getEl(a.elActivePgnFile);if(a.elActiveComment)this.elActiveComment=this.__getEl(a.elActiveComment);if(a.colorLightSquares||a.colorLightSquares=="")this.colorLightSquares=a.colorLightSquares;if(a.colorDarkSquares||a.colorDarkSquares=="")this.colorDarkSquares=a.colorDarkSquares;if(a.bgImageDarkSquares||
a.bgImageDarkSquares=="")this.bgImageDarkSquares=a.bgImageDarkSquares;if(a.bgImageLightSquares||a.bgImageLightSquares=="")this.bgImageLightSquares=a.bgImageLightSquares;if(a.animate||a.animate===false)this.animate=a.animate;if(a.sound||a.sound===false)this.sound=a.sound;if(a.indicateLastMove||a.indicateLastMove===false)this.indicateLastMove=a.indicateLastMove;if(a.displayPrefaceCommentWithInlineMoves||a.displayPrefaceCommentWithInlineMoves===false)this.displayPrefaceCommentWithInlineMoves=a.displayPrefaceCommentWithInlineMoves;
if(a.elGameAttributes)this.elGameAttributes=a.elGameAttributes;if(a.dragAndDropColor)this.dragAndDropColor=a.dragAndDropColor;if(a.liveUpdateInterval)this.liveUpdateInterval=a.liveUpdateInterval;if(a.elMovesInTableMaxMovesPerTable)this.elMovesInTableMaxMovesPerTable=a.elMovesInTableMaxMovesPerTable;if(a.languageCode)this.languageCode=a.languageCode;if(a.keyboardSupport||a.keyboardSupport===false)this.keyboardSupport=a.keyboardSupport},__isDragOk:function(a){if(this.currentGameIndex===false||this.isBusy||
this.autoPlayActive)return false;var b=this.__getNextMove();if(a!=b.color)return false;if(a!=this.dragAndDropColor)return false;return true},__clearDragProperties:function(){this.dragProperties={}},__moveDownOnChessPiece:function(a){if(document.all)a=event;var b=this.getAttribute("color"),c=this.getAttribute("pieceIndex"),d=this.getAttribute("objectIndex");d=D_chessObjects[d];var e="white";if(b=="b")e="black";if(d.__isDragOk(e,c)){b=d.pieces[e][c].el.style.left.replace("px","")/1;var f=d.pieces[e][c].el.style.top.replace("px",
"")/1;d.currentZIndex++;d.pieces[e][c].el.style.zIndex=d.currentZIndex;d.dragProperties={color:e,pieceIndex:c,mouseX:a.clientX,mouseY:a.clientY,pieceX:b,pieceY:f,toFile:false,toRank:false};d.dragCountDownVar=2;document.body.style.cursor="move";d.__countDownToDragStart()}return false},__countDownToDragStart:function(){if(this.dragCountDownVar>=0&&this.dragCountDownVar<5){this.dragCountDownVar++;setTimeout("D_chessObjects["+this.objectIndex+"].__countDownToDragStart()",5)}},__moveDraggedPiece:function(a){if(document.all)a=
event;if(this.dragCountDownVar==5){this.pieces[this.dragProperties.color][this.dragProperties.pieceIndex].el.style.left=a.clientX-this.dragProperties.mouseX+this.dragProperties.pieceX+"px";this.pieces[this.dragProperties.color][this.dragProperties.pieceIndex].el.style.top=a.clientY-this.dragProperties.mouseY+this.dragProperties.pieceY+"px"}},__getSquareFromDragXY:function(a,b){a=Math.ceil(a/this.squareSize);b=Math.ceil(8-b/this.squareSize);if(this.flipBoard){a=9-a;b=9-b}return this.__getFileByCol(a)+
b},__isCorrectPieceDraggedToCorrectSquare:function(a){if(this.currentGameIndex===false)return false;var b=this.__getNextMove();if(b.pawnMove){if((b.capture?this.__movePawnCapture(b.notation,b.fromFile,b.color,false):this.__movePawnForward(b.notation,b.color))==this.dragProperties.pieceIndex&&a==b.toSquare)return true;return false}var c=this.pieces[this.dragProperties.color][this.dragProperties.pieceIndex],d=true;this.__canPieceMoveToSquare(this.dragProperties.color,this.dragProperties.pieceIndex/
1,a)||(d=false);if(c.pieceType!=b.pieceType)d=false;if(b.fromFile&&b.fromFile!=c.file)d=false;if(b.toSquare!=a)d=false;if(b.fromRank&&b.fromRank!=c.rank)d=false;if(d)return true;if(!this.insideVariation)if(c=this.__getVariationIndexes(b.move,b.color)){for(var e in c){this.__setStartVariationVariables(b.move,b.color,e);if(this.__isCorrectPieceDraggedToCorrectSquare(a))return true}this.insideVariation=false}this.__getPieceOnSquare(a,this.dragProperties.color=="white"?"black":"white")===false?this.__playSound("move"):
this.__playSound("capture");return false},__getVariationIndexes:function(a,b){try{return this.pgnObject.gameDetails[this.currentGameIndex].moves[a][b].variation}catch(c){return false}},__dragAndDropAfterMoveCallback:function(){if(this.__getLastPlayedMove().color==this.dragProperties.color){setTimeout("D_chessObjects["+this.objectIndex+"].move(1)",100);this.__handleCallback("correctMove")}else this.callbackOnMoveComplete=false},__releaseDraggedPiece:function(a){if(this.dragCountDownVar==5){document.body.style.cursor=
"";var b=this.objectIndex;this.dragCountDownVar=-1;if(document.all)a=event;var c=a.clientX-this.__getLeftPos(this.divBoard)+Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);a=a.clientY-this.__getTopPos(this.divBoard)+Math.max(document.documentElement.scrollTop,document.body.scrollTop);c=this.__getSquareFromDragXY(c,a);if(this.__isCorrectPieceDraggedToCorrectSquare(c)){this.callbackOnMoveComplete="D_chessObjects["+b+"].__dragAndDropAfterMoveCallback";this.move(1)}else{b=this.__getPieceXY(this.dragProperties.color,
this.dragProperties.pieceIndex);a=this.pieces[this.dragProperties.color][this.dragProperties.pieceIndex];var d=this.__getBoardPosByNotation(a.file+a.rank);a=this.slideCoordinates.length;this.slideCoordinates[a]=this.__getSlideCoordinates({x:b.x,y:b.y},{x:d.x,y:d.y});d="differentSquare";if(c==this.pieces[this.dragProperties.color][this.dragProperties.pieceIndex].file+this.pieces[this.dragProperties.color][this.dragProperties.pieceIndex].rank)d="sameSquare";this.__slideElement({coordIndex:a,coordStep:1},
{x:b.x,y:b.y},this.dragProperties.pieceIndex,this.dragProperties.color,d)}}},__getPieceXY:function(a,b){var c={};c.x=this.pieces[a][b].el.style.left.replace("px","")/1;c.y=this.pieces[a][b].el.style.top.replace("px","")/1;return c},__cancelEvent:function(){return false},__addGeneralEvents:function(){var a=this.objectIndex;this.addEvent(window,"unload",function(){D_chessObjects[a].__clearMemoryGarbage()});this.addEvent(document.documentElement,"mousemove",function(b){D_chessObjects[a].__moveDraggedPiece(b)});
this.addEvent(document.documentElement,"mouseup",function(b){D_chessObjects[a].__releaseDraggedPiece(b)})},__createLiveUpdateHandler:function(){this.liveUpdateInterval&&setInterval("D_chessObjects["+this.objectIndex+"].__getNewGameData()",this.liveUpdateInterval*1E3)},__addSoundEffects:function(){if(this.sound){this.soundEmbed=document.createElement("bgsound");this.soundEmbed.setAttribute("autostart",true);this.soundEmbed.setAttribute("loop",false);this.soundEmbed.src="";document.getElementsByTagName("HEAD")[0].appendChild(this.soundEmbed)}},
__playSound:function(a){if(this.sound){var b=this.__getLastPlayedMove();if(a)switch(a){case "startGame":c="startgame1.wav";break;case "move":c="move1.wav";break;case "capture":c="capture1.wav";break}else{var c="move1.wav";if(b.moveString.indexOf("x")>=0)c="capture1.wav";if(b.moveString.indexOf("O-O")>=0)c="castle1.wav"}if(this.soundEmbed.src.indexOf("1")>0)c=c.replace("1","2");this.soundEmbed.src="sound/"+c}},correctPng:function(a){a=this.__getEl(a);a.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+
a.src+"', sizingMethod='scale')";a.src=this.imageFolder+"spacer.gif";a.width=this.squareSize;a.height=this.squareSize},__getStyle:function(a,b){a=this.__getEl(a);if(document.defaultView&&document.defaultView.getComputedStyle){var c=null,d=document.defaultView.getComputedStyle(a,"");if(d){c=d[b];if(!c){d=document.defaultView.getComputedStyle(a,null);c=d.getPropertyCSSValue(b)}}if(c==null)c="";return a.style[b]||c}if(document.documentElement.currentStyle&&this.isMSIE){c=a.currentStyle?a.currentStyle[b]:
null;return a.style[b]||c}return a.style[b]},__clearTBodyRows:function(a){if(a){if(a.tagName.toLowerCase()=="table"){var b=a;a=a.getElementsByTagName("TBODY")[0]}else b=a.parentNode;var c=a.className,d=a.style.cssText;this.__discardElement(a);a=document.createElement("tbody");if(c)a.className=c;if(d)a.style.cssText=d;b.appendChild(a)}},__replaceTbody:function(a,b){var c=b.getElementsByTagName("TBODY");c.length>0&&this.__discardElement(c[0]);a="<tbody>"+a+"</tbody>";try{b.innerHTML+=a}catch(d){tokens=
b.outerHTML.split("</TABLE>");newHTML=tokens[0]+a+"</table>";b.outerHTML=newHTML}},__discardElement:function(a){a=this.__getEl(a);var b=document.getElementById("IELeakGBin");if(!b){b=document.createElement("DIV");b.id="IELeakGBin";b.style.display="none";document.getElementsByTagName("HEAD")[0].appendChild(b)}b.appendChild(a);b.innerHTML=""},__isArray:function(a){if(!a)return false;if(a.constructor.toString().indexOf("Array")!=-1)return true;return false},__addEventEl:function(a){this.eventElements[this.eventElements]=
a},__clearMemoryGarbage:function(){if(this.isMSIE){for(var a=0;a<this.eventElements.length;a++)try{var b=this.eventElements[a];b.onclick=null;b.onmousedown=null;b.onmousemove=null;b.onmouseout=null;b.onmouseover=null;b.onmouseup=null;b.onfocus=null;b.onblur=null;b.onkeydown=null;b.onkeypress=null;b.onkeyup=null;b.onselectstart=null;b.ondragstart=null;b.oncontextmenu=null;b=b.onscroll=null}catch(c){}window.onbeforeunload=null;window.onunload=null}},addEvent:function(a,b,c,d){d||(d="");if(a.attachEvent){if(typeof ChessWidgetEventFuncs[b+
c+d]!="function"){ChessWidgetEventFuncs[b+c+d]=function(){c.apply(window.event.srcElement)};a.attachEvent("on"+b,ChessWidgetEventFuncs[b+c+d])}a=null}else a.addEventListener(b,c,false);this.__addEventEl(a)},removeEvent:function(a,b,c,d){if(a.detachEvent){a.detachEvent("on"+b,ChessWidgetEventFuncs[b+c+d]);ChessWidgetEventFuncs[b+c+d]=null}else a.removeEventListener(b,c,false)},__getLeftPos:function(a){if(document.getBoxObjectFor)return document.getBoxObjectFor(a).x;for(var b=a.offsetLeft;(a=a.offsetParent)!=
null;)if(a.tagName!="HTML"){b+=a.offsetLeft;if(document.all)b+=a.clientLeft}return b},__getTopPos:function(a){if(document.getBoxObjectFor)return document.getBoxObjectFor(a).y;for(var b=a.offsetTop;(a=a.offsetParent)!=null;)if(a.tagName!="HTML"){b+=a.offsetTop-a.scrollTop;if(document.all)b+=a.clientTop}return b}};