//                             This file is copyright 2009 by Michael H. Dickman. All rights reserved.


// The quote, without punctuation but with spaces, hyphens, and capitalization. Used to display the blank grid and the grid with solution.
var sAcrostiString = "One illusion possibly the strongest of all is the one that makes us believe that we have a direct hold on reality "
					+ "The work of interpretation conducted by perception never comes to light and leaves no other trace than its "
					+ "final result       "; // 7 spaces have been added to the end.
						
var iASLen = sAcrostiString.length; // Length of quote including spaces and padding at end.

// This is the sAcrostiString, but all uppercase and without spaces (or hyphens). It is used to determine whether the puzzle has been solved. 
var sSolutionString = "ONEILLUSIONPOSSIBLYTHESTRONGESTOFALLISTHEONETHATMAKESUSBELIEVETHATWEHAVEADIRECTHOLDONREALITYTHEWORKOFINTERPRETATION"
					+ "CONDUCTEDBYPERCEPTIONNEVERCOMESTOLIGHTANDLEAVESNOOTHERTRACETHANITSFINALRESULT";

var iTotalLetters = sSolutionString.length; // Total number of letters (no spaces) in quote (and therefore Wurdz).

// Answers to clues, first letter of each word capitalized but no spaces or hyphens (letters and numbers only).
var aWurdz = new Array ("Nekton", "InkyCap", "Newts", "Ichabod", "OathsThatHe", "TenFold", "Hollerith", "Element", "SargassoSea", "Crofter", 
						"Idiot", "Epicene", "Novello", "Contort", "Eyesight", "Obviate", "FreeThrow", "Ivanhoe", "Luthier", "Laputa", "Urticated", 
						"Sandstone", "Illness", "Overtly", "Nimble", "Sputter");

var sWurdzString = "NEKTONINKYCAPNEWTSICHABODOATHSTHATHETENFOLDHOLLERITHELEMENTSARGASSOSEACROFTERIDIOTEPICENENOVELLOCONTORTEYESIGHTOBVIATEFREETHROW"
					+ "IVANHOELUTHIERLAPUTAURTICATEDSANDSTONEILLNESSOVERTLYNIMBLESPUTTER";

var aWhichClue = new Array (iTotalLetters);
// Given a position in the aWurdzAttempt array, which clue is it in? Zero-based counting. Used for keyboard navigation.

var aWhichLetter = new Array (iTotalLetters);
// Given a position in the aWurdzAttempt array, which letter of the wurd is it? ***One-based*** counting. Used for keyboard navigation.

						
var aClues = new Array("Aggregate of actively swimming aquatic organisms in a body of water", "Mushroom with gills that liquify (2 wds.)", 
					"\"The War With the __\" Capek (1936)", "\"Legend of Sleepy Hollow\" name", 
					"\"He hail\'d down __ was only mine\" (3 wds., A Midsummer Night\'s Dream, act I)", "Order of magnitude (hyph.)", 
					"He developed punch cards for the census", "Not a compound", "\"Wide __\" novel by Rhys (1966; 2 wds.)", 
					"\"The __ and the Laird\" McPhee (1970)", 
					"\"A member of a large and powerful tribe whose influence in human affairs has always been dominant and controlling.\" (Ambrose Bierce)", 
					"Referring or belonging to both sexes", "First woman surgeon general of the US", "Twist, bend out of shape", "Vision", "Prevent, remove", 
					"Foul consequence (2 wds.)", "Sir Walter Scott novel in which Robin Hood appears", "Guitar maker", 
					"Flying island from Gulliver\'s Travels", "Stung with nettles", "Sedimentary rock", "Ailment, malady", 
					"Publicly, without concealment", "Spry", "Emit forcibly in small particles");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 1, 1, 1, 2,   1, 1, 1, 1, 1,   4, 1, 1, 1, 1,   1, 1, 2, 1, 1,   1, 1, 1, 1, 1,  1  ); // 26 total
// How many lines each clue uses, given the current parameters. Must find by experiment at present. Used to dimension the clue text boxes.

var aGridAttempt = new Array(iTotalLetters);	// Holds letters for attempted solution. Blanks are represented by spaces.
var aWurdzAttempt = new Array(iTotalLetters);	// Ditto, except blanks are represented by underscores.

