var move;
n=144;
tileset=0;
layout=0;
f=1;
size();

function size()
{
topoffset=123;
leftoffset=200;
tileheight=41*f;
tilewidth=33*f;
tileoffset=10*f;
topoffset=topoffset+tileoffset;
leftoffset=leftoffset+tileoffset;
tileimgheight=44*f;
tileimgwidth=36*f;
layeroffset=-4*f;
markimgheight=49*f;
markimgwidth=41*f;
menuimgheight=22*f;
menuimgwidth1=33*f;
menuimgwidth2=36*f;
shadowstrength=5*f;
bgheight=351*f;
bgwidth=518*f;
copytopoffset=464;
copyleftoffset=671;
}

function preload()
{
count=0;
image=new Array ('bg.jpg','bamb1.gif','bamb2.gif','bamb3.gif','bamb4.gif','bamb5.gif','bamb6.gif','bamb7.gif','bamb8.gif','bamb9.gif','circ1.gif','circ2.gif','circ3.gif','circ4.gif','circ5.gif','circ6.gif','circ7.gif','circ8.gif','circ9.gif','numb1.gif','numb2.gif','numb3.gif','numb4.gif','numb5.gif','numb6.gif','numb7.gif','numb8.gif','numb9.gif','wind1.gif','wind2.gif','wind3.gif','wind4.gif','drag1.gif','drag2.gif','drag3.gif','flow1.gif','flow2.gif','flow3.gif','flow4.gif','seas1.gif','seas2.gif','seas3.gif','seas4.gif','bamb1a.gif','bamb2a.gif','bamb3a.gif','bamb4a.gif','bamb5a.gif','bamb6a.gif','bamb7a.gif','bamb8a.gif','bamb9a.gif','circ1a.gif','circ2a.gif','circ3a.gif','circ4a.gif','circ5a.gif','circ6a.gif','circ7a.gif','circ8a.gif','circ9a.gif','numb1a.gif','numb2a.gif','numb3a.gif','numb4a.gif','numb5a.gif','numb6a.gif','numb7a.gif','numb8a.gif','numb9a.gif','wind1a.gif','wind2a.gif','wind3a.gif','wind4a.gif','drag1a.gif','drag2a.gif','drag3a.gif','flow1a.gif','flow2a.gif','flow3a.gif','flow4a.gif','seas1a.gif','seas2a.gif','seas3a.gif','seas4a.gif','mark.gif','new.gif','tileset.gif','layout.gif','restart.gif','undo.gif','moves.gif','hint.gif','zoom.gif','help.gif','faq.gif','info.gif','email.gif');
picture=new Array(image.length);
for (i=0;i<image.length;i++)
{
picture[i]=new Image();
picture[i].onload=loadcheck;
picture[i].src=image[i];
}
}

function loadcheck()
{
count++;
percent=Math.round(count/image.length*100);
if (count>0&&count<image.length)
{
display="<table cellspacing=\"0\" cellpadding=\"0\" style=\"width:518px;position:absolute;top:"+(topoffset-tileoffset)+";left:"+(leftoffset-tileoffset)+"\"><tr><td height=\"24\" width=\""+(percent*5.18)+"\" style=\"background-color:#80895c\">&nbsp;<\/td><td height=\"24\" width=\""+(100*5.18-percent*5.18)+"\" style=\"background-color:#B6B08C\">&nbsp;<\/td><\/tr><\/table><font style=\"font-family:Arial,Helvetica,sans-serif;font-size:14pt;white-space:nowrap;position:absolute;top:"+(topoffset-tileoffset+1)+";left:"+(leftoffset-tileoffset)+"\">&nbsp;Loading...&nbsp;"+percent+"%<\/font>";
document.getElementById("screen").innerHTML=display;
}
else setup();
}


function select(i,face)
{
i=i-120;
suggest=0;
test(i);
if (cond)
{
if (move==1)select2(i,face);
else select1(i,face);
}
else noselect();
}

function noselect()
{
message="Tile is not free!";
mark[k]="";
move=0;
show();
wait();
}

function nomatch()
{
message="Tiles are different!";
mark[k]="";
move=0;
show();
wait();
}

function equal()
{
message="No tile selected.";
mark[k]="";
move=0;
show();
wait();
}

function select1(i,face)
{
i1sto=i;
facesto=face;
message="Tile selected...";
k=i;
mark[k]="<a href=\"javascript:void(0)\" onclick=\"equal()\"><img src=\"mark.gif\"style=\"position:absolute;top:"+(offsetfact[k]*layeroffset+topoffset+tilefacty[k]*tileheight)+";left:"+(offsetfact[k]*layeroffset+leftoffset+tilefactx[k]*tilewidth)+"\" height=\""+markimgheight+"\" width=\""+markimgwidth+"\" border=\"0\" alt=\"\"><\/a>";
move=1;
showhelp=0;
showinfo=0;
question=0;
show();
}

function select2(i,face)
{
if (facesto!=face)nomatch();
else
{
i2sto=i;
ihistory[ihistory.length]=i1sto;
ihistory[ihistory.length]=i2sto;
tilehistory[tilehistory.length]=tile[i1sto];
tilehistory[tilehistory.length]=tile[i2sto];
tile[i1sto]=notile[i1sto];
tile[i2sto]=notile[i2sto];
message="Selected tiles match!";
mark[k]="";
move=0;
back++;
show();
counter-=2;
wait();
}
}

function shuffle()
{
randomnumber=new Array(n);
for (i=0;i<n;i++)
{
random=parseInt(Math.random()*(i+1));
randomnumber[i]=randomnumber[random];
randomnumber[random]=i;
}
}

