//                             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 = "Then I read the most wonderful title of a chapter of any book I had ever held Fundamentals of Rocket Engines "
					+ "Theres calculus in there and differential equations Miss Riley said You could ask Mr Hartsfield He might help you "
					+ "I dont know how to thank you I blurted All Ive done is give you a book she said You have to have the courage to "
					+ "learn whats inside it    "; // 4 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 = "THENIREADTHEMOSTWONDERFULTITLEOFACHAPTEROFANYBOOKIHADEVERHELDFUNDAMENTALSOFROCKETENGINESTHERESCALCULUSINTHEREAND"
					+ "DIFFERENTIALEQUATIONSMISSRILEYSAIDYOUCOULDASKMRHARTSFIELDHEMIGHTHELPYOUIDONTKNOWHOWTOTHANKYOUIBLURTEDALLIVEDONEIS"
					+ "GIVEYOUABOOKSHESAIDYOUHAVETOHAVETHECOURAGETOLEARNWHATSINSIDEIT";

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 ("HaveDoneWith", "OutOfTheBlue", "Midlothian", "Eratosthenes", "Roundheads", "HalfHidden", "Heartened", 
						"Isolationist", "Chowderhead", "Kotukutuku", "Adequately", "Methodists", "Refractory", "Offensively", 
						"Captures", "Kabalevsky", "Eisenhower", "Threnody", "Bowline", "OffTheHook", "Youthening", "Slighted", 
						"Aramaic", "Munificent", "ElSalvador", "Milestones", "OlduvaiGorge", "Initially", "Rapacious");

var sWurdzString = "HAVEDONEWITHOUTOFTHEBLUEMIDLOTHIANERATOSTHENESROUNDHEADSHALFHIDDENHEARTENEDISOLATIONISTCHOWDERHEADKOTUKUTUKU"
					+ "ADEQUATELYMETHODISTSREFRACTORYOFFENSIVELYCAPTURESKABALEVSKYEISENHOWERTHRENODYBOWLINEOFFTHEHOOKYOUTHENING"
					+ "SLIGHTEDARAMAICMUNIFICENTELSALVADORMILESTONESOLDUVAIGORGEINITIALLYRAPACIOUS";

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("\"Depart, I say, and let us _____ you!\" (Oliver Cromwell, 3 wds.)", "Without warning; from nowhere (4 wds.)", 
					"Scottish Council area which formerly included Edinburgh", "Greek scholar (c. 275-194 BC) who calculated the circumference of the Earth", 
					"Supporters of Oliver Cromwell against King Charles I", "Partly obscured (hyph.)", "Cheered up, boosted spirits, reassured", 
					"One who favors non-interventionism and protectionism", "Lummox, numbskull, dingbat", "New Zealand fuchsia, largest member of its genus", 
					"Satisfactorily, acceptably", "Followers of John and Charles Wesley, e.g.", "Stubborn; resistant, esp. to heat", "In an attacking manner", 
					"Takes control of, records", "Russian composer (1904-1987; Colas Breugnon; The Comedians)", "Last WWI veteran to serve as U.S. president", 
					"Lament, song of mourning", "Knot for forming a loop at the end of a rope", "No longer in difficulty or responsible (3 wds.)", 
					"Condition of Merlin and Benjamin Button", "Insulted", "Semitic language", "Generous, lavish", 
					"Smallest country by area in continental America (2 wds.)", "Landmarks, watersheds", 
					"Northern Tanzania site important for hominid fossils (2 wds.)", "At first", "Greedy, grasping, predatory");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 1, 2, 2, 2,   1, 1, 2, 1, 2,   1, 1, 1, 1, 1,   2, 1, 1, 1, 2,  1, 1, 1, 1, 2,  1, 2, 1, 1 ); // 29 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 (50, 213, 227, 92, 243, 13, 103, 6, 194, 285, 257, 169, 46, 23, 9, 220, 41, 69, 89, 166, 233, 207, 151, 116, 66, 144, 
							8, 59, 234, 162, 253, 102, 276, 280, 284, 56, 248, 128, 230, 136, 267, 10, 218, 273, 67, 101, 263, 130, 231, 85, 153, 
							34, 177, 70, 168, 237, 57, 264, 215, 164, 1, 172, 112, 64, 222, 119, 176, 211, 42, 117, 27, 81, 221, 270, 184, 216, 14, 
							150, 71, 127, 120, 138, 76, 63, 113, 163, 80, 149, 174, 196, 274, 60, 86, 107, 192, 170, 65, 52, 201, 185, 195, 208, 78, 
							246, 0, 126, 48, 148, 160, 19, 79, 125, 182, 254, 15, 2, 214, 229, 171, 106, 277, 159, 203, 111, 242, 281, 210, 87, 91, 
							53, 31, 137, 95, 260, 175, 252, 39, 244, 190, 74, 115, 124, 82, 135, 226, 255, 55, 28, 146, 97, 122, 36, 88, 204, 161, 
							29, 93, 236, 51, 206, 35, 269, 256, 249, 278, 188, 141, 90, 84, 142, 228, 200, 247, 181, 191, 11, 5, 104, 238, 209, 118, 
							186, 268, 219, 180, 45, 147, 16, 123, 279, 68, 108, 193, 22, 61, 187, 105, 140, 198, 30, 17, 156, 202, 245, 62, 251, 258, 
							38, 18, 282, 189, 225, 240, 24, 223, 265, 275, 286, 20, 212, 232, 158, 199, 12, 32, 183, 77, 133, 100, 110, 26, 114, 129, 
							94, 58, 3, 37, 266, 96, 132, 109, 139, 54, 154, 145, 47, 75, 157, 49, 167, 259, 72, 197, 235, 43, 250, 224, 40, 99, 283, 
							262, 217, 143, 134, 83, 73, 21, 173, 239, 4, 131, 121, 25, 205, 271, 152, 178, 44, 272, 241, 179, 7, 33, 165, 261, 98, 155);
								
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 + 490;	// 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 = 'Homer H. Hickam (Jr.): <a href="http://www.amazon.com/gp/product/0385333218?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0385333218" target="_blank">Rocket Boys, a Memoir</a>. '
					+'"Then I read the most wonderful title of a chapter of any book I had ever held: \'Fundamentals of Rocket Engines.\' \'There\'s calculus in there and differential equations,\' Miss Riley said. \'You could ask Mr. Hartsfield. He might help you.\' ... \'I don\'t know how to thank you!\' I blurted. \'All I\'ve done is give you a book,\' she said. \'You have to have the courage to learn what\'s inside it.\'"';
					
						
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 = "51chal";

