//                             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 = "Many of the most beguiling misunderstandings can arise where identical words have different meanings in the two cultures "
					+ "and lingoes When an American exclaims Im mad about my flat she is upset about her punctured tire When a Brit exclaims "
					+ "Im mad about my flat she is exulting about her apartment     "; // 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 = "MANYOFTHEMOSTBEGUILINGMISUNDERSTANDINGSCANARISEWHEREIDENTICALWORDSHAVEDIFFERENTMEANINGSINTHETWOCULTURESANDLINGOESWHEN"
					+ "ANAMERICANEXCLAIMSIMMADABOUTMYFLATSHEISUPSETABOUTHERPUNCTUREDTIREWHENABRITEXCLAIMSIMMADABOUTMYFLATSHEISEXULTINGABOUTHERAPARTMENT";

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 ("Rumfustian", "Inhabitants", "Coercion", "Hemingway", "Afterwards", "RalphBunche", "Debutante", "Lightfast", "Exhausting", 
					"Dexterous", "Excitement", "Ravishing", "Enchilada", "RainDown", "Atypical", "Midwestern", "Autumns", "Neptunium", "Ombudsman", 
					"Forcible", "Meredith", "YosemiteFalls", "WhiteMeat", "OmegaMinus", "Rambler", "Diogenes", "SeaSalt");

var sWurdzString = "RUMFUSTIANINHABITANTSCOERCIONHEMINGWAYAFTERWARDSRALPHBUNCHEDEBUTANTELIGHTFASTEXHAUSTINGDEXTEROUSEXCITEMENTRAVISHINGENCHILADA"
				+ "RAINDOWNATYPICALMIDWESTERNAUTUMNSNEPTUNIUMOMBUDSMANFORCIBLEMEREDITHYOSEMITEFALLSWHITEMEATOMEGAMINUSRAMBLERDIOGENESSEASALT";

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("17th century alcoholic drink", "People living in a place", "Persuasion using threats", "1954 Nobel Prize laureate in Literature", 
					"Subsequently", "1950 Nobel Peace Prize laureate (first, last name)", "Young woman making her first appearance in society", 
					"Describing a dye stable (or resistant to fading) in the sun", "Using up; tiring out", "Skillful, clever, adroit", 
					"Thrill, pleasure, elation", "Delightful, entrancing", "\"The whole ____\" (everything)", 
					"\"Let your love ____ on me\" (Bramlett and Clapton; 2 wds.)", "Not the usual sort of thing", 
					"The old Northwest Territory now consists of ____ states", "Falls", "Element between uranium and plutonium", 
					"Official appointed to investigate individual's complaints against an organization", "Done using power or strength", 
					"Actor, portrayed Rocky Balboa's trainer and The Penguin", "Highest measured waterfall in North America (2 wds.)", 
					"Chicken breast, e.g. (2 wds.)", "Particle (baryon) consisting of three strange quarks (hyph.)", "Car brand (1950-1969) made by Nash and AMC", 
					"Ancient Greek philosopher who supposedly searched for an honest man", "Food ingredient obtained by evaporation of brine (2 wds.)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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. 
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 = 'Richard Lederer: <a href="http://www.amazon.com/gp/product/0312317867?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0312317867" target="_blank">A Man of My Words</a> (Reflections on the English Language). '
					+'"Many of the most beguiling misunderstandings can arise where identical words have different meanings in the two cultures and lingoes. When an American exclaims, "I\'m mad about my flat," she is upset about her punctured tire. When a Brit exclaims, "I\'m mad about my flat," she is exulting about her apartment."';
					
						
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 = "67lede";
