//                             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 = "The light was watery dim and incomparably sad Vast grey gloomy hills rose up all around them and in between the hills "
					+ "there was a wide expanse of black bog Stephen had never seen a landscape so calculated to reduce the onlooker to "
					+ "utter despair in an instant This is one of your kingdoms I suppose sir he said My kingdoms exclaimed the gentleman "
					+ "in surprize Oh no This is Scotland    "; // 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 = "THELIGHTWASWATERYDIMANDINCOMPARABLYSADVASTGREYGLOOMYHILLSROSEUPALLAROUNDTHEMANDINBETWEENTHEHILLSTHEREWASAWIDE"
					+ "EXPANSEOFBLACKBOGSTEPHENHADNEVERSEENALANDSCAPESOCALCULATEDTOREDUCETHEONLOOKERTOUTTERDESPAIRINANINSTANTTHISISONE"
					+ "OFYOURKINGDOMSISUPPOSESIRHESAIDMYKINGDOMSEXCLAIMEDTHEGENTLEMANINSURPRIZEOHNOTHISISSCOTLAND";

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.
var aWurdz = new Array ("Slipshod", "Unsettling", "Sidewinder", "Admonished", "Needlessly", "NoveltyShop", "Alexandria", "Closeup", 
						"Legalistic", "Anacoluthon", "Repossessed", "Kenophobia", "Embodiment", "Strengths", "Temerity", "Rhinestones", 
						"Asilomar", "Nighthawks", "GataKamsky", "Exculpated", "Acadian", "NowAndThen", "Duboisia", "Megabyte", 
						"RazorStrop", "NewThought", "OpenAndShut", "Reclusive", "Rhetorical", "EmptyHeaded", "LaminarFlow", "LeifEricson");

var sWurdzString = "SLIPSHODUNSETTLINGSIDEWINDERADMONISHEDNEEDLESSLYNOVELTYSHOPALEXANDRIACLOSEUPLEGALISTICANACOLUTHONREPOSSESSEDKENOPHOBIA"
					+ "EMBODIMENTSTRENGTHSTEMERITYRHINESTONESASILOMARNIGHTHAWKSGATAKAMSKYEXCULPATEDACADIANNOWANDTHENDUBOISIAMEGABYTE"
					+ "RAZORSTROPNEWTHOUGHTOPENANDSHUTRECLUSIVERHETORICALEMPTYHEADEDLAMINARFLOWLEIFERICSON";

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("Carelessly done", "Causing one to feel anxious or disturbed", "Rattlesnake with a distinctive means of locomotion", 
					"Warned, reprimanded", "Avoidably; unjustifiably", "Place to buy gifts, toys, magic tricks, etc. (2 wds.)", 
					"Egyptian city known for its former library and lighthouse", "Type of photo, movie shot, or magic (hyph.)", "Excessively adherent to rules", 
					"Figure of speech characterized by non sequitur or abrupt change of syntax", "1990 movie with Linda Blair and Leslie Nielsen", 
					"Abnormal fear of large, empty spaces", "Tangible example", "Talents, powers, advantages", "Audacity, effrontery, chutzpah", 
					"Imitation gems associated with Elvis, Liberace, and Glen Campbell", "California State Beach on the Monterey Peninsula", 
					"Edward Hopper's famous painting (1942) of people sitting in a diner", 
					"Soviet-born American chess player (b. 1974; first, last name)", "Declared free of blame", 
					"Type of French colonist in the New World", "From time to time (3 wds.)", 
					"Australian plant genus, grown for pharmaceuticals (Corkwood tree)", "Unit of measurement often used with computers", 
					"Leather used to sharpen a thin blade (2 wds.)", "Spiritual movement originating in the USA during the late 19th century (2 wds.)", 
					"(A case) easily disposed of (3 wds.)", "Solitary, isolated, like a hermit", "(Question) asked to produce an effect rather than to get information", 
					"Vacuous (hyph.)", "Opposite of turbulence (2 wds.)", "Vinland founder (full name)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 1, 2, 1, 1,   2, 2, 1, 1, 2,   2, 1, 1, 1, 1,   2, 2, 2, 2, 1,   1, 1, 2, 2, 2,  2, 1, 1, 2, 1,   1, 1  ); // 32 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 (195, 162, 106, 62, 150, 6, 58, 135, 285, 113, 240, 154, 96, 7, 47, 234, 179, 42, 247, 266, 309, 131, 8, 23, 
							87, 17, 241, 169, 9, 250, 27, 124, 294, 289, 95, 176, 137, 149, 218, 177, 115, 193, 306, 14, 103, 141, 65, 51, 
							283, 217, 138, 128, 94, 0, 34, 302, 271, 168, 196, 63, 119, 143, 110, 104, 148, 71, 185, 53, 163, 160, 93, 231, 
							40, 261, 188, 238, 277, 194, 125, 152, 54, 200, 242, 83, 254, 157, 102, 136, 147, 151, 258, 64, 236, 305, 73, 
							116, 281, 99, 291, 28, 178, 214, 56, 272, 299, 233, 246, 78, 183, 191, 203, 68, 237, 1, 48, 81, 198, 248, 219, 
							50, 32, 182, 22, 204, 279, 274, 80, 189, 35, 41, 244, 174, 201, 46, 167, 297, 126, 88, 109, 259, 98, 288, 215, 
							270, 222, 192, 130, 213, 77, 2, 301, 296, 220, 275, 90, 10, 120, 260, 249, 146, 187, 75, 134, 140, 209, 282, 5, 
							91, 164, 52, 265, 84, 226, 114, 273, 39, 211, 31, 122, 197, 19, 206, 253, 45, 86, 262, 173, 61, 3, 111, 12, 127, 
							184, 166, 112, 263, 307, 107, 300, 66, 24, 132, 239, 101, 202, 70, 230, 175, 97, 170, 255, 257, 172, 123, 295, 92, 
							216, 18, 76, 251, 100, 256, 29, 118, 16, 207, 44, 67, 158, 290, 181, 30, 59, 190, 43, 223, 153, 144, 268, 11, 210, 
							293, 49, 224, 229, 245, 276, 156, 287, 139, 21, 208, 228, 171, 235, 212, 161, 186, 57, 74, 25, 33, 69, 284, 298, 38, 
							82, 199, 133, 142, 13, 292, 225, 243, 303, 280, 264, 60, 232, 129, 72, 252, 89, 85, 145, 269, 108, 37, 159, 20, 267, 
							4, 308, 36, 286, 221, 55, 304, 105, 180, 165, 79, 117, 278, 15, 227, 121, 155, 26, 205);
								
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 = 'Susanna Clarke: <a href="http://www.amazon.com/gp/product/0765356155?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0765356155" target="_blank">(Jonathan) Strange and Mr Norrell</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0765356155" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (A Novel). '
					+'"The light was watery, dim, and incomparably sad. Vast, grey, gloomy hills rose up all around them and in between the hills there was a wide expanse of black bog. Stephen had never seen a landscape so calculated to reduce the onlooker to utter despair in an instant. \'This is one of your kingdoms, I suppose, sir?\' he said. \'My kingdoms?\' exclaimed the gentleman in surprize. \'Oh, no! This is Scotland!\'"';
					
						
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 = "30stra";

