var isMSIE = /*@cc_on!@*/false;document.puzzle=null;function P3(){this.badSquares={};this.board={};this.mask={};this.solved=false;this.width=3;this.height=3;this.maximumValue=this.width*this.height;this.timer=0;this.startDate=null;this.endDate=null;for(var C=0;C<this.maximumValue;C++){for(var B=0;B<this.maximumValue;B++){this.board[C+","+B]=arguments[C*this.maximumValue+B]}}for(var A=this.maximumValue;A<arguments.length;A++){this.mask[arguments[A]]=1}}P3.prototype.tupleToID=function(A){var B=""+parseInt(A.substring(0,A.indexOf(",")),10)+":";B+=parseInt(A.substring(A.indexOf(",")+1),10);return B};P3.prototype.IDToTuple=function(B){var A=parseInt(B.substring(0,B.indexOf(":")),10)+",";A+=parseInt(B.substring(B.indexOf(":")+1),10);return A};P3.prototype.cleanClassName=function(){var A=arguments[0];var B=A;if(A.indexOf("active")!=-1){B=A.substring(0,A.indexOf("active"))}return B};P3.prototype.setup=function(){this.startDate=new Date();for(var D=0;D<this.maximumValue;D++){for(var B=0;B<this.maximumValue;B++){var A=D+","+B;var C=document.getElementById(this.tupleToID(A));C.className=this.cleanClassName(C.className);if(this.mask[A]){C.style.color="#000";if(isMSIE){C.innerText=this.board[A]}C.textContent=this.board[A];C.onclick=null}else{C.style.color="#3b7bd4";if(isMSIE){C.innerText=" "}C.textContent=" ";C.onclick=function(){document.puzzle.choose(this.id)};C.className=C.className+" active"}}}document.getElementById("board-options").style.display="none"};P3.prototype.choose=function(B){var A=document.getElementById("chooser");A.style.position="absolute";A.style.zIndex="1";A.style.display="block";this.id=B;document.getElementById("board-screen").style.display="block";document.getElementById(B).className="boardchoose active"};P3.prototype.options=function(A){var B=document.getElementById("board-options");if(B.style.display=="block"){B.style.display="none"}else{B.style.display="block"}B.getElementsByTagName("h3")[0].innerHTML=A};P3.prototype.gameOver=function(){this.endDate=new Date();this.timer=parseInt((this.endDate-this.startDate)/1000,10);this.options("Congradulations!<br /><p>You solved this puzzle in<br />"+this.timer+" seconds.</p>")};P3.prototype.isSolved=function(){return this.solved};P3.prototype.setValue=function(E,G){if(isMSIE){document.getElementById(E).innerText=G}document.getElementById(E).textContent=G;if(G){var C=this.badSquares;this.badSquares={};this.validate("0,0");this.validate("1,3");this.validate("2,6");this.validate("3,1");this.validate("4,4");this.validate("5,7");this.validate("6,2");this.validate("7,5");this.validate("8,8");for(var F in C){if(!this.badSquares[F]){var H=this.tupleToID(F);document.getElementById(H).style.color="#3b7bd4"}}var A=0;for(var F in this.badSquares){A++;if(!C[F]){var H=this.tupleToID(F);document.getElementById(H).style.color="#a90e24"}}if(A===0){var I=true;for(var D=0;D<this.maximumValue;D++){for(var B=0;B<this.maximumValue;B++){var F=D+","+B;if(isMSIE){if(this.board[F]!=document.getElementById(this.tupleToID(F)).innerText){I=false}}if(this.board[F]!=document.getElementById(this.tupleToID(F)).textContent){I=false}}}if(I){this.solved=true;this.gameOver()}}}};P3.prototype.validate=function(F){var C=parseInt(F.substring(0,F.indexOf(",")),10);var I=parseInt(F.substring(F.indexOf(",")+1),10);var G=[[3,6],[4,7],[5,8],[0,6],[1,7],[2,8],[0,3],[1,4],[2,5]];var H=[[1,2],[0,2],[0,1],[4,5],[3,5],[3,4],[7,8],[6,8],[6,7]];this.validateTuple(C+",0",C+",1",C+",2",C+",3",C+",4",C+",5",C+",6",C+",7",C+",8");var E=H[C];var B=H[I];this.validateTuple(C+","+I,C+","+B[0],C+","+B[1],E[0]+","+B[0],E[0]+","+B[1],E[1]+","+B[0],E[1]+","+B[1],E[0]+","+I,E[1]+","+I);var A=G[C];var D=G[I];this.validateTuple(C+","+I,C+","+D[0],C+","+D[1],A[0]+","+D[0],A[0]+","+D[1],A[1]+","+D[0],A[1]+","+D[1],A[0]+","+I,A[1]+","+I)};P3.prototype.validateTuple=function(){var B=[];for(var F=0;F<arguments.length;F++){var E=document.getElementById(this.tupleToID(arguments[F]));if(isMSIE){if(E&&E.innerText&&E.innerText!=" "){var G=E.innerText;if(!B[G]){B[G]=[]}B[G][B[G].length]=E}}else{if(E&&E.textContent&&E.textContent!=" "){var G=E.textContent;if(!B[G]){B[G]=[]}B[G][B[G].length]=E}}}for(var F in B){if(B[F].length>1){for(var C=0;C<B[F].length;C++){var D=B[F][C];var A=this.IDToTuple(D.id);if(!this.mask[A]){this.badSquares[A]++}}}}};var lastGameIndex=-1;function setupPuzzle(){var gameIndex=Math.floor(Math.random()*_1.length);while(gameIndex==lastGameIndex){gameIndex=Math.floor(Math.random()*_1.length)}lastGameIndex=gameIndex;document.puzzle=eval(_1[gameIndex]);document.puzzle.setup()}function reStart(A){if(A&&document.puzzle){document.puzzle.options("Restart this puzzle?")}else{document.puzzle.setup()}}function newStart(A){if(A&&document.puzzle){document.puzzle.options("Start a new Puzzle?")}else{setupPuzzle()}}function edit(){document.puzzle.options("Game Options")}function skip(){var A=parent.document.getElementById("chooser");A.style.display="none";A.style.zIndex="-1";document.getElementById(document.puzzle.id).className="active";document.getElementById("board-screen").style.display="none"}function pick(A){skip();document.puzzle.setValue(document.puzzle.id,A);document.getElementById(document.puzzle.id).className="active";document.getElementById("board-screen").style.display="none"}function appleDevice(){return(navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i))}function snip_addbar(){window.scrollTo(0,1);window.scrollTo(0,0)}if(document.addEventListener){if(appleDevice()){addEventListener("load",function(){setTimeout(snip_addbar,0)},false)}addEventListener("load",function(){setupPuzzle()},false)};