function setup()
{
counter=n;
message="Game ready: "+n+" tiles are set up.";
move=0;
showhelp=0;
showinfo=0;
question=0;
k=0;
suggest=0;
back=0;
tile=new Array(n);
notile=new Array(n);
mark=new Array(n);
value=new Array(n);
ihistory=new Array();
tilehistory=new Array();
fig=new Array(n);
tilevalue=new Array(10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,22,22,23,23,23,23,24,24,24,24,25,25,25,25,26,26,26,26,27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,32,32,32,32,33,33,33,33,34,34,34,34,35,35,35,35,36,36,36,36,37,37,37,37,38,38,38,38,39,39,39,39,40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,44,44,44,44,45,45,45,45);
tileface=new Array('circ1','circ1','circ1','circ1','circ2','circ2','circ2','circ2','circ3','circ3','circ3','circ3','circ4','circ4','circ4','circ4','circ5','circ5','circ5','circ5','circ6','circ6','circ6','circ6','circ7','circ7','circ7','circ7','circ8','circ8','circ8','circ8','circ9','circ9','circ9','circ9','bamb1','bamb1','bamb1','bamb1','bamb2','bamb2','bamb2','bamb2','bamb3','bamb3','bamb3','bamb3','bamb4','bamb4','bamb4','bamb4','bamb5','bamb5','bamb5','bamb5','bamb6','bamb6','bamb6','bamb6','bamb7','bamb7','bamb7','bamb7','bamb8','bamb8','bamb8','bamb8','bamb9','bamb9','bamb9','bamb9','numb1','numb1','numb1','numb1','numb2','numb2','numb2','numb2','numb3','numb3','numb3','numb3','numb4','numb4','numb4','numb4','numb5','numb5','numb5','numb5','numb6','numb6','numb6','numb6','numb7','numb7','numb7','numb7','numb8','numb8','numb8','numb8','numb9','numb9','numb9','numb9','wind1','wind1','wind1','wind1','wind2','wind2','wind2','wind2','wind3','wind3','wind3','wind3','wind4','wind4','wind4','wind4','drag1','drag1','drag1','drag1','drag2','drag2','drag2','drag2','drag3','drag3','drag3','drag3','seas1','seas2','seas3','seas4','flow1','flow2','flow3','flow4');
shuffle();
for (i=0;i<n;i++)
{
tile[i]="<a href=\"javascript:void(0)\" onclick=\"select("+(randomnumber[i]+120)+","+tilevalue[i]+")\"><img src=\""+tileface[i];
notile[i]="";
mark[i]="";
value[i]=(randomnumber[i]+120)*1000+tilevalue[i];
}

if (tileset==1)
{
for (i=0;i<n;i++)
tile[i]=tile[i]+"a";
}
else if (tileset==2)
{
for (i=0;i<n;i++)
tile[i]=tile[i]+"b";
}

tile.sort();
value.sort();
tilepos=".gif\" style=\"filter:progid:dxImageTransform.Microsoft.Shadow(color=#6B5231,direction=135,enabled=true,strength="+shadowstrength+");position:absolute;top:";
if (layout==1) layout1();
else if (layout==2) layout2();
else if (layout==3) layout3();
else if (layout==4) layout4();
else if (layout==5) layout5();
else if (layout==6) layout6();
else layout0();
for (i=0;i<n;i++)
tile[i]=tile[i]+tilepos+(offsetfact[i]*layeroffset+topoffset+tilefacty[i]*tileheight)+";left:"+(offsetfact[i]*layeroffset+leftoffset+tilefactx[i]*tilewidth)+"\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" border=\"0\" alt=\"\"><\/a>";
background="<img src=\"bg.jpg\" height=\""+bgheight+"\" width=\""+bgwidth+"\" style=\"position:absolute;top:"+(topoffset-tileoffset)+";left:"+(leftoffset-tileoffset)+"\" alt=\"\">";
copyright="<font style=\"font-family:Arial,Helvetica,sans-serif;font-size:7pt;white-space:nowrap;position:absolute;top:"+copytopoffset+";left:"+copyleftoffset+"\">&copy; 2010 twb<\/font>";
menu="<br><br><a href=\"javascript:void(0)\" onclick=\"setup()\"><img src=\"new.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Sets up new game\"><\/a><a href=\"javascript:void(0)\" onclick=\"settileset()\"><img src=\"tileset.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Changes tileset\"><\/a><a href=\"javascript:void(0)\" onclick=\"setlayout()\"><img src=\"layout.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Changes layout\"><\/a><a href=\"javascript:void(0)\" onclick=\"restart()\"><img src=\"restart.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Restarts same game\"><\/a><a href=\"javascript:void(0)\" onclick=\"undo()\"><img src=\"undo.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Withdraws last move\"><\/a><a href=\"javascript:void(0)\" onclick=\"moves()\"><img src=\"moves.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Displays number of possible moves\"><\/a><a href=\"javascript:void(0)\" onclick=\"hint()\"><img src=\"hint.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Shows possible moves\"><\/a><a href=\"javascript:void(0)\" onclick=\"zoom()\"><img src=\"zoom.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Zooms game in/out\"><\/a><a href=\"javascript:void(0)\" onclick=\"help()\"><img src=\"help.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Displays rules of the game\"><\/a><a href=\"javascript:void(0)\" onclick=\"faq()\"><img src=\"faq.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Displays frequently asked questions\"><\/a><a href=\"javascript:void(0)\" onclick=\"info()\"><img src=\"info.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth1+"\" border=\"0\" alt=\"\" title=\"Displays game information\"><\/a><a href=\"mailto:thomas.weibel@bluewin.ch\"><img src=\"email.gif\" height=\""+menuimgheight+"\" width=\""+menuimgwidth2+"\" border=\"0\" alt=\"\" title=\"Sends e-mail to the author\"><\/a>";
show();
wait();
}

