//                             This file is copyright 2008 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 = "I knew that mercury was incredibly heavy and dense Even lead floated on it as my uncle showed me by floating "
					+ "a lead bullet in a bowl of quicksilver But then he pulled out a small grey bar from his pocket and to my "
					+ "amazement this sank immediately to the bottom That he said was his metal tungsten     "; // 5 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 = "IKNEWTHATMERCURYWASINCREDIBLYHEAVYANDDENSEEVENLEADFLOATEDONITASMYUNCLESHOWEDMEBYFLOATINGALEADBULLETINABOWL"
					+ "OFQUICKSILVERBUTTHENHEPULLEDOUTASMALLGREYBARFROMHISPOCKETANDTOMYAMAZEMENTTHISSANKIMMEDIATELYTOTHEBOTTOM"
					+ "THATHESAIDWASHISMETALTUNGSTEN";

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 ("Olfactory",  "Lollapalooza", "Iphimedia",  "Ventralward",  "Eyewitness", "RhythmMethod",  "Subsequently", "Abacus",  
						"Chastisement",  "KurtWaldheim", "SafetyBelts",  "Udall",  "Neodymium", "Cobweb",  "Lambasted",   "Enneastyle",  
						"Taffymaker", "Umiak", "NansenBottle", "Gemlike", "Smoothheaded", "ThunderAndLightning", "Evocative", "NotWithIt");

var sWurdzString = "OLFACTORYLOLLAPALOOZAIPHIMEDIAVENTRALWARDEYEWITNESSRHYTHMMETHODSUBSEQUENTLYABACUSCHASTISEMENTKURTWALDHEIMSAFETYBELTS"
					+ "UDALLNEODYMIUMCOBWEBLAMBASTEDENNEASTYLETAFFYMAKERUMIAKNANSENBOTTLEGEMLIKESMOOTHHEADEDTHUNDERANDLIGHTNING"
					+ "EVOCATIVENOTWITHIT";

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("Pertaining to the sense of smell" ,"90's alt. rock fest; 1985 John Adams composition", 
						"Daughter of Triops, bore two sons of Poseidon", "In the direction of the abdomen",
						"One who saw", "Type of birth control (2 wds.)", "After that", "Beaded calculator", "Castigation",
						"Secretary-general of the UN 1972-82 (full name)", "Restraints worn to avoid injury (2 wds.)", 
						"1960's Secretary of the Interior", "Element 60",
						"Spider's trap", "Excoriated", "Having nine columns",
						"Type of confectioner" , "Eskimo open boat", 
						"Type of container for seawater samples (name and word)",
						"Resembling a precious stone", "Completely bald (hyph.)", "Donner und Blitzen (3 wds.)", 
						"Tending to elicit memories or feelings","Unhip (3 wds.)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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 - 85;	// 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 = 'Oliver Sacks: <a href="http://www.amazon.com/gp/product/0375704043?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0375704043" target="_blank">Uncle Tungsten</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0375704043" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (Memories of a Chemical Boyhood). '
					+'"I knew that mercury, (that strange liquid metal), was incredibly heavy and dense. Even lead floated on it, as my uncle showed me by floating a lead bullet in a bowl of quicksilver. But then he pulled out a small grey bar from his pocket, and to my amazement, this sank immediately to the bottom. That, he said, was his metal, tungsten."';
					
						
var iInstructionsTop = (iBoxHeight * iBoxDown) + iPuzzleTopCoord + 50; // 1Thirty 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 = "20tung";
