//                             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 = "Superstar lawyers and math whizzes and software entrepreneurs appear at first blush to lie outside ordinary experience "
					+ "But they dont Their success is not exceptional or mysterious It is grounded in a web of advantages and inheritances "
					+ "some deserved some not some earned some just plain lucky         "; // 9 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 = "SUPERSTARLAWYERSANDMATHWHIZZESANDSOFTWAREENTREPRENEURSAPPEARATFIRSTBLUSHTOLIEOUTSIDEORDINARYEXPERIENCEBUTTHEYDONTTHEIR"
					+ "SUCCESSISNOTEXCEPTIONALORMYSTERIOUSITISGROUNDEDINAWEBOFADVANTAGESANDINHERITANCESSOMEDESERVEDSOMENOTSOMEEARNEDSOME"
					+ "JUSTPLAINLUCKY";

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 ("Mustache", "Abrasive", "Lufthansa", "ChipShot", "OysterStew", "Luxuriant", "MovieStar", "GrandPrix", "LeseMajesty", 
						"Audited", "Disinfect", "Westerner", "Ecosystem", "Lassitude", "Lodestone", "OpenEnded", "Unassisted", "Tribune", 
						"Lipizzaner", "Interests", "EdwardKoch", "Repertoire", "SnowedIn", "Saroyan", "Teacher", "OnPurpose", "RoofBeam", "Youngman");

var sWurdzString = "MUSTACHEABRASIVELUFTHANSACHIPSHOTOYSTERSTEWLUXURIANTMOVIESTARGRANDPRIXLESEMAJESTYAUDITEDDISINFECTWESTERNERECOSYSTEMLASSITUDE"
					+ "LODESTONEOPENENDEDUNASSISTEDTRIBUNELIPIZZANERINTERESTSEDWARDKOCHREPERTOIRESNOWEDINSAROYANTEACHERONPURPOSEROOFBEAMYOUNGMAN";

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("Handlebar, walrus, or Fu Manchu", "Like grit or an inconsiderate person", "Airline with hub in Frankfurt", 
						"Golf stroke, usually used to reach the green (2 wds.)", "Dish for the Walrus and the Carpenter (2 wds.)", 
						"Lush, profuse, vigorous", "Ginger, on \"Gilligan's Island\" (2 wds.)", 
						"Sporting event, often forming part of a championship series (Fr., 2 wds.)", 
						"Offense against the dignity of a reigning sovereign (var.; 2 wds.)", "Examined an account", "Sanitize, destroy pathogens", 
						"\"The ____\"; 1960 TV series created by Sam Peckinpah", "Interdependent biological community plus its physical environment", 
						"Weariness, tiredness, apathy", "Natural magnet", "Having no predetermined limit (hyph.)", "Without help; single-handedly", 
						"Common newspaper name", "White horse breed known for dressage", "Concerns, businesses; hobbies, enthusiasms", 
						"Mayor of New York City 1978-1989 (first, last name)", "Stock or collection of plays, dances, or music regularly performed", 
						"Christmas album by Hanson (1997; 2 wds.)", "Won Pulitzer prize for drama (1940) and Academy award (1944)", "Educator", 
						"Intentionally (2 wds.)", "\"Raise High the ____, Carpenters\" (story by J. D. Salinger; 2 wds.)", 
						"Comedian whose autobiography is titled, \"Take My Life, Please!\"");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 1, 1, 2, 2,   1, 1, 2, 2, 1,   1, 2, 2, 1, 1,   1, 1, 1, 1, 2,  2, 2, 1, 2, 1,  1, 2, 2   ); // 28 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 (219, 232, 152, 105, 173, 121, 114, 98, 54, 170, 148, 60, 70, 97, 207, 133, 9, 151, 172, 112, 22, 139, 187, 145, 222, 
							242, 71, 238, 46, 5, 24, 199, 79, 150, 144, 126, 72, 225, 39, 217, 104, 203, 11, 74, 160, 93, 241, 190, 63, 7, 224, 
							234, 229, 77, 175, 165, 28, 198, 21, 179, 4, 157, 223, 38, 49, 164, 2, 96, 136, 131, 240, 83, 29, 220, 19, 89, 231, 3, 
							156, 216, 244, 16, 51, 82, 186, 146, 101, 209, 86, 75, 204, 25, 214, 35, 115, 195, 43, 23, 208, 80, 129, 122, 59, 138, 
							213, 44, 95, 120, 159, 233, 12, 65, 36, 45, 200, 140, 167, 118, 33, 155, 6, 1, 202, 107, 68, 128, 18, 163, 227, 61, 211, 
							194, 181, 141, 235, 76, 184, 57, 111, 32, 40, 174, 103, 161, 30, 0, 15, 116, 124, 66, 50, 226, 135, 64, 125, 102, 119, 
							177, 196, 236, 87, 94, 191, 27, 26, 58, 17, 130, 142, 149, 99, 113, 41, 90, 13, 123, 154, 53, 205, 162, 37, 20, 14, 109, 
							243, 215, 132, 188, 8, 230, 55, 201, 206, 192, 110, 81, 85, 92, 210, 239, 34, 168, 189, 185, 153, 42, 197, 183, 117, 218, 
							91, 176, 166, 178, 169, 193, 100, 106, 221, 47, 228, 88, 56, 69, 158, 134, 73, 182, 147, 52, 171, 84, 62, 67, 48, 10, 143, 
							108, 137, 78, 127, 180, 212, 237, 31);
								
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 = 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. 
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 = 'Malcolm Gladwell: <a href="http://www.amazon.com/gp/product/0316017922?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0316017922" target="_blank">Outliers ((The) Story (of Success))</a>. '
					+'"(It is impossible for any outlier... to look down from their lofty perch and say with truthfulness, "I did this, all by myself.") Superstar lawyers and math whizzes and software entrepreneurs appear at first blush to lie outside ordinary experience. But they don\'t. (They are products of history and community, of opportunity and legacy.) Their success is not exceptional or mysterious. It is grounded in a web of advantages and inheritances, some deserved, some not, some earned, some just plain lucky -- (but all critical to making them who they are.)"';
					
						
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 = "66outl";