function layout0()
{
offsetfact=new Array(4,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
tilefacty=new Array(3.5,3,3,4,4,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3.5,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,3.5,3.5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7);
tilefactx=new Array(6.5,6,7,6,7,5,6,7,8,5,6,7,8,5,6,7,8,5,6,7,8,4,5,6,7,8,9,4,5,6,7,8,9,4,5,6,7,8,9,4,5,6,7,8,9,4,5,6,7,8,9,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,10,11,12,3,4,5,6,7,8,9,10,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12,13,14,2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,11,12,4,10);
}

function layout1()
{
offsetfact=new Array (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3);
tilefacty=new Array (0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,0.5,0.5,0.5,0.5,1,3,4,4,5,5,6.5,6.5,6.5,6.5,7,4,5);
tilefactx=new Array (1,2,3,4,10,11,12,13,1,2,3,4,6.5,7.5,10,11,12,13,3,4,5,6,7,8,9,10,11,0.5,1.5,5,6,7,8,9,12.5,13.5,0.5,4.5,5.5,6.5,7.5,8.5,9.5,13.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,0.5,1.5,2.5,3.5,5.5,6.5,7.5,8.5,10.5,11.5,12.5,13.5,0.5,1.5,2.5,3.5,6,7,8,10.5,11.5,12.5,13.5,2,3,4,10,11,12,2,3,4,6.5,7.5,10,11,12,4,10,0.5,1.5,6,7,8,12.5,13.5,0.5,5.5,6.5,7.5,8.5,13.5,4.5,5.5,6.5,7.5,8.5,9.5,1.5,2.5,3.5,10.5,11.5,12.5,1.5,2.5,3.5,6,7,8,10.5,11.5,12.5,2.5,3.5,10.5,11.5,7,7,6.5,7.5,6.5,7.5,2,3,11,12,7,7,7);
}

function layout2()
{
offsetfact=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4);
tilefacty=new Array(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,0,0,0,0,0,1,1,1,1,2,2,2,3,3,4,5,6,6,7,7,7,0,0,0,1,1,2,7,0);
tilefactx=new Array(2,3,4,5,6,7,8,9,10,2,3,4,5,6,7,8,9,12,2,3,4,5,6,7,8,11,12,2,3,4,5,6,7,10,11,12,2,3,4,5,6,9,10,11,12,2,3,4,5,8,9,10,11,12,2,3,4,7,8,9,10,11,12,2,3,6,7,8,9,10,11,12,2,3,4,5,6,7,8,2,3,4,5,6,7,2,3,4,5,6,2,3,4,5,12,2,3,4,11,12,2,3,10,11,12,2,9,10,11,12,8,9,10,11,12,2,3,4,5,6,2,3,4,5,2,3,4,2,3,2,12,11,12,10,11,12,2,3,4,2,3,2,12,2);
}

function layout3()
{
offsetfact=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3);
tilefacty=new Array(0,0,0,1,1,2,2,2,5,5,5,6,6,7,7,7,1.5,1.5,1.5,1.5,1.5,2.5,2.5,3.5,3.5,4.5,4.5,5.5,5.5,5.5,5.5,5.5,0,0,0,1,1,2,2,2,5,5,5,6,6,7,7,7,0,0,0,1,1,2,2,2,5,5,5,6,6,7,7,7,1.5,1.5,1.5,1.5,1.5,2.5,2.5,3.5,3.5,4.5,4.5,5.5,5.5,5.5,5.5,5.5,0,0,0,1,1,2,2,2,5,5,5,6,6,7,7,7,0,0,0,1,1,2,2,2,5,5,5,6,6,7,7,7,0,0,0,1,1,2,2,2,5,5,5,6,6,7,7,7,0,0,2,2,5,5,7,7,0,0,2,2,5,5,7,7);
tilefactx=new Array(2,3,4,2,4,2,3,4,2,3,4,2,4,2,3,4,5,6,7,8,9,5,9,5,9,5,9,5,6,7,8,9,10,11,12,10,12,10,11,12,10,11,12,10,12,10,11,12,2,3,4,2,4,2,3,4,2,3,4,2,4,2,3,4,5,6,7,8,9,5,9,5,9,5,9,5,6,7,8,9,10,11,12,10,12,10,11,12,10,11,12,10,12,10,11,12,2,3,4,2,4,2,3,4,2,3,4,2,4,2,3,4,10,11,12,10,12,10,11,12,10,11,12,10,12,10,11,12,2,4,2,4,2,4,2,4,10,12,10,12,10,12,10,12);
}

function layout4()
{
offsetfact=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
tilefacty=new Array(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7);
tilefactx=new Array(3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11);
}

function layout5()
{
offsetfact=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5);
tilefacty=new Array(1,1,2,2,1,1,2,2,1,1,2,2,5,5,6,6,5,5,6,6,5,5,6,6,1,1,2,2,1,1,2,2,1,1,2,2,5,5,6,6,5,5,6,6,5,5,6,6,1,1,2,2,1,1,2,2,1,1,2,2,5,5,6,6,5,5,6,6,5,5,6,6,1,1,2,2,1,1,2,2,1,1,2,2,5,5,6,6,5,5,6,6,5,5,6,6,1,1,2,2,1,1,2,2,1,1,2,2,5,5,6,6,5,5,6,6,5,5,6,6,1,1,2,2,1,1,2,2,1,1,2,2,5,5,6,6,5,5,6,6,5,5,6,6);
tilefactx=new Array(2,3,2,3,6,7,6,7,10,11,10,11,3,4,3,4,7,8,7,8,11,12,11,12,2,3,2,3,6,7,6,7,10,11,10,11,3,4,3,4,7,8,7,8,11,12,11,12,2,3,2,3,6,7,6,7,10,11,10,11,3,4,3,4,7,8,7,8,11,12,11,12,2,3,2,3,6,7,6,7,10,11,10,11,3,4,3,4,7,8,7,8,11,12,11,12,2,3,2,3,6,7,6,7,10,11,10,11,3,4,3,4,7,8,7,8,11,12,11,12,2,3,2,3,6,7,6,7,10,11,10,11,3,4,3,4,7,8,7,8,11,12,11,12);
}

