//                             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 = "My grandfather suffered a stroke in his late seventies He was standing in his kitchen when he suddenly fell "
					+ "over backwards and landed on one of his cats A menu of ten different meals hung on the kitchen wall First on "
					+ "the list bear balls roasted in bacon fat Dont eat bear balls Eat healthy delectable plant-based foods so "
					+ "that you will never fall over on your cat         "; // 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 = "MYGRANDFATHERSUFFEREDASTROKEINHISLATESEVENTIESHEWASSTANDINGINHISKITCHENWHENHESUDDENLYFELLOVERBACKWARDSANDLANDED"
					+ "ONONEOFHISCATSAMENUOFTENDIFFERENTMEALSHUNGONTHEKITCHENWALLFIRSTONTHELISTBEARBALLSROASTEDINBACONFATDONTEAT"
					+ "BEARBALLSEATHEALTHYDELECTABLEPLANTBASEDFOODSSOTHATYOUWILLNEVERFALLOVERONYOURCAT";

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 ("Reynolds", "IllBehaved", "Panini", "EbbAndFlow", "SkeletonCoast", "SlubbingBilly", "Evenhanded", 
					"Lackawanna", "Steelyard", "TheArmOfTheStarfish", "YesWeHaveNoBananas", "NorthAtlanticDrift", "TakesOffAfter", 
					"Hustings", "Ethelfleda", "Emboss", "Notify", "Guadalcanal", "InvertedWorld", "NoneOtherThan", "Esculent", 
					"Turmeric", "WheelsAndDeals", "OffTheHook", "Descartes", "Insistent", "Earful", "Toehold");

var sWurdzString = "REYNOLDSILLBEHAVEDPANINIEBBANDFLOWSKELETONCOASTSLUBBINGBILLYEVENHANDEDLACKAWANNASTEELYARDTHEARMOFTHESTARFISH"
					+ "YESWEHAVENOBANANASNORTHATLANTICDRIFTTAKESOFFAFTERHUSTINGSETHELFLEDAEMBOSSNOTIFYGUADALCANALINVERTEDWORLD"
					+ "NONEOTHERTHANESCULENTTURMERICWHEELSANDDEALSOFFTHEHOOKDESCARTESINSISTENTEARFULTOEHOLD";

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("Fluid mechanician (1842-1912)", "Unruly (hyph)", "Italian painter of cityscapes and ruins (1691-1765)", 
					"Fluctuate, fluctuations (3 wds.)", "Dangerous area for ships off of northern Namibia (2 wds.)", 
					"1790's machine for removing lumps in carded fibers before they go to the spinning jenny (2 wds.)", 
					"Impartial, unbiased", "Steel town, lately known for its six wannabe terrorists", 
					"Trading station in London for the Hanseatic League; portable balance using a sliding weight", 
					"First of the second series of novels after the Wrinkle in Time quartet of Madeleine L'Engle (5 wds.)", 
					"1923 hit song by Silver and Cohn (5 wds.)", "Slow moving eastern extension of the Gulf Stream (3 wds.)", 
					"Gives chase (3 wds.)", "Platform or other site for making campaign speeches", 
					"Lady (i.e. ruling queen) of the Mercians, daughter of Alfred the Great (not the spelling using æ)", 
					"Fashion in relievo", "Inform, apprise", "Solomon Island, location of a major WWII campaign", 
					"Christopher Priest's novel about a hyperboloid-shaped world  (2 wds. with The)", "The very same as (3 wds.)", 
					"Edible, comestible", "Yellow spice; its active ingredient is curcumin", 
					"Trades actively in business or politics (3 wds.)", "Out from under, acquitted (3 wds.)", 
					"This coordinated fellow thought, therefore he is, right here in this puzzle", "Pushy, firm", 
					"Scolding; gossip", "A meager grip, but a starting point");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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

var iPuzzleLeftCoord = iCluesLeftCoord + 525;	// Distance of puzzle grid from left side. *********** Was 490
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 = 'Rip Esselstyn: <a href="http://www.amazon.com/gp/product/093570275X?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=093570275X" target="_blank">The Engine Two Diet</a> (The Texas Firefighter\'s 28-Day Save-Your-Life Plan that Lowers Cholesterol and Burns Away the Pounds). '
					+'"My grandfather, (the great doctor Barney Crile,) suffered a stroke in his late seventies. He was standing in his kitchen when he suddenly fell over backwards and landed on one of his (two) cats, (Sunday Morning in the Twilight Gleaming, a crazy-pills long name for a cat the size of a dog...) A menu of ten different meals (that) hung on the kitchen wall (epitomized the Crile eating style). First on the list: bear balls roasted in bacon fat. Don\'t eat bear balls. Eat healthy, delectable, plant-based foods so that you will never fall over on your cat."';
					
						
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 = "44caut";
