//                             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 = "Though the Mongols never took Constantinople the city contains one curious remnant of the Mongol Empire a "
					+ "thirteenth-century Byzantine church known as Mouchliotissa or Our Lady of the Mongols it is the only Byzantine "
					+ "church that was not converted into a mosque    "; // 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 = "THOUGHTHEMONGOLSNEVERTOOKCONSTANTINOPLETHECITYCONTAINSONECURIOUSREMNANTOFTHEMONGOLEMPIREATHIRTEENTHCENTURYBYZANTINECHURCH"
					+ "KNOWNASMOUCHLIOTISSAOROURLADYOFTHEMONGOLSITISTHEONLYBYZANTINECHURCHTHATWASNOTCONVERTEDINTOAMOSQUE";

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 ("Sousa", "TheAbyss", "Einthoven", "Wharton", "Afternoon", "Rhizotomy", "Tynemouth", "Emunctory", "Moccasin", "Polemicize", 
					"InTheSoup", "Reconciled", "Electron", "OnTheDot", "Foment", "Guncotton", "Enthusiast", "NorthernLights", "Grouchily", "Harvester", 
					"Italy", "Solon", "KnowBanquo", "Hack", "Authentic", "Nottingham");

var sWurdzString = "SOUSATHEABYSSEINTHOVENWHARTONAFTERNOONRHIZOTOMYTYNEMOUTHEMUNCTORYMOCCASINPOLEMICIZEINTHESOUPRECONCILEDELECTRONONTHEDOTFOMENTGUNCOTTON"
				+ "ENTHUSIASTNORTHERNLIGHTSGROUCHILYHARVESTERITALYSOLONKNOWBANQUOHACKAUTHENTICNOTTINGHAM";

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("March composer", "1989 James Cameron movie (2 wds.)", "EKG inventor", "Author (\"The Age of Innocence\")", 
					"\"...they are a company of giddy-heads, ___ men.\" (Burton, Anatomy of Menacholy)", "Surgical cutting of spinal nerve roots", 
					"English coastal resort village", "Organ or duct that removes or carries waste from the body", "Soft shoe", "Engage in a controversy", 
					"Having difficulties (3 wds.)", "No longer in disagreement", "Charged lepton", "Exactly punctual (3 wds.)", "Instigate", 
					"Smokeless powder ingredient", "Ardent supporter", "Aurora borealis (2 wds.)", "In an ill-natured manner", "Orange-brown butterfly", 
					"Mediterranean country", "Lawgiver", "\"Both of you __ was your enemy.\" (2 wds.; Macbeth, act iii scene 1)", 
					"Taxicab; writer producing dull, unoriginal work", "Real", "City known for legendary sheriff");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 1, 1, 1, 2,   1, 1, 2, 1, 1,   1, 1, 1, 1, 1,   1, 1, 1, 1, 1,  1, 1, 2, 2, 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 (165, 156, 103, 63, 68, 111, 116, 8, 193, 106, 172, 214, 138, 82, 91, 27, 6, 40, 135, 201, 95, 101, 124, 187, 
							50, 104, 163, 196, 180, 190, 72, 49, 205, 59, 177, 199, 210, 195, 145, 167, 207, 175, 47, 188, 2, 66, 149, 29, 
							107, 208, 17, 128, 54, 184, 0, 132, 202, 9, 3, 67, 46, 178, 143, 118, 105, 83, 10, 42, 186, 211, 15, 51, 170, 
							84, 61, 14, 56, 76, 43, 99, 134, 108, 181, 162, 69, 197, 183, 94, 139, 213, 130, 36, 86, 154, 119, 71, 11, 57, 
							164, 171, 114, 148, 41, 160, 217, 131, 32, 20, 13, 78, 129, 157, 191, 120, 65, 206, 150, 93, 151, 169, 212, 75, 
							110, 70, 4, 144, 96, 115, 123, 136, 44, 35, 31, 38, 34, 97, 74, 58, 161, 137, 126, 53, 166, 48, 141, 64, 204, 189, 
							19, 185, 52, 133, 60, 158, 1, 152, 194, 79, 142, 26, 216, 182, 90, 112, 146, 174, 7, 176, 203, 18, 100, 28, 209, 
							87, 92, 85, 73, 147, 81, 45, 127, 23, 37, 159, 200, 121, 125, 22, 192, 173, 140, 55, 215, 117, 80, 98, 30, 198, 24, 
							88, 62, 39, 153, 168, 113, 102, 33, 25, 16, 77, 89, 21, 179, 122, 12, 5, 109, 155);
								
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 = '(Stanley) Stewart: <a href="http://www.amazon.com/gp/product/1592281060?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1592281060" target="_blank">(In the) Empire of Genghis Khan</a> (An Amazing Odyssey Through the Lands of the Most Feared Conquerors in History). '
					+'"Though the Mongols never took Constantinople, the city contains one curious remnant of the Mongol Empire, a thirteenth-century Byzantine church known as Mouchliotissa, or Our Lady of the Mongols. (The church is a unique link to the Greek capital before the Turkish conquest as) it is the only Byzantine church that was not converted into a mosque."';
					
						
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 = "58lega";