function show()
{
title="<font style=\"font-family:Arial,Helvetica,sans-serif;font-size:24pt;white-space:nowrap;position:absolute;top:"+66+";left:"+(leftoffset+tilewidth)+"\">Mahjongg Solitaire<\/font>"+background+copyright;
for (i=0;i<n;i++)fig[i]=tile[i]+mark[i];
if (layout==0) display=title+fig[57]+fig[58]+fig[59]+fig[60]+fig[61]+fig[62]+fig[63]+fig[64]+fig[65]+fig[66]+fig[67]+fig[68]+fig[69]+fig[70]+fig[71]+fig[72]+fig[73]+fig[74]+fig[75]+fig[76]+fig[77]+fig[78]+fig[79]+fig[80]+fig[81]+fig[82]+fig[83]+fig[84]+fig[85]+fig[86]+fig[87]+fig[88]+fig[89]+fig[90]+fig[91]+fig[92]+fig[93]+fig[94]+fig[95]+fig[96]+fig[97]+fig[98]+fig[99]+fig[100]+fig[101]+fig[102]+fig[103]+fig[104]+fig[105]+fig[106]+fig[107]+fig[108]+fig[109]+fig[110]+fig[111]+fig[112]+fig[113]+fig[114]+fig[115]+fig[116]+fig[117]+fig[118]+fig[119]+fig[120]+fig[121]+fig[122]+fig[123]+fig[124]+fig[125]+fig[126]+fig[127]+fig[128]+fig[129]+fig[130]+fig[131]+fig[132]+fig[133]+fig[134]+fig[135]+fig[136]+fig[137]+fig[138]+fig[139]+fig[140]+fig[141]+fig[142]+fig[143]+fig[21]+fig[22]+fig[23]+fig[24]+fig[25]+fig[26]+fig[27]+fig[28]+fig[29]+fig[30]+fig[31]+fig[32]+fig[33]+fig[34]+fig[35]+fig[36]+fig[37]+fig[38]+fig[39]+fig[40]+fig[41]+fig[42]+fig[43]+fig[44]+fig[45]+fig[46]+fig[47]+fig[48]+fig[49]+fig[50]+fig[51]+fig[52]+fig[53]+fig[54]+fig[55]+fig[56]+fig[5]+fig[6]+fig[7]+fig[8]+fig[9]+fig[10]+fig[11]+fig[12]+fig[13]+fig[14]+fig[15]+fig[16]+fig[17]+fig[18]+fig[19]+fig[20]+fig[1]+fig[2]+fig[3]+fig[4]+fig[0]+"<table width=\""+(tilewidth*12+3)+"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"position:absolute;top:"+(topoffset+tileheight*9)+";left:"+(leftoffset+tilewidth)+"\"><tr><td style=\"font-family:Arial,Helvetica,sans-serif;font-size:14pt\">"+message+"<\/td><\/tr><tr><td>"+menu+"<\/td><\/tr><\/table>";

else display=title+fig[0]+fig[1]+fig[2]+fig[3]+fig[4]+fig[5]+fig[6]+fig[7]+fig[8]+fig[9]+fig[10]+fig[11]+fig[12]+fig[13]+fig[14]+fig[15]+fig[16]+fig[17]+fig[18]+fig[19]+fig[20]+fig[21]+fig[22]+fig[23]+fig[24]+fig[25]+fig[26]+fig[27]+fig[28]+fig[29]+fig[30]+fig[31]+fig[32]+fig[33]+fig[34]+fig[35]+fig[36]+fig[37]+fig[38]+fig[39]+fig[40]+fig[41]+fig[42]+fig[43]+fig[44]+fig[45]+fig[46]+fig[47]+fig[48]+fig[49]+fig[50]+fig[51]+fig[52]+fig[53]+fig[54]+fig[55]+fig[56]+fig[57]+fig[58]+fig[59]+fig[60]+fig[61]+fig[62]+fig[63]+fig[64]+fig[65]+fig[66]+fig[67]+fig[68]+fig[69]+fig[70]+fig[71]+fig[72]+fig[73]+fig[74]+fig[75]+fig[76]+fig[77]+fig[78]+fig[79]+fig[80]+fig[81]+fig[82]+fig[83]+fig[84]+fig[85]+fig[86]+fig[87]+fig[88]+fig[89]+fig[90]+fig[91]+fig[92]+fig[93]+fig[94]+fig[95]+fig[96]+fig[97]+fig[98]+fig[99]+fig[100]+fig[101]+fig[102]+fig[103]+fig[104]+fig[105]+fig[106]+fig[107]+fig[108]+fig[109]+fig[110]+fig[111]+fig[112]+fig[113]+fig[114]+fig[115]+fig[116]+fig[117]+fig[118]+fig[119]+fig[120]+fig[121]+fig[122]+fig[123]+fig[124]+fig[125]+fig[126]+fig[127]+fig[128]+fig[129]+fig[130]+fig[131]+fig[132]+fig[133]+fig[134]+fig[135]+fig[136]+fig[137]+fig[138]+fig[139]+fig[140]+fig[141]+fig[142]+fig[143]+"<table width=\""+(tilewidth*12+3)+"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"position:absolute;top:"+(topoffset+tileheight*9)+";left:"+(leftoffset+tilewidth)+"\"><tr><td style=\"font-family:Arial,Helvetica,sans-serif;font-size:14pt\">"+message+"<\/td><\/tr><tr><td>"+menu+"<\/td><\/tr><\/table>";
document.getElementById("screen").innerHTML=display;
}

function wait()
{
showhelp=0;
showinfo=0;
question=0;
if (counter!=0) message="Score: "+(n-counter);
else message="Score: "+(n-counter)+" &#150; congratulations! You win!";
setTimeout('show()',2000);
}

