//                             This file is copyright 2010 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 = "If we keep our heads use our heads nourish learning tend the fires of freedom and treat one another with justice and " + 
					"compassion our descendants may say of us that we had the vision to do science and the courage to live by liberty           "; // 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 = "IFWEKEEPOURHEADSUSEOURHEADSNOURISHLEARNINGTENDTHEFIRESOFFREEDOMANDTREATONEANOTHERWITHJUSTICEANDCOMPASSIONOURDESCENDANTS" + 
						"MAYSAYOFUSTHATWEHADTHEVISIONTODOSCIENCEANDTHECOURAGETOLIVEBYLIBERTY";

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 ("FaceOff", "Evasive", "Roundheads", "Raceme", "InTheWay", "Spader", "ToYourTaste", "HandOfDeath", "Ejected", "Stadion", 
						"Coterie", "Incised", "Emphasis", "Nuthouse", "Consul", "Eyebrow", "Oshkosh", "Flourish", "Lamented", "Ingot", "Bright", 
						"Einstein", "Rondeau", "Turandot", "Yawner");

var sWurdzString = "FACEOFFEVASIVEROUNDHEADSRACEMEINTHEWAYSPADERTOYOURTASTEHANDOFDEATHEJECTEDSTADIONCOTERIEINCISEDEMPHASISNUTHOUSECONSULEYEBROW" + 
					"OSHKOSHFLOURISHLAMENTEDINGOTBRIGHTEINSTEINRONDEAUTURANDOTYAWNER";

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("John Woo film (1997) with John Travolta and Nicholas Cage (2 wds. with \"/\")", 
					"Equivocal, prevaricating; with <i>action</i>, an avoidance maneuver", "Parliamentarian opponents of the Royalist Cavaliers", 
					"Type of flower cluster (1 wd.); invitation to a competition (2 wds.)", 
					"<i>Old and ___</i>, bluegrass group with Jerry Garcia, David Grisman, and Peter Rowan (3 wds.)", 
					"Actor James (<i>Pretty in Pink</i>; <i>Crash</i>; <i>Boston Legal</i>)", "The proper way to season food (3 wds.)", 
					"John Woo martial arts film (1976) with Jackie Chan (3 wds.)", "Braves manager Bobby Cox now has the record for being ___ from games", 
					"Ancient Olympic footrace", "Small group of people with shared interests", "Cut", 
					"What is he whose grief / Bears such an ___? (Hamlet, act V sc. 1)", "Loony bin", 
					"One of the two annually elected chief magistrates who jointly ruled the Roman republic", 
					"And then the lover, / Sighing like furnace, with a woeful ballad / Made to his mistress' _____ (As You Like It, act II sc. 7)", 
					"Wisconsin town on Lake Winnebago", "Thrive, prosper; twirl, display", "Grieved, mourned", "Block of metal suitable for further processing", 
					"Shining; clever", "Nobel prize winner (1921) \"...especially for his discovery of the law of the photoelectric effect.\"", 
					"French poetic form with thirteen lines", 
					"Opera containing the aria <a href='http://en.wikipedia.org/wiki/Nessun_dorma' target='_blank'><i>Nessun Dorma</i></a>", 
					"Boring movie or story, e.g.");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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


var iCluWidth = 240;
var iLineHeight = 23;
var iTotalCluesHeight = 0; // Calculated in initPuzzle.
var iPadFactor = 8;

var iPuzzleLeftCoord = iCluesLeftCoord + 500;	// Distance of puzzle grid from left side. (500)
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 = '<a href="http://en.wikipedia.org/wiki/Timothy_Ferris" target="_blank">(Timothy) Ferris</a>: <a href="http://www.amazon.com/gp/product/0060781505?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0060781505" target="_blank">The Science of Liberty</a> (Democracy, Reason, and the Laws of Nature). '
					+'"If we keep our heads, use our heads, nourish learning, tend the fires of freedom, and treat one another with justice and compassion, our descendants may say of us that we had the vision to do science, and the courage to live by liberty."';
					
						
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 = 150; // May need to be changed depending on puzzle.

var sPuzzleCode = "85free";

