//                             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 = "Cultures around the world have employed the caterpillar-to-butterfly miracle in their myths and legends in an effort "
					+ "to explain death and what comes next Butterflies appear in stories worldwide as messengers and as representatives "
					+ "of love and luck both good and bad           "; // 11 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 = "CULTURESAROUNDTHEWORLDHAVEEMPLOYEDTHECATERPILLARTOBUTTERFLYMIRACLEINTHEIRMYTHSANDLEGENDSINANEFFORTTOEXPLAINDEATHANDWHAT"
					+ "COMESNEXTBUTTERFLIESAPPEARINSTORIESWORLDWIDEASMESSENGERSANDASREPRESENTATIVESOFLOVEANDLUCKBOTHGOODANDBAD";

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 ("LastBreath", "Ancient", "Undertaker", "Foretold", "Expectant", "Rattrap", "Torment", "Headstand", "Earworm", "Wednesday", 
					"Omphalos", "Rabid", "LeftHanded", "Dystopia", "Overwhelm", "Festering", "Befouler", "Unseemly", "Taboo", "Trashed", 
					"EvilWould", "Replicant", "Fugitives", "LostCause", "IdleHands", "Ensorceling", "Sphinx");

var sWurdzString = "LASTBREATHANCIENTUNDERTAKERFORETOLDEXPECTANTRATTRAPTORMENTHEADSTANDEARWORMWEDNESDAYOMPHALOSRABIDLEFTHANDEDDYSTOPIAOVERWHELM"
					+ "FESTERINGBEFOULERUNSEEMLYTABOOTRASHEDEVILWOULDREPLICANTFUGITIVESLOSTCAUSEIDLEHANDSENSORCELINGSPHINX";

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("\"...made a groan of her ____ and now she sings in heaven.\" (2 wds.; All's Well That End's Well, act 4 sc. 3)", 
					"\"Here was done the very secret and ____ rite in detestation of Bokrug, the water-lizard...\" (H.P. Lovecraft, \"The Doom That Came to Sarnath\")", 
					"One who prepares dead bodies for funerals", "Predicted", "Mia Farrow\'s character was an ____ mother in Rosemary\'s Baby", 
					"Device for catching rodents; ramshackle building", "Suffering, agony", "Place to display a skull?", "Haunting melody, stuck in one\'s head", 
					"Christina Ricci, in two Addams Family movies", "Center of the world, navel of the earth", "Fanatical; mad, hydrophobic", "Sinistral (hyph.)", 
					"Place where everyone is miserable", "Inundate, bury, defeat completely", "Becoming septic; putrifying", "One who pollutes", 
					"Improper, inappropriate", "Forbidden, unspeakable", "Discarded, wrecked, vandalized", 
					"\"There is some soul of goodness in things __, ___ men observingly distil it out.\" (2 wds.; Henry V act 4 sc. 1)", 
					"Term for android used in \"Blade Runner\"", "Escaped prisoners", "Hopeless task (2 wds.)", "The Devil\'s tools, according to some (2 wds.)", 
					"Bewitching (var.)", "Monster with lion's body and human head");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (3, 4, 1, 1, 2,   2, 1, 1, 1, 2,   1, 1, 1, 1, 1,   1, 1, 1, 1, 1,  3, 1, 1, 1, 2,  1, 1 ); // 27 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 (81, 62, 167, 53, 128, 72, 132, 109, 190, 116, 46, 187, 206, 88, 193, 146, 14, 51, 124, 86, 142, 61, 3, 163, 207, 152, 55, 
							196, 49, 173, 100, 188, 10, 2, 80, 54, 101, 140, 84, 0, 39, 175, 89, 110, 19, 23, 34, 68, 47, 8, 182, 118, 195, 150, 27, 181, 
							106, 98, 22, 40, 201, 215, 179, 97, 220, 79, 161, 172, 216, 5, 17, 155, 180, 73, 159, 25, 114, 12, 6, 185, 21, 139, 74, 18, 
							165, 28, 111, 178, 197, 209, 87, 133, 117, 50, 145, 203, 29, 162, 94, 130, 15, 78, 176, 158, 125, 221, 177, 31, 194, 210, 214, 
							102, 71, 112, 30, 24, 169, 96, 115, 211, 184, 20, 59, 56, 26, 147, 131, 65, 9, 43, 202, 83, 208, 200, 134, 99, 4, 45, 82, 41, 
							205, 170, 164, 36, 108, 121, 64, 58, 127, 90, 219, 95, 198, 148, 156, 38, 7, 76, 137, 33, 166, 192, 60, 103, 154, 213, 1, 204, 
							13, 183, 16, 42, 57, 66, 119, 104, 113, 48, 93, 129, 171, 105, 75, 191, 199, 70, 123, 157, 149, 138, 52, 37, 189, 11, 153, 122, 
							151, 218, 44, 92, 69, 143, 85, 107, 77, 186, 67, 168, 120, 144, 63, 32, 135, 160, 91, 212, 174, 141, 35, 136, 217, 126);
								
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 = '(Peter) Laufer: <a href="http://www.amazon.com/gp/product/1599215551?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1599215551" target="_blank">The (Dangerous) World of Butterflies</a> (The Startling Subculture of Criminals, Collectors, and Conservationists). '
					+'"Cultures around the world have employed the caterpillar-to-butterfly miracle in their myths and legends in an effort to explain death and what comes next. Butterflies appear in stories worldwide as messengers, and as representatives of love and luck -- both good and bad."';
					
						
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 = "54Boo!";