function help()
{
if (showhelp==0)
{
showhelp=1;
message="Mahjongg Solitaire, also called Taipei or Shanghai, is the web adaptation of an old chinese board game. The objective is to remove all "+n+" tiles from the board; for each pair of tiles removed you will get two points.<p>The rules are simple:<\/p><p>Starting from the sides, or from the central tile at the top of the pile, remove tiles by clicking on two equal symbols. If the tiles are identical, they will disappear, and your score will rise.<\/p><p>Removeable tiles always must be free on their left or right side. If a tile sits between two tiles on the same level, it cannot be selected.<\/p><p><img src=\"seas1.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"seas2.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"seas3.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"seas4.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\">&nbsp;&nbsp;<img src=\"flow1.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"flow2.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"flow3.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"flow4.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><br><img src=\"seas1a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"seas2a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"seas3a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"seas4a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\">&nbsp;&nbsp;<img src=\"flow1a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"flow2a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"flow3a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><img src=\"flow4a.gif\" height=\""+tileimgheight+"\" width=\""+tileimgwidth+"\" alt=\"\"><br>Note: The four tiles showing season symbols or queens (above, left) match even if they are different; the four flower or king tiles (above, right) match respectively.<\/p><p>Options:<\/p><p><ul><li>New: sets up a new game.<\/li><li>Tileset: sets up a new game using a different tileset.<\/li><li>Layout: sets up a new game using a different layout.<\/li><li>Restart: restarts the current game.<\/li><li>Undo: withdraws your moves one by one.<\/li><li>Moves: displays the number of currently possible moves.<\/li><li>Hints: shows currently possible moves one by one.<\/li><li>Zoom: zooms the game in or out.<\/li><li>Help: displays the rules of the game.<\/li><li>FAQ: gives answers to frequently asked questions.<\/li><li>Info: displays game information and version history.<\/li><li>Sudoku: Opens Sudoku online game.<\/li><li>Email: sends an e-mail to the author.<\/li><\/ul><\/p>";
suggest=0;
mark[k]="";
move=0;
show();
}
else
{
message="Back to the game.";
show();
wait();
}
}

function info()
{
if (showinfo==0)
{
showinfo=1;
message="In mathematical terms, Mahjongg Solitaire is easily described. There are 144!/(4!)<sup>36<\/sup> different games, the probability that you will encounter the same game twice is 1/1.1394912*10<sup>200<\/sup>. As to the classic layout, the number of games that actually can be won cannot be calculated, yet experts estimate that good players win every third up to every second game.<p>This web version of Mahjongg Solitaire consists of only two files coded in dynamic HTML. In addition, images are used for the tiles, buttons and game background. To play the game no plugins are needed. There are no special system requirements, except for a DHTML compatible browser. If the javascript option is enabled, just click and play.<\/p><p>The idea for this game came from the www.the5k.org competition held between 2000 and 2002, the objective of which it was to encourage lean, efficient, functional, original and aesthetic web programming. A less than 5kb version of Mahjongg Solitaire took part in the 2002  contest.<\/p><p>Site history:<\/p><p><ul><li>2002, Jun 6: Mahjongg Solitaire v1.0, submission to the5k.org<\/li><li>2002, Sep 26: Mahjongg Solitaire v2.3 online<\/li><li>2006, Feb 4: Mahjongg Solitaire v3.0 online<\/li><li>2006, Aug 12: Sudoku online<\/li><li>2007, Dec 28: Reversi online<\/li><li>2008, Apr 18: The Same Game online<\/li><li>2008, Aug 28: Tower of Hanoi online<\/li><li>2008, Sep 16: Set online<\/li><li>2008, Nov 1: 10 million visitors<\/li><li>2009, Mar 31: Eleven High online<\/li><li>2009, May 23: Master Mind II online<\/li><li>2009, Jul 7: Rush Hour online<\/li><li>2009, Aug 4: Gravity online<\/li><li>2009, Aug 21: Maverick online<\/li><li>2009, Oct 04: Pairs online<\/li><li>2010, Feb 20: Snake online<\/li><li>2010, Mar 14: Tangram online<\/li><\/ul><\/p><p>Mahjongg Solitaire v3.01<br>Copyright &copy; 2002-2010 by Thomas Weibel<br>4102 Binningen, Switzerland<br>All rights reserved<p>Last update: Mar 14, 2010<br><br><\/p>";
suggest=0;
mark[k]="";
move=0;
show();
}
else
{
message="Back to the game.";
show();
wait();
}
}

function faq()
{
if (question==0)
{
question=1;
message="Frequently asked questions:<p><ul><li>Does Mahjongg Solitaire cost money?<p>No. Playing Mahjongg Solitaire is free.<br><br><\/p><\/li><li>Can every game be won?<p>No. The games are set up at random, which means that not every game can be finished. Mahjongg Solitaire is a true challenge.<br><br><\/p><\/li><li>Can I download the game?<p>No. Mahjongg Solitaire is no commercial software but a free online gaming offer.<br><br><\/p><\/li><li>Every time I click the tiles disappear and slowly reappear one by one. Is there something wrong with the game?<p>No. The problem is caused by your (non-default) web browser settings. If you are using the Microsoft Internet Explorer, click 'Extras', 'Internet options', 'Temporary internet files', 'Settings...'. Make sure that you have the 'Automatic' option checked in order to prevent your computer from re-reading all the images after every click.<br><br><\/p><\/li><li>Do I have to stay online in order to play Mahjongg Solitaire?<p>No. After the game has fully loaded you can disconnect from the internet and continue playing as long as you like.<\/p><\/li><\/ul><\/p>";
suggest=0;
mark[k]="";
move=0;
show();
}
else
{
message="Back to the game.";
show();
wait();
}
}

function undo()
{
if (ihistory.length==0)
{
message="Undo not possible!";
suggest=0;
mark[k]="";
move=0;
show();
wait();
}
else
{
restore();
message="Move undone.";
suggest=0;
mark[k]="";
move=0;
back--;
show();
counter+=2;
wait();
}
}

function restart()
{
if (ihistory.length==0)
{
message="Restart not possible!";
suggest=0;
mark[k]="";
move=0;
show();
wait();
}
else
{
for (i=0;i<back;i++) restore();
message="Game restarted.";
suggest=0;
mark[k]="";
move=0;
back=0;
show();
counter=n;
wait();
}
}

