//                             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 = "Americans harbor a secret fascination for the forbidden subject of misanthropy It reared its head when I told "
					+ "certain people that I was writing this book Their first response was a hungry-sounding Ohhh followed by eager "
					+ "suggestions of whom to put in it"; // No 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 = "AMERICANSHARBORASECRETFASCINATIONFORTHEFORBIDDENSUBJECTOFMISANTHROPYITREAREDITSHEADWHENITOLDCERTAINPEOPLETHATIWAS"
					+ "WRITINGTHISBOOKTHEIRFIRSTRESPONSEWASAHUNGRYSOUNDINGOHHHFOLLOWEDBYEAGERSUGGESTIONSOFWHOMTOPUTINIT";

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 ("KineticArt", "Interabang", "Northwest", "Gladhand", "Waterloo", "Identity", "Twister", "Honeybun", "Cowflops", 
					 "Hotshot", "Aussie", "Rushhour", "IndirectObject", "TheFarSide", "Yossarian", "Taffies", "Oregon", "Whisper", 
					"Amphibia", "Rhombic", "Daffodil", "Smoggier", "Nephew", "Outright", "Nonfat", "Espresso");

var sWurdzString = "KINETICARTINTERABANGNORTHWESTGLADHANDWATERLOOIDENTITYTWISTERHONEYBUNCOWFLOPSHOTSHOTAUSSIERUSHHOURINDIRECTOBJECT"
					+ "THEFARSIDEYOSSARIANTAFFIESOREGONWHISPERAMPHIBIARHOMBICDAFFODILSMOGGIERNEPHEWOUTRIGHTNONFATESPRESSO";

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("Sculpture or similar work that moves (2 wds.)", "Combination of question mark and exclamation point", 
					"Hitchcock movie, \"North by ___\"", "Greet warmly, perhaps insincerely (hyph.)", "Belgian town, site of famous 1815 battle", 
					"Sense of self", "Cyclone", "Sweetie", "Meadow muffins", "Showboat, grandstander", "One from Wagga Wagga", 
					"Movie with Jackie Chan and Chris Tucker (2 wds.)", "Girl, in \"He gave the book to the girl.\" (2 wds.)", 
					"Gary Larson's cartoon (3 wds.)", "Main character in Catch-22", "Chewy candies", "One state in the US containing the Blue Mountains", 
					"Lowest volume speech or sound", "Class comprising newts, salamanders, etc.", "Having the form of an equilateral parallelogram", 
					"Yellow spring flower", "Having more polluted air", "Son of a sibling", "Without qualification", "Containing no triglycerides", "Strong coffee");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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 = '(Florence) King: <a href="http://www.amazon.com/gp/product/0312094140?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0312094140" target="_blank">With Charity Towards None</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0312094140" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (A Fond Look At Misanthropy). '
					+'"Americans harbor a secret fascination for the forbidden subject of misanthropy. It reared its head when I told certain people that I was writing this book. Their first response was a hungry-sounding "Ohhh," followed by eager suggestions of whom to put in 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 = "38misa";