// The array below shows which grid square to go to from a given wurdz space, starting at zero.
var aWurdzToGrid = new Array (154, 59, 50, 169, 163, 177, 15, 102, 98, 91, 129, 87, 106, 183, 104, 66, 121, 161, 149, 77, 93, 72, 55, 0, 123, 
							147, 64, 30, 166, 13, 179, 20, 171, 92, 151, 2, 62, 56, 1, 100, 25, 185, 82, 39, 12, 34, 17, 187, 140, 182, 78, 175, 
							86, 4, 157, 48, 28, 136, 65, 180, 49, 97, 150, 176, 22, 14, 113, 188, 122, 33, 120, 170, 99, 181, 19, 40, 75, 8, 155, 
							89, 31, 111, 94, 11, 112, 172, 71, 117, 144, 42, 116, 60, 137, 88, 156, 83, 115, 41, 26, 47, 96, 107, 132, 76, 125, 51, 
							145, 133, 27, 63, 23, 9, 124, 138, 74, 153, 191, 21, 32, 128, 108, 139, 152, 79, 24, 164, 95, 178, 159, 110, 84, 68, 
							142, 130, 5, 119, 38, 45, 58, 67, 85, 57, 69, 126, 53, 90, 184, 6, 105, 109, 36, 141, 158, 165, 61, 118, 37, 46, 10, 73, 
							52, 174, 80, 114, 127, 3, 35, 81, 162, 173, 54, 29, 134, 70, 167, 186, 44, 148, 18, 135, 101, 143, 16, 190, 160, 7, 131, 
							189, 146, 103, 43, 168);
								
var aGridToWurdz = new Array (aWurdzToGrid.length); //This will map the grid squares (not counting spaces, as in aGridNumbers below) to the aWurdzAttempt array.
													// Initialized in initPuzzle(). Zero-based array.

var aGridNumbers = new Array (iASLen);	// This would be the way the grid is numbered in print. The spaces (and padding) will be represented by zero.
										//  Initialized in initPuzzle(). 
var aGridAttemptToGaps = new Array (iASLen);	// This maps the attempt string -without spaces- to the grid -with spaces-.
								
//****** The variables below are associated with placement of graphic items.
var iBoxAcross = 12;	// Taken from width of acrostic pdf, for example. Number of columns in acrostic.
var iBoxWidth = 25;
var iBoxHeight = 24;
var iBoxDown = Math.ceil(iASLen/iBoxAcross); // Calculates number of rows in puzzle grid.

var iCluesLeftCoord = 30;
var iCluesTopCoord = 100;

var iCluWidth = 240;
var iLineHeight = 23;
var iTotalCluesHeight = 0; // Calculated in initPuzzle.
var iPadFactor = 8;

var iPuzzleLeftCoord = iCluesLeftCoord + 490;	// Distance of puzzle grid from left side.
var iPuzzleTopCoord = iCluesTopCoord + 5;	// Distance of puzzle grid (and cluse and wurdz) from top.

var iMaxWurdzLength = 0;
var iUnderscoreWidth = 14;
var iWurdzHeight = 20;
var iWurdzLeftCoord = iCluesLeftCoord + iCluWidth + 10;
var iWurdzWidth = iPuzzleLeftCoord - iWurdzLeftCoord - 5; 
var iWurdzRightCoord = iWurdzLeftCoord + iWurdzWidth;
var iWurdzTop = iCluesTopCoord;
var iWurdzBottom = iWurdzTop + iTotalCluesHeight * iCluNum; // Will be recalculated later.

var iBoxSelected = 0;	// Which grid square(underscore) is selected?
var iGridLeft = iPuzzleLeftCoord + 2;
var iGridRight = iGridLeft + iBoxWidth * iBoxAcross;
var iGridTop = iPuzzleTopCoord + 4;
var iGridBottom = iGridTop + iBoxHeight * iBoxDown;
							
var sAuthorQuote = '(Jacques) Ninio: <a href="http://www.amazon.com/gp/product/0801437709?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0801437709" target="_blank">The Science of Illusions</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0801437709" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. '
					+'"One illusion, possibly the strongest of all, is the one that makes us believe that we have a direct hold on reality. The work of interpretation conducted by perception never comes to light and leaves no other trace than its final result."';
					
						
var iInstructionsTop = (iBoxHeight * iBoxDown) + iPuzzleTopCoord + 30; // Thirty pixels below the bottom of the puzzle.
var iInstructionsLeft = iPuzzleLeftCoord + 5;
var iInstructionsWidth = iBoxAcross * iBoxWidth; // Width of grid, approx.
var iInstructionsHeight = 50; // May need to be changed depending on puzzle.

var sPuzzleCode = "39seem";