function restore()
{
tile[ihistory[ihistory.length-1]]=tilehistory[tilehistory.length-1];
tile[ihistory[ihistory.length-2]]=tilehistory[tilehistory.length-2];
ihistory.length=ihistory.length-2;
tilehistory.length=tilehistory.length-2;
}

function moves()
{
suggest=0;
remain=0;
calc=new Array();
free=new Array();
for (i=0;i<n;i++)
{
remaining(i);
if (cond)
free[free.length]=calc[i];
}
free.sort();
for (i=0;i<(free.length-1);i++)
{
if (free[i]==free[i+1]&&free[i]==free[i+2]&&free[i]==free[i+3])
{
remain+=2; i+=3;
}
if (free[i]==free[i+1]&&free[i]==free[i+2])
{
remain++; i+=2;
}
if (free[i]==free[i+1])
{
remain++; i++;
}
}
if (remain==0) message="Game over: No moves left!";
else message="Possible moves: "+remain;
mark[k]="";
move=0;
show();
wait();
}

function hint()
{
mark[k]="";
if (suggest==0)
{
calc=new Array();
free=new Array();
hints=new Array();
for (i=0;i<n;i++)
{
remaining(i);
if (cond)
free[free.length]=calc[i]*1000+i;
}
free.sort();
for (i=0;i<(free.length-1);i++)
{
if (parseInt(free[i]/1000)==parseInt(free[i+1]/1000))
{
hints[hints.length]=free[i]-parseInt(free[i]/1000)*1000;
hints[hints.length]=free[i+1]-parseInt(free[i+1]/1000)*1000;
}
}
if (hints.length==0)
{
message="Game over: No moves left!";
suggest=0;
}
else
{
remainmsg();
suggest=1;
}
}
else if (suggest==1)
{
remainmsg();
}
move=0;
show();
mark[hints[0]]="";
mark[hints[1]]="";
hints[hints.length]=hints[0];
hints[hints.length]=hints[1];
for (i=0;i<hints.length-2;i++)
hints[i]=hints[i+2];
hints.length=hints.length-2;
wait();
}

function remaining(i)
{
calc[i]=value[i]-parseInt(value[i]/1000)*1000;
test(i);
}

function remainmsg()
{
message="Possible move";
mark[hints[0]]="<img src=\"mark.gif\" style=\"position:absolute;top:"+(offsetfact[hints[0]]*layeroffset+topoffset+tilefacty[hints[0]]*tileheight)+";left:"+(offsetfact[hints[0]]*layeroffset+leftoffset+tilefactx[hints[0]]*tilewidth)+"\" height=\""+markimgheight+"\" width=\""+markimgwidth+"\" alt=\"\">";
mark[hints[1]]="<img src=\"mark.gif\" style=\"position:absolute;top:"+(offsetfact[hints[1]]*layeroffset+topoffset+tilefacty[hints[1]]*tileheight)+";left:"+(offsetfact[hints[1]]*layeroffset+leftoffset+tilefactx[hints[1]]*tilewidth)+"\" height=\""+markimgheight+"\" width=\""+markimgwidth+"\" alt=\"\">";
}

