//                             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 = "When I was eight years old I was invited to play the Monopoly game for the first time The experience was pivotal "
					+ "I fought back tears when forced to mortgage property I felt guilty when sent to jail and breathed a sigh of "
					+ "relief when my top hat leaped over Boardwalk and I avoided bankruptcy          "; // 10 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 = "WHENIWASEIGHTYEARSOLDIWASINVITEDTOPLAYTHEMONOPOLYGAMEFORTHEFIRSTTIMETHEEXPERIENCEWASPIVOTALIFOUGHTBACKTEARSWHEN"
					+ "FORCEDTOMORTGAGEPROPERTYIFELTGUILTYWHENSENTTOJAILANDBREATHEDASIGHOFRELIEFWHENMYTOPHATLEAPEDOVERBOARDWALKAND"
					+ "IAVOIDEDBANKRUPTCY";

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 ("Patchouli",  "Hotdogs", "Imperfect", "LightHeaded",  "Inexorably",  "Pinafore", "OffTheWall",  "Reykjavik", "Bayonet",  
						"Abeyance", "NightLatch",  "Edgewood", "SweetPotato",  "Trevino",  "Handfasts", "Eiderdown",  "GlottalStop",   "Airwaves",  
						"Misdefined", "Ethnography", "MummyApple", "Apiol", "KaterinaWitt", "Everywhere", "RightBower", "Surfeit");

var sWurdzString = "PATCHOULIHOTDOGSIMPERFECTLIGHTHEADEDINEXORABLYPINAFOREOFFTHEWALLREYKJAVIKBAYONETABEYANCENIGHTLATCHEDGEWOODSWEETPOTATO"
					+ "TREVINOHANDFASTSEIDERDOWNGLOTTALSTOPAIRWAVESMISDEFINEDETHNOGRAPHYMUMMYAPPLEAPIOLKATERINAWITTEVERYWHERERIGHTBOWERSURFEIT";

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("Oil used as a fixative in amber, chypre, and fougere-type perfumes" ,"Shows off", 
						"Flawed", "Dizzy or frivolous (hyph.)", "In an unstoppable manner", 
						"Gilbert & Sullivan vessel (w. HMS)", "Unusual, bizarre (3 hyph. wds.)",
						"City whose name means \"smoky bay\"", "Close-combat weapon named after a French city", "Temporary cessation, suspension", 
						"Door lock with keyhole outside and knob inside (2 wds.)", "College in Madison, WI", "Ocarina (2 wds.)", 
						"Champion golfer struck by lightning in 1975","Betroths, grasps firmly (obs.)" , 
						"Kind of feather or quilt", "Voiceless plosive articulated by the vocal folds (2 wds.)",
						"Radio and TV broadcast medium", "Characterized inaccurately", 
						"Anthropological description of societies", "Another name for pawpaw or papaya (2 wds.)", 
						"Parsley seed oil ingredient","Figure skater born in former East Berlin (full name)", "In all places",
						"Highest trump in N. American euchre (2 wds.)", "More than enough");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 1, 1, 1, 1,   1, 1, 1, 2, 1,   2, 1, 1, 1, 1,   1, 2, 1, 1, 1,  1, 1, 2, 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 (73, 124, 12, 114, 108, 221, 141, 159, 85, 39, 44, 63, 217, 207, 174, 17, 28, 51, 84, 169, 61, 92, 151, 79, 
							144, 90, 142, 49, 57, 167, 69, 74, 171, 223, 197, 210, 65, 43, 77, 72, 155, 230, 15, 226, 143, 37, 127, 25, 
							216, 160, 53, 118, 178, 200, 46, 183, 59, 133, 96, 115, 81, 50, 19, 213, 75, 204, 134, 214, 156, 36, 27, 218, 
							101, 206, 99, 145, 54, 110, 186, 29, 208, 98, 179, 48, 215, 149, 234, 14, 78, 158, 95, 185, 68, 35, 6, 88, 100, 
							175, 52, 162, 10, 224, 0, 120, 176, 31, 150, 107, 165, 2, 38, 130, 33, 97, 198, 139, 112, 190, 105, 109, 86, 4, 
							228, 202, 193, 219, 3, 225, 136, 82, 106, 117, 172, 40, 60, 20, 148, 113, 201, 191, 5, 187, 140, 47, 129, 102, 
							153, 194, 180, 83, 56, 18, 199, 166, 21, 128, 184, 104, 203, 58, 7, 188, 76, 24, 170, 8, 177, 91, 161, 67, 116, 
							80, 32, 1, 152, 93, 125, 132, 23, 192, 11, 235, 66, 94, 41, 119, 13, 227, 232, 34, 196, 103, 157, 45, 181, 87, 
							138, 229, 89, 195, 131, 164, 222, 26, 212, 146, 135, 64, 122, 126, 220, 70, 121, 189, 22, 168, 30, 209, 182, 205, 
							9, 123, 147, 233, 163, 42, 211, 71, 55, 62, 231, 16, 111, 137, 173, 154);
								
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 = 'Philip (E.) Orbanes: <a href="http://www.amazon.com/gp/product/1591392691?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1591392691" target="_blank">The Game Makers</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=1591392691" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (The Story of Parker Brothers, from Tiddledy Winks to Trivial Pursuit). '
					+'"When I was eight years old, I was invited to play the Monopoly game for the first time. The experience was pivotal... I fought back tears when forced to mortgage property; I felt guilty when sent to jail; and breathed a sigh of relief when my top hat leaped over Boardwalk and I avoided bankruptcy."';
					
						
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 = "24pass";
