//                             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 = "Thats enough to begin with Humpty Dumpty interrupted there are plenty of hard words there Brillig means four oclock "
					+ "in the afternoon the time when you begin broiling things for dinner Thatll do very well said Alice and slithy Well "
					+ "slithy means lithe and slimy Lithe is the same as active You see its like a portmanteau  there are two meanings "
					+ "packed up into one word     "; // 6 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 = "THATSENOUGHTOBEGINWITHHUMPTYDUMPTYINTERRUPTEDTHEREAREPLENTYOFHARDWORDSTHEREBRILLIGMEANSFOUROCLOCKINTHEAFTERNOONTHE"
					+ "TIMEWHENYOUBEGINBROILINGTHINGSFORDINNERTHATLLDOVERYWELLSAIDALICEANDSLITHYWELLSLITHYMEANSLITHEANDSLIMYLITHEISTHESAME"
					+ "ASACTIVEYOUSEEITSLIKEAPORTMANTEAUTHEREARETWOMEANINGSPACKEDUPINTOONEWORD";

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 ("Literally", "Enthymeme", "Weeknight", "InHotWater", "SheepWitted", "Cloister", "Antipathy", "Reasoned", 
					"RingCycle", "Observation", "Leftfield", "Lifestyle", "TinWhistle", "HalfTwist", "Rustle", "OnTheMend", "Uprising", 
					"GypsyMoth", "HulaHoop", "Torpedo", "Heathers", "Edmonton", "Lauderdale", "Obtundity", "Ornithopter", "KurtWaldheim", 
					"Ivanhoe", "Nourishing", "GirlScout", "Ganymede", "Lieberman", "Anaheim", "Santeria", "Sawbuck");

var sWurdzString = "LITERALLYENTHYMEMEWEEKNIGHTINHOTWATERSHEEPWITTEDCLOISTERANTIPATHYREASONEDRINGCYCLEOBSERVATIONLEFTFIELDLIFESTYLE"
					+ "TINWHISTLEHALFTWISTRUSTLEONTHEMENDUPRISINGGYPSYMOTHHULAHOOPTORPEDOHEATHERSEDMONTONLAUDERDALEOBTUNDITYORNITHOPTER"
					+ "KURTWALDHEIMIVANHOENOURISHINGGIRLSCOUTGANYMEDELIEBERMANANAHEIMSANTERIASAWBUCK";

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("Not figuratively", "Argument in which one premise is not explicitly stated", 
					"Small armored horseman (2 wds.); any evening except Sat. or Sun.", "Up a creek (3 wds.)", 
					" \"...the __ earl who could claim long descent from a king's leman... was a better man than I was.\" (hyph.; Twain, A Connecticut Yankee in King Arthur's Court)",
					"Covered walk; abbey, monastery", "Dislike, hostility", "Used logic", "Set of four related Wagner operas (with The; 2 wds.)", 
					"\"We ought... never to search for truth but by the natural road of experiment and ___\" (Antoine Lavoisier)", 
					"Baseball position (2 wds.); British electronica duo", "Customs, behaviors, habits (coined by Adler in 1929)", 
					"Simple six-holed woodwind instrument assoc. with Ireland (2 wds.)", "Phrase assoc. with gymnastics or moebius strip (2 wds.)", 
					"Make a soft crackling sound; steal livestock", "Recuperating (3 wds.)", "Act of popular resistance, revolt", 
					"Insect brought to the United States in a failed attempt to start a silkworm industry (2 wds.)", "50's fad item desired by Alvin the chipmunk (2 wds.)", 
					"Underwater explosive device", "Cult classic with Winona Ryder, Christian Slater and Shannen Doherty (1989)", "Capital of Alberta", 
					"Fort ___ , Florida spring break city", "Dullness, bluntness", "Machine designed to achieve flight by means of flapping wings", 
					"U.N. and Austria head who had been a Wehrmacht officer (full name; 1918-2007)", "Sir Walter Scott novel (1819)",
					"Providing sustenence; wholesome, beneficial", "Annual cookie seller (in USA; 2 wds.)", "Cupbearer for the Olympic gods; moon of Jupiter", 
					"Gore's VP running mate in 2000", "Disneyland home", "Caribbean religion", "Device for holding wood; ten dollar bill");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 2, 2, 1, 4,   1, 1, 1, 2, 3,   2, 2, 2, 2, 1,   1, 1, 3, 1, 1,   2, 1, 1, 1, 2,  2, 1, 2, 1, 2,  1, 1, 1, 1  ); // 34 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 (168, 289, 204, 105, 39, 275, 192, 157, 27, 266, 136, 32, 22, 237, 213, 188, 255, 49, 296, 5, 166, 284, 56, 97, 15, 119, 
							45, 19, 85, 139, 108, 36, 118, 50, 258, 269, 298, 169, 10, 37, 259, 251, 65, 183, 26, 20, 52, 286, 95, 211, 292, 34, 221, 
							156, 177, 90, 178, 98, 270, 128, 31, 170, 104, 205, 186, 163, 72, 62, 201, 7, 278, 236, 147, 152, 135, 121, 127, 92, 33,
							232, 215, 264, 59, 13, 245, 274, 63, 161, 102, 262, 234, 94, 294, 174, 228, 144, 114, 60, 216, 242, 134, 180, 167, 133, 87, 
							43, 225, 138, 122, 79, 249, 222, 16, 110, 165, 185, 80, 210, 217, 246, 117, 218, 229, 189, 103, 244, 271, 171, 280, 291, 76, 
							23, 69, 42, 93, 224, 293, 257, 153, 263, 285, 197, 241, 129, 68, 124, 25, 38, 148, 4, 277, 200, 142, 81, 164, 41, 143, 196, 
							24, 91, 254, 46, 112, 8, 202, 155, 223, 12, 88, 53, 3, 272, 106, 288, 162, 28, 297, 21, 151, 199, 11, 1, 55, 73, 191, 83, 44, 
							30, 145, 107, 184, 123, 149, 78, 207, 89, 299, 14, 131, 159, 282, 182, 219, 109, 130, 194, 29, 17, 64, 247, 233, 214, 66, 253, 
							35, 193, 99, 61, 160, 281, 0, 126, 268, 96, 261, 48, 111, 187, 250, 54, 172, 195, 120, 220, 116, 140, 235, 260, 150, 154, 252, 
							74, 6, 132, 239, 51, 243, 86, 71, 203, 276, 137, 9, 115, 146, 158, 181, 176, 238, 40, 70, 279, 231, 141, 58, 82, 101, 209, 47, 
							190, 212, 113, 75, 295, 67, 273, 256, 290, 267, 179, 2, 100, 206, 175, 227, 230, 173, 208, 57, 198, 265, 77, 84, 240, 226, 18, 
							125, 287, 283, 248);
								
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 = 'Lewis Carroll: <a href="http://www.amazon.com/gp/product/0393048470?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0393048470" target="_blank">Through the Looking-Glass</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0393048470" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />, (and What Alice Found There). '
					+'" \'That\'s enough to begin with,\' Humpty Dumpty interrupted: \'there are plenty of hard words there. "Brillig" means four o\'clock in the afternoon -- the time when you begin broiling things for dinner.\' \'That\'ll do very well,\' said Alice: \'and "slithy"?\' \'Well, "slithy" means "lithe and slimy." "Lithe" is the same as "active." You see it\'s like a portmanteau -- there are two meanings packed up into one word.\' "';
					
						
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 = "32hump";