function test(i)
{
lr=(tile[i-1]==notile[i-1]||tile[i+1]==notile[i+1]);
none=(tile[i]!=notile[i]);
loop=new Array();
if (layout==0)
{
vari=new Array(10,11,14,15,28,29,30,31,34,35,36,37,40,41,42,43,46,47,48,49,70,71,72,73,74,75,79,80,81,82,83,84,91,92,93,94,95,96,103,104,105,106,107,108,116,117,118,119,120,121,125,126,127,128,129,130);
for (j=1;j<57;j++) loop[j]=(i==vari[j-1]&&(lr&&tile[j]==notile[j]));
cond=((i==0||i==5||i==8||i==9||i==12||i==13||i==16||i==17||i==20||i==21||i==26||i==27||i==32||i==33||i==38||i==39||i==44||i==45||i==50||i==51||i==56||i==57||i==68||i==69||i==76||i==77||i==86||i==87||i==113||i==114||i==123||i==124||i==131||i==132||i==143||
((i>=1&&i<=4)&&tile[0]==notile[0])||
((i==6||i==7||i==18||i==19||(i>=22&&i<=25)||(i>=52&&i<=55)||(i>=58&&i<=67)||i==78||i==85||(i>=88&&i<=90)||i==97||i==98||i==101||i==102||(i>=109&&i<=111)||i==115||i==122||i==133||(i>=134&&i<=142))&&lr)||
loop[1]||loop[2]||loop[3]||loop[4]||loop[5]||loop[6]||loop[7]||loop[8]||loop[9]||loop[10]||loop[11]||loop[12]||loop[13]||loop[14]||loop[15]||loop[16]||loop[17]||loop[18]||loop[19]||loop[20]||loop[21]||loop[22]||loop[23]||loop[24]||loop[25]||loop[26]||loop[27]||loop[28]||loop[29]||loop[30]||loop[31]||loop[32]||loop[33]||loop[34]||loop[35]||loop[36]||loop[37]||loop[38]||loop[39]||loop[40]||loop[41]||loop[42]||loop[43]||loop[44]||loop[45]||loop[46]||loop[47]||loop[48]||loop[49]||loop[50]||loop[51]||loop[52]||loop[53]||loop[54]||loop[55]||loop[56]||
(i==99&&(tile[98]==notile[98]||tile[112]==notile[112]))||
(i==100&&(tile[87]==notile[87]||tile[101]==notile[101]))||
(i==112&&((tile[99]==notile[99]&&tile[111]==notile[111])||tile[113]==notile[113])))&&none);
}

else if (layout==1)
{cond=(((i>126&&i<133)||i>136||i==91||i==92||i==93||i==94||i==98||i==99||i==100||i==105||i==95||i==97||i==101||i==104||i==106||i==111||i==121|i==123||i==0||i==8||i==7||i==17||i==18||i==26||i==29||i==33||i==37||i==42||i==44||i==53||i==54||i==66||i==65||i==76||i==58||i==61||
((i==133||i==134)&&tile[142]==notile[142])||
((i==135||i==136)&&tile[143]==notile[143])||
((i==77||i==83)&&tile[127]==notile[127])||
((i==79||i==85)&&tile[128]==notile[128])||
((i==78||i==84)&&lr&&tile[127]==notile[127]&&tile[128]==notile[128])||
((i==86||i==87)&&tile[131]==notile[131])||
((i==80||i==88)&&tile[129]==notile[129])||
((i==82||i==90)&&tile[130]==notile[130])||
((i==81||i==89)&&lr&&tile[129]==notile[129]&&tile[130]==notile[130])||
((i==86||i==87)&&tile[131]==notile[131])||
(i==96&&lr&&tile[132]==notile[132])||
((i==102||i==103)&&lr&&tile[i+31]==notile[i+31])||
((i==107||i==110)&&lr)||
((i==108||i==109)&&lr&&tile[i+27]==notile[i+27])||
((i==112||i==118)&&tile[137]==notile[137])||
((i==114||i==120)&&tile[138]==notile[138])||
((i==113||i==119)&&lr&&tile[137]==notile[137]&&tile[138]==notile[138])||
((i==115||i==124)&&tile[139]==notile[139])||
((i==117||i==126)&&tile[140]==notile[140])||
((i==116||i==125)&&lr&&tile[139]==notile[139]&&tile[140]==notile[140])||
(i==122&&tile[141]==notile[141])||
((i==1||i==2||i==5||i==6)&&lr&&tile[i+76]==notile[i+76])||
((i==9||i==10||i==15||i==16)&&lr&&tile[i+74]==notile[i+74])||
((i==3||i==4)&&tile[i+76]==notile[i+76])||
((i>10&&i<15)&&tile[i+74]==notile[i+74])||
(i==19&&lr&&tile[91]==notile[91])||
(i==25&&lr&&tile[92]==notile[92])||
((i>19&&i<25)&&lr)||
((i==27||i==28)&&tile[i+66]==notile[i+66])||
(i==36&&tile[100]==notile[100])||
((i==34||i==35)&&tile[i+64]==notile[i+64])||
(i==43&&tile[105]==notile[105])||
((i>29&&i<33)&&lr&&tile[i+65]==notile[i+65])||
((i>37&&i<42)&&lr&&tile[i+63]==notile[i+63])||
((i==45||i==52)&&lr)||
((i>45&&i<52)&&lr&&tile[i+60]==notile[i+60])||
((i==55||i==56)&&lr&&tile[i+57]==notile[i+57])||
((i==67||i==68||i==74||i==75)&&lr&&tile[i+51]==notile[i+51])||
(i==57&&tile[114]==notile[114])||
(i==69&&tile[120]==notile[120])||
((i==59||i==60)&&lr)||
((i==70||i==72)&&tile[i+51]==notile[i+51])||
(i==71&&tile[122]==notile[122])||
((i==63||i==64)&&lr&&tile[i+53]==notile[i+53])||
(i==62&&tile[115]==notile[115])||
(i==73&&tile[124]==notile[124]))&&none);
}

else if (layout==2)
{
cond=(
((i>137&&i<144)||i==119||i==123||(i>125&&i<134)||i==78||i==84||i==89||i==93||i==94||(i>96&&i<103)||i==105||i==106||i==110||i==8||i==16||i==17||(i>23&&i<27)||i==32||i==33||i==40||i==41||i==48||i==49||i==56||i==57||(i>62&&i<66)||
((i==136||i==135)&&tile[i+7]==notile[i+7])||
((i==137||i==118||i==122||i==125||i==134||i==77||i==83||i==88||i==92||i==96||i==103||i==107||i==111||i==7||i==15||i==23||i==31||i==34||i==39||i==42||i==47||i==50||i==55||i==58||i==66)&&lr)||
(i==115&&tile[136]==notile[136])||
((i==116||i==117)&&lr&&tile[i+21]==notile[i+21])||
(i==120&&tile[139]==notile[139])||
(i==121&&lr&&tile[140]==notile[140])||
(i==124&&tile[141]==notile[141])||
(i==72&&tile[115]==notile[115])||
((i>72&&i<77)&&lr&&tile[i+43]==notile[i+43])||
(i==79&&tile[120]==notile[120])||
((i>79&&i<83)&&lr&&tile[i+41]==notile[i+41])||
(i==85&&tile[124]==notile[124])||
((i==86||i==87)&&lr&&tile[i+39]==notile[i+39])||
(i==90&&tile[127]==notile[127])||
(i==91&&lr&&tile[128]==notile[128])||
(i==95&&tile[129]==notile[129])||
(i==104&&tile[130]==notile[130])||
(i==108&&lr&&tile[131]==notile[131])||
(i==109&&tile[132]==notile[132])||
((i==112||i==113)&&lr&&tile[i+21]==notile[i+21])||
(i==114&&tile[135]==notile[135])||
(i==0&&tile[72]==notile[72])||
((i>0&&i<7)&&lr&&tile[i+72]==notile[i+72])||
(i==9&&tile[79]==notile[79])||
((i>9&&i<15)&&lr&&tile[i+70]==notile[i+70])||
(i==18&&tile[85]==notile[85])||
((i>18&&i<23)&&lr&&tile[i+67]==notile[i+67])||
(i==27&&tile[90]==notile[90])||
((i>27&&i<31)&&lr&&tile[i+63]==notile[i+63])||
((i==35||i==36)&&tile[i+59]==notile[i+59])||
((i==37||i==38)&&lr&&tile[i+59]==notile[i+59])||
(i==43&&lr&&tile[98]==notile[98])||
((i==44||i==45)&&tile[i+55]==notile[i+55])||
(i==46&&lr&&tile[101]==notile[101])||
((i==51||i==52)&&lr&&tile[i+51]==notile[i+51])||
((i==53||i==54)&&tile[i+51]==notile[i+51])||
((i>58&&i<62)&&lr&&tile[i+47]==notile[i+47])||
(i==62&&tile[109]==notile[109])||
((i>66&&i<71)&&lr&&tile[i+43]==notile[i+43])||
(i==71&&tile[114]==notile[114])
)&&none);
}

else if (layout==3)
{
cond=(((
(i>127||i==99||i==100||i==107||i==108||i==115||i==116||i==123||i==124||(i>=69&&i<=74))||
(i==96&&tile[128]==notile[128])||(i==98&&tile[129]==notile[129])||(i==101&&tile[130]==notile[130])||(i==103&&tile[131]==notile[131])||
(i==104&&tile[132]==notile[132])||(i==106&&tile[133]==notile[133])||(i==109&&tile[134]==notile[134])||(i==111&&tile[135]==notile[135])||
(i==112&&tile[136]==notile[136])||(i==114&&tile[137]==notile[137])||(i==117&&tile[138]==notile[138])||(i==119&&tile[139]==notile[139])||
(i==120&&tile[140]==notile[140])||(i==122&&tile[141]==notile[141])||(i==125&&tile[142]==notile[142])||(i==127&&tile[143]==notile[143])||
(i==97&&lr)||(i==102&&lr)||(i==105&&lr)||(i==110&&lr)||(i==113&&lr)||(i==118&&lr)||(i==121&&lr)||(i==126&&lr)||
(((i==48||i==50||i==53||i==56||i==61||i==63||i==51||i==52||i==59||i==60)||((i==49||i==54||i==57||i==62)&&lr)||(i==55&&((tile[64]==notile[64]&&tile[69]==notile[69])||tile[54]==notile[54]))||(i==58&&((tile[73]==notile[73]&&tile[75]==notile[75])||tile[57]==notile[57])))&&tile[i+48]==notile[i+48])||
(((i==80||i==82||i==87||i==90||i==93||i==95||i==83||i==84||i==91||i==92)||((i==81||i==86||i==89||i==94)&&lr)||(i==85&&((tile[68]==notile[68]&&tile[70]==notile[70])||tile[86]==notile[86]))||(i==88&&((tile[74]==notile[74]&&tile[79]==notile[79])||tile[89]==notile[89])))&&tile[i+32]==notile[i+32])||
(i==64&&((tile[52]==notile[52]&&tile[55]==notile[55])||tile[65]==notile[65]))||
(i==68&&((tile[83]==notile[83]&&tile[85]==notile[85])||tile[67]==notile[67]))||
(i==75&&((tile[58]==notile[58]&&tile[60]==notile[60])||tile[76]==notile[76]))||
(i==79&&((tile[88]==notile[88]&&tile[91]==notile[91])||tile[78]==notile[78]))||
((i==65||i==66||i==67||i==76||i==77||i==78)&&lr)||
(((i==0||i==2||i==3||i==4||i==5||i==8||i==11||i==12||i==13||i==15||i==32||i==34||i==35||i==36||i==39||i==42||i==43||i==44||i==45||i==47)&&tile[i+48]==notile[i+48])||
((i==1||i==6||i==9||i==14||i==33||i==38||i==41||i==46)&&lr)||
(i==7&&((tile[16]==notile[16]&&tile[21]==notile[21])||tile[6]==notile[6]))||
(i==10&&((tile[25]==notile[25]&&tile[27]==notile[27])||tile[9]==notile[9]))||
(i==37&&((tile[20]==notile[20]&&tile[22]==notile[22])||tile[38]==notile[38]))||
(i==40&&((tile[26]==notile[26]&&tile[31]==notile[31])||tile[41]==notile[41]))||
(i==16&&((tile[4]==notile[4]&&tile[7]==notile[7])||tile[17]==notile[17]))||
(i==20&&((tile[35]==notile[35]&&tile[37]==notile[37])||tile[19]==notile[19]))||
(i==27&&((tile[10]==notile[10]&&tile[12]==notile[12])||tile[28]==notile[28]))||
(i==31&&((tile[40]==notile[40]&&tile[43]==notile[43])||tile[30]==notile[30]))||
((i==17||i==18||i==19||i==28||i==29||i==30)&&lr)||
(i>=21&&i<=26))&&tile[i+48]==notile[i+48]))&&none);
}

else if (layout==4)
{
cond=((((i==0||i==8||i==9||i==17||i==18||i==26||i==27||i==35||i==36||i==44||i==45||i==53||i==54||i==62||i==63||i==71)&&tile[i+72]==notile[i+72])||(i==72||i==80||i==81||i==89||i==90||i==98||i==99||i==107||i==108||i==116||i==117||i==125||i==126||i==134||i==135||i==143))&&none);
if ((((i>0&&i<8)||(i>9&&i<17)||(i>18&&i<26)||(i>27&&i<35)||(i>36&&i<44)||(i>45&&i<53)||(i>54&&i<62)||(i>63&&i<71))&&tile[i+n/2]==notile[i+n/2])&&none) cond=lr;
else if (((i>72&&i<80)||(i>81&&i<89)||(i>90&&i<98)||(i>99&&i<107)||(i>108&&i<116)||(i>117&&i<125)||(i>126&&i<134)||(i>135&&i<143))&&none) cond=lr;
}

else
{
cond=((
(i>119&&i<n)||
((i>=0&&i<120)&&tile[i+24]==notile[24]))&&tile[i]!=notile[i]);
}
}

function settileset()
{
tileset++;
if (tileset==2) tileset=0;
setup();
}

function setlayout()
{
layout++;
if (layout==6) layout=0;
setup();
}

function zoom()
{
if (f==1)
{
f++;
size();
copytopoffset=815;
copyleftoffset=1189;
setup();
}
else
{
f--;
size();
setup();
}
}

