//                             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 = "The world isnt made a better place because we wish it so but because we create it so A path is nothing unless its "
					+ "taken Roads are merely pavement without travelers upon them Unless we seize the day we will find ourselves standing "
					+ "forever in the mud I say lets hit the road    "; // 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 = "THEWORLDISNTMADEABETTERPLACEBECAUSEWEWISHITSOBUTBECAUSEWECREATEITSOAPATHISNOTHINGUNLESSITSTAKENROADSAREMERELY"
					+ "PAVEMENTWITHOUTTRAVELERSUPONTHEMUNLESSWESEIZETHEDAYWEWILLFINDOURSELVESSTANDINGFOREVERINTHEMUDISAYLETSHITTHEROAD";

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 ("Epimetheus", "Devoutly", "WhiteWater", "Ambulates", "Rowdiest", "DeathWish", "SweetFlag", "Rochester", "OneTwoThree", 
						"Appetizer", "Duration", "Sunbathes", "Flimsiest", "Residual", "Overstatements", "Mentions", "Tincture", "HandsDown", 
						"Eisenstein", "Allspice", "ShockWave", "Heidelberg", "Eventually", "Surabaya");

var sWurdzString = "EPIMETHEUSDEVOUTLYWHITEWATERAMBULATESROWDIESTDEATHWISHSWEETFLAGROCHESTERONETWOTHREEAPPETIZERDURATIONSUNBATHESFLIMSIESTRESIDUAL"
					+ "OVERSTATEMENTSMENTIONSTINCTUREHANDSDOWNEISENSTEINALLSPICESHOCKWAVEHEIDELBERGEVENTUALLYSURABAYA";

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("Pandora's husband", "With strict adherence", "Rafting thrill (2 wds.)", "Rides shank's mare", "Most boisterous", 
					"Charles Bronson film (1974; 2 wds.)", "Calamus (2 wds.)", "City on the Erie canal", "\"___... Infinity\" (Gamow book; 3 wds.)", 
					"Hors d'oeuvre", "Continuance in time", "Catches some rays", "Least sturdy", "Something left over", "Exaggerations", 
					"Casually refers to", "Alcoholic extract", "Easily, without question (2 wds.)", "Russian film director (1898-1948)", 
					"Jamaican flavoring", "Sonic boom cause (2 wds.)", "Site of Germany's oldest University", "At an unspecified future time", 
					"Capital city of East Java");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 1, 1, 1, 1,   1, 1, 1, 1, 1,   1, 1, 1, 1, 1,   1, 1, 1, 1, 1,  1, 1, 1, 1  ); // 24 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 (93, 134, 118, 103, 128, 180, 210, 59, 46, 85, 157, 139, 176, 4, 52, 20, 143, 108, 37, 77, 184, 11, 198, 147, 
							97, 42, 27, 172, 204, 140, 45, 122, 6, 218, 19, 15, 178, 125, 217, 55, 7, 41, 34, 132, 154, 183, 153, 13, 196, 
							1, 162, 38, 173, 120, 53, 160, 148, 130, 124, 166, 24, 91, 186, 193, 75, 57, 138, 156, 39, 47, 104, 95, 170, 195, 
							102, 64, 3, 188, 90, 40, 216, 36, 18, 60, 109, 68, 54, 213, 167, 152, 207, 189, 169, 200, 5, 110, 70, 151, 96, 115, 
							89, 32, 74, 17, 100, 116, 155, 215, 145, 187, 107, 202, 12, 65, 163, 192, 73, 88, 22, 114, 146, 211, 219, 133, 181, 
							175, 121, 127, 144, 101, 203, 208, 16, 0, 56, 199, 190, 182, 137, 33, 113, 150, 10, 119, 72, 66, 142, 179, 212, 8, 
							94, 30, 61, 141, 105, 161, 197, 126, 168, 201, 149, 98, 135, 117, 79, 112, 194, 86, 49, 82, 209, 123, 177, 78, 185, 
							31, 83, 206, 99, 23, 87, 50, 174, 9, 214, 44, 26, 92, 35, 69, 111, 21, 71, 106, 63, 14, 84, 164, 28, 2, 58, 80, 29, 
							191, 62, 136, 76, 81, 51, 165, 129, 159, 43, 171, 131, 25, 48, 67, 205, 158);
								
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 + 470;	// 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 = '(Megan) Edwards: <a href="http://www.amazon.com/gp/product/1891290010?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1891290010" target="_blank">Roads From the Ashes</a> (An Odyssey in Real Life on the Virtual Frontier). '
					+'"The world isn\'t made a better place because we wish it so, but because we create it so. A path is nothing unless it\'s taken. Roads are merely pavement without travelers upon them. Unless we seize the day, we will find ourselves standing forever in the mud... I say, let\'s hit the road."';
					
						
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 = "77road";

