//                             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 = "Since the dawn of time man has anagrammed things Before there was written language primitive man would anagram sticks "
					+ "Some have postulated that a particularly enthusiastic anagram session led to the discovery of fire"; // ? 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 = "SINCETHEDAWNOFTIMEMANHASANAGRAMMEDTHINGSBEFORETHEREWASWRITTENLANGUAGEPRIMITIVEMANWOULDANAGRAMSTICKSSOMEHAVEPOSTULATED"
					+ "THATAPARTICULARLYENTHUSIASTICANAGRAMSESSIONLEDTOTHEDISCOVERYOFFIRE";

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 ("Hacksaw", "Emirates", "Await", "Nights", "Edifies", "Yamaha", "Harpsichord", "Offset", "LastGasp", "Yemen", 
					"Tightwad", "Amigo", "Nonsuch", "Gamma", "Outsmart", "Oversaw", "Fructose", "Lavender", "Imminent", "Tennille", "Evident", 
					"Raglan", "Astro", "Tunic", "Upbraid", "Roseate", "Ethel");

var sWurdzString = "HACKSAWEMIRATESAWAITNIGHTSEDIFIESYAMAHAHARPSICHORDOFFSETLASTGASPYEMENTIGHTWADAMIGONONSUCHGAMMAOUTSMARTOVERSAWFRUCTOSE"
					+ "LAVENDERIMMINENTTENNILLEEVIDENTRAGLANASTROTUNICUPBRAIDROSEATEETHEL";

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("Tool used to cut metal", "They put the \"E\" in the UAE", "Expect, anticipate; lie ahead", "__ in Rodanthe (Nicholas Sparks)", 
					"Instructs or improves morally or intellectually", "This company's logo is three superimposed tuning forks", 
					"Keyboard instrument in which strings are plucked", "Counterbalance; displacement; printing method", 
					"San Francisco company, originally published underground comics (2 wds.)", "Republic on the Arabian Peninsula", "Skinflint", 
					"Chum, compadre, homie", "Henry VIII's palace in Surrey", "Third letter of the Greek alphabet", 
					"Get the better of, using intelligence or cunning", "Supervised", "Type of sugar", 
					"Flowering plant in the mint family, used in perfumery", "About to happen", 
					"Captain and ____ (\"Love Will Keep Us Together\"; \"Muskrat Love\")", "Apparent, obvious", 
					"Type of sleeve named after a British commander in the Crimean War", "Jetson's dog or Houston ballplayer", 
					"Apparel item often used in a religious or military context", "Reprimand, scold", "Pink or reddish; type of tern or spoonbill", 
					"Merman or Barrymore");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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


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

var iPuzzleLeftCoord = iCluesLeftCoord + 420;	// 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 = '(Francis) Heaney: <a href="http://www.amazon.com/gp/product/1578601592?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1578601592" target="_blank">Holy Tango of Literature</a>. '
					+'"Since the dawn of time, man has anagrammed things. Before there was written language, primitive man would anagram sticks. Some have postulated that a particularly enthusiastic anagram session led to the discovery of fire..." Acrostica note: "Holy Tango" is an anagram of "Anthology."';
					
						
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 = 170; // May need to be changed depending on puzzle.

var sPuzzleCode = "72holy";
