//                             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 = "Most reasonable people and even many neuroscientists and philosophers assume that apes monkeys and other mammals with "
					+ "relatively large brains have conscious experience But it is worth recalling that some very smart humans notably "
					+ "Descartes have believed that all nonhuman animals are nonsentient automatons      "; // 6 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 = "MOSTREASONABLEPEOPLEANDEVENMANYNEUROSCIENTISTSANDPHILOSOPHERSASSUMETHATAPESMONKEYSANDOTHERMAMMALSWITHRELATIVELYLARGE"
					+ "BRAINSHAVECONSCIOUSEXPERIENCEBUTITISWORTHRECALLINGTHATSOMEVERYSMARTHUMANSNOTABLYDESCARTESHAVEBELIEVEDTHATALLNONHUMAN"
					+ "ANIMALSARENONSENTIENTAUTOMATONS";

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.
var aWurdz = new Array ("Hierophant",  "OmarKhayyam", "Resuscitates", "GibsonDesert",  "Annatto",  "NavalAcademy", "Thusness",  "Horrisonant", "Exculpates",  
						"Uranophobia", "NemeanGames",  "Disallowable", "Invaluable",  "Strontium",  "Carnivals", "OnTheLevel",  "Vehemently",   "ElephantsEar",  
						"Resentment", "Episcotister", "DaltonsLaw", "MachNumber", "Impassiveness", "Neathmost", "DominoTheory");

var sWurdzString = "HIEROPHANTOMARKHAYYAMRESUSCITATESGIBSONDESERTANNATTONAVALACADEMYTHUSNESSHORRISONANTEXCULPATESURANOPHOBIANEMEANGAMESDISALLOWABLE"
					+ "INVALUABLESTRONTIUMCARNIVALSONTHELEVELVEHEMENTLYELEPHANTSEARRESENTMENTEPISCOTISTERDALTONSLAWMACHNUMBERIMPASSIVENESSNEATHMOSTDOMINOTHEORY";

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("Chief Eleusinian priest" ,"Persian mathematician and poet (\"Rubaiyat\"; 1048-1131, 2 wds.)", 
						"Restores, revives",
						"Arid region containing Uluru (Ayer's Rock) (2 wds.)", "Red food coloring used in cheese", 
						"Annapolis institution (2 wds.)", "\"Why is this thus? What is the reason of this __?\" (Artemus Ward)",
						"Making an awful sound (rare)", "Removes blame, acquits", "Fear of heaven", 
						"One of the four panhellenic sports festivals (2 wds.)", "Like an illegal tax deduction", "Priceless", 
						"Metallic element, source of red color in fireworks","Fairs" , 
						"Honest, ethical (3 wds.)", 
						"Strongly, impassionately", "Large-leaved plant of the genus Alocasia (2 wds.)", 
						"Peevishness, outrage", "Opaque disk with an open wedge sector", "Total pressure is the sum of the partial pressures (2 wds.)",
						"Supersonic speed measure (2 wds.)", "Apathy","At bottom, poetically", 
						"Vietnam war rationalization (2 wds.)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 2, 1, 2, 1,   1, 2, 1, 1, 1,   2, 1, 1, 2, 1,   1, 1, 2, 1, 1,  2, 1, 1, 1, 1);
// 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 (68, 140, 215, 176, 35, 49, 156, 206, 40, 44, 55, 235, 20, 117, 78, 227, 123, 110, 177, 91, 65, 139, 39, 62, 33, 43, 
							143, 98, 202, 230, 169, 175, 74, 165, 106, 145, 54, 260, 47, 84, 241, 178, 73, 113, 99, 186, 31, 9, 61, 105, 252, 256, 
							26, 258, 107, 71, 111, 221, 159, 168, 48, 58, 229, 195, 255, 183, 133, 45, 261, 125, 238, 7, 205, 153, 240, 157, 148, 
							198, 225, 83, 219, 142, 248, 5, 136, 199, 64, 109, 56, 232, 70, 25, 60, 146, 89, 104, 120, 190, 17, 218, 171, 11, 249, 
							200, 242, 173, 179, 250, 118, 21, 114, 46, 93, 138, 129, 216, 42, 245, 69, 237, 223, 8, 97, 192, 209, 52, 19, 234, 244, 
							24, 6, 161, 228, 10, 116, 194, 102, 151, 259, 201, 127, 187, 67, 38, 254, 90, 130, 112, 181, 226, 51, 174, 94, 18, 121, 
							132, 247, 147, 167, 23, 162, 158, 207, 213, 222, 124, 13, 57, 210, 75, 115, 233, 86, 103, 80, 88, 211, 246, 14, 122, 28, 
							164, 41, 63, 79, 160, 59, 101, 66, 81, 135, 189, 3, 185, 203, 29, 149, 208, 72, 212, 134, 126, 1, 155, 150, 96, 166, 141, 
							34, 196, 236, 12, 217, 243, 231, 262, 95, 82, 152, 172, 239, 37, 100, 251, 184, 257, 193, 32, 154, 131, 92, 137, 180, 204, 
							36, 119, 214, 144, 77, 108, 170, 188, 128, 15, 253, 182, 50, 27, 85, 2, 220, 22, 76, 0, 163, 224, 16, 191, 87, 197, 53, 4, 30);
								
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 = 270;

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

var iPuzzleLeftCoord = iCluesLeftCoord + 470;	// 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 = '(John) Horgan: <a href="http://www.amazon.com/gp/product/0684865785?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0684865785" target="_blank">The Undiscovered Mind</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0684865785" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (How the Human Brain Defies Replication, Medication, and Explanation). '
					+'"Most reasonable people, and even many neuroscientists and philosophers, assume that apes, monkeys, and other mammals with relatively large brains have conscious experience. But it is worth recalling that some very smart humans, notably Descartes, have believed that all nonhuman animals are nonsentient automatons."';
					
						
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 = "23thnk";
