//                             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 = "Initially English was coerced into absorbing foreign terms as Latin Norse and French influences encroached on its "
					+ "territory Since then in the course of its travels English has reversed the process forcing itself on speakers of "
					+ "many other languages     "; // 5 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 = "INITIALLYENGLISHWASCOERCEDINTOABSORBINGFOREIGNTERMSASLATINNORSEANDFRENCHINFLUENCESENCROACHEDONITSTERRITORYSINCETHENIN"
					+ "THECOURSEOFITSTRAVELSENGLISHHASREVERSEDTHEPROCESSFORCINGITSELFONSPEAKERSOFMANYOTHERLANGUAGES";

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 ("Humpback", "Incenses", "TradeRoute", "Candid", "Horsetail", "InSearchOf", "Notices", "GString", "Stoneflies", "Symbolic", 
						"Efforts", "Coastline", "Refreshing", "Evangeline", "Triples", "LangSyne", "Interiors", "Fennel", "EasyChair", "Overshot", 
						"Frisson", "Wrenches", "OneNight", "RootCanal", "Draught", "Seer");

var sWurdzString = "HUMPBACKINCENSESTRADEROUTECANDIDHORSETAILINSEARCHOFNOTICESGSTRINGSTONEFLIESSYMBOLICEFFORTSCOASTLINEREFRESHINGEVANGELINE"
					+ "TRIPLESLANGSYNEINTERIORSFENNELEASYCHAIROVERSHOTFRISSONWRENCHESONENIGHTROOTCANALDRAUGHTSEER";

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("Singing baleen whale", "Makes furious; substances fragrent when burned", "Silk road, e.g. (2 wds.)", 
					"Truthful and straightforward", "\"Living fossil\" nonflowering plant (Equisetum) related to ferns", 
					"TV series with Leonard Nimoy (3 wds.)", "Becomes aware of; public signs", "\"Air for the ____\" (J. S. Bach; letter, word)", 
					"Insects (Plecoptera) often used as fishing bait", "Figurative, representative", "Serious attempts", "Where the land meets the sea", 
					"Stimulating, energizing; updating", "Longfellow poem (1847)", "Three-base hits", "\"Auld _____\" (2 wds.)", 
					"Woody Allen's first drama (1978)", "Anise-flavored herb the ancient Greeks called \"marathon\"", "Comfortable place to sit (2 wds.)",
					"Water wheel type; went too far", "Shiver of excitement", "Pulls and twists something suddenly or violently; tools for loosening bolts", 
					"\"It Happened ____\" (1934 Frank Capra movie; 2 wds.)", "Notoriously painful dental procedure (2 wds.)", "Beer from a keg, in the UK", 
					"Visionary, oracle, diviner");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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 = '(Henry) Hitchings: <a href="http://www.amazon.com/gp/product/0312428561?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0312428561" target="_blank">(The) Secret Life of Words</a> (How English Became English). '
					+'"Initially English was coerced into absorbing foreign terms, as Latin, Norse and French influences encroached on its territory. Since then, in the course of its travels, English has reversed the process, forcing itself on speakers of many other languages."';
					
						
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 = "63secr";
