//                             This file is copyright 2010 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 = "Could anyone have believed that the Eighteenth Amendment ostensibly addressing the single subject of intoxicating "
					+ "beverages would provoke the establishment of the first nationwide criminal syndicate the idea of home dinner parties "
					+ "the deep engagement of women in political issues other than suffrage and the creation of Las Vegas       "; // 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 = "COULDANYONEHAVEBELIEVEDTHATTHEEIGHTEENTHAMENDMENTOSTENSIBLYADDRESSINGTHESINGLESUBJECTOFINTOXICATINGBEVERAGESWOULDPROVOKE"
					+ "THEESTABLISHMENTOFTHEFIRSTNATIONWIDECRIMINALSYNDICATETHEIDEAOFHOMEDINNERPARTIESTHEDEEPENGAGEMENTOFWOMENINPOLITICALISSUES"
					+ "OTHERTHANSUFFRAGEANDTHECREATIONOFLASVEGAS";

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 ("Demagogue", "AheadOfTime", "NewOrleans", "Investments", "Exhaustive", "Lengthens", "OfTheDead", "KidGloves", 
					"Retrofitted", "Eustatic", "Nibelungen", "TweetTweet", "Lancetfish", "AlCapone", "Sheridan", "Thesmothete", "Chileans", 
					"Airtight", "LeHavre", "Linares", "Popinjay", "Respite", "Onomastics", "Hologram", "Indebtedness", "BaffinBay", "Inveighed", 
					"Thetford", "IceFishing", "Oenomancy", "NoDoubt");

var sWurdzString = "DEMAGOGUEAHEADOFTIMENEWORLEANSINVESTMENTSEXHAUSTIVELENGTHENSOFTHEDEADKIDGLOVESRETROFITTEDEUSTATICNIBELUNGENTWEETTWEET"
					+ "LANCETFISHALCAPONESHERIDANTHESMOTHETECHILEANSAIRTIGHTLEHAVRELINARESPOPINJAYRESPITEONOMASTICSHOLOGRAMINDEBTEDNESS"
					+ "BAFFINBAYINVEIGHEDTHETFORDICEFISHINGOENOMANCYNODOUBT";

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("One who seeks to persuade by appealing to the passions and prejudices of the audience rather than logic and reason", 
				"Earlier than expected (3 wds.)", "US city associated with beignets (2 wds.)", "Financial concern", "Fully comprehensive, thorough", 
				"Enlarges, prolongs", "Day _____: Mexican holiday, or 1985 George Romero film (3 wds.)", 
				"Figuratively worn to handle something or someone very carefully (2 wds.)", "Added new technology or features to an older unit", 
				"Relating to or characterized by a worldwide change of sea level", "Wagner's opera cycle, <i>Der Ring des</i> ___", 
				"Punk rock album, <i>____ My Lovely</i> by Snuff (1998; 2 wds.)", "Scaleless deep-sea predator with long teeth", 
				"Famous bootlegger (2 wds.)", "Irish playwright (1751-1816; <i>The Rivals</i>, <i>A School for Scandal</i>)", 
				"Lawgiver; one of the six junior archons at Athens", "Inhabitants of a certain South American country", 
				"Describing an irrefutable alibi", "City on the English Channel (2 wds.)", 
				"Birthplace of Andrés Segovia; where Hannibal is said to have wed Himilce", "Talkative person; type of archery target", 
				"Time out, intermission, pause", "Study of the history and origin of proper names", "Common credit card security feature", 
				"Financial concern", "Body of water between Canada and Greenland (2 wds.)", "Denounced, vituperated (with <i>against</i>)", 
				"Birthplace of Thomas Paine", "Cold-weather sport involving a saw, axe, or auger, and spear or hook (2 wds.)", 
				"Divination using wine (var.)", "Group with Gwen Stefani (2 wds.)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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


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

var iPuzzleLeftCoord = iCluesLeftCoord + 500;	// Distance of puzzle grid from left side. (500)
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 = '<a href="http://en.wikipedia.org/wiki/Daniel_Okrent", target="_blank">Daniel Okrent</a>: <a href="http://www.amazon.com/gp/product/0743277023?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0743277023" target="_blank">Last Call</a> -- (the Rise and Fall of) Prohibition. '
					+'"(In 1920) could anyone have believed that the Eighteenth Amendment, ostensibly addressing the single subject of intoxicating beverages, would... provoke the establishment of the first nationwide criminal syndicate, the idea of home dinner parties, the deep engagement of women in political issues other than suffrage, and the creation of Las Vegas?"';
					
						
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 = 150; // May need to be changed depending on puzzle.

var sPuzzleCode = "83okre";

