// Original:  Kien Caoxuan (kcaoxuan@caoxuan.com) 
// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com 
// This script has been heavily modified by ShondasAnimalCrackups.com
// This modified script is covered by the Creative Commons License (by,nc,sa)
// With Arbitration (by), Noncommercial (nc) and ShareAlike (sa)
// Version 20081003 


// Need to add Easy, Medium, Hard, which are 3X3 4X4 and 5X5 puzzles
Vis = ["hidden","visible"];

function GetDiv(divId,divY,divX,divW,divH,bCol,visb,zInd) {
bkCol=(bCol!="")?(";background:"+bCol):"";
// All start out as invisible when created
visb=0;

// Need a variable to NOT let TestMe() be called until NextGuess() has reset the 'clickable' flag
// If people click too fast it could mess up the game logic (which is based on OLD click not the new click...)

// CSS is now standard on all browsers, no check needed
Styl="<DIV name='"+divId+"' style='position:absolute;top:"+divY+";left:"+divX+";width:"+divW+";height:"+divH+bkCol+";visibility:"+Vis[visb]+";z-index:"+zInd+"'>"; 
document.writeln(Styl);
}

function EndDiv() {
document.writeln("</DIV>");
}

function resize_puzzle(){
   ind=0;
   for (rows = 0; rows < maxrows; rows++) {
      for (cols = 0; cols < maxcols; cols++) {
      ind++;
      corr[ind] = 0;
      picarr[ind] = 0;
      // Make the control invisible and reset its coordinates to new grid
      divob=document.getElementsByName( eval("'divTile"+ind+"'") )[0];
      divob.style.visibility='hidden';
      divob.style.left=cols*tilew;
      divob.style.top=rows*tileh;
      divob.style.visibility='visible';

      divob=document.getElementsByName( eval("'divBlankTop"+ind+"'" ) )[0];
      divob.style.left=cols*tilew;
      divob.style.top=rows*tileh;
      divob.style.visibility='hidden';
      }
   }

   // Now blank out any remaining tiles
   for( ind++; ind <= (maxboardrows * maxboardcols); ind++){
      corr[ind]=0;
      picarr[ind]=0;
      document.getElementsByName( eval("'divTile"+ind+"'") )[0].style.visibility='hidden';
      document.getElementsByName( eval("'divBlankTop"+ind+"'") )[0].style.visibility='hidden';
   }

   docob=document.getElementsByName('Control1')[0];
   docob.style.left=0;
   docob.style.top=maxrows*tileh;
   docob.style.width=maxcols*tilew;
   docob.style.visibility='visible';

   docob=document.getElementsByName('Control2')[0];
   docob.style.visibility='hidden';
   docob.style.left=0;
   docob.style.top=maxrows*tileh;
   docob.style.width=maxcols*tilew;

   docob=document.getElementsByName('divFindMe')[0];
   docob.style.left=maxcols*tilew;
   docob.style.top=maxrows*tileh;
   docob.style.visibility='visible';

   docob=document.getElementById('FindMe');
   docob.src="unknown.gif";

   docob=document.getElementsByName('gLevel')[0];
   docob.style.top=0;
   docob.style.left=maxcols*tilew;
   docob.style.visibility='visible';

   ScramblePics();
}

