//                             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 = "No one was trying to make Hush Puppies a trend Yet somehow thats exactly what happened The shoes passed a certain point " +
					"in popularity and they tipped How does a thirty-dollar pair of shoes go from a handful of downtown Manhattan hipsters and " +
					"designers to every mall in America in the space of two years          "; // 10 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 = "NOONEWASTRYINGTOMAKEHUSHPUPPIESATRENDYETSOMEHOWTHATSEXACTLYWHATHAPPENEDTHESHOESPASSEDACERTAINPOINTINPOPULARITYANDTHEY" +
					"TIPPEDHOWDOESATHIRTYDOLLARPAIROFSHOESGOFROMAHANDFULOFDOWNTOWNMANHATTANHIPSTERSANDDESIGNERSTOEVERYMALLINAMERICAINTHESPACEOFTWOYEARS";

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 ("Meditation", "Amethyst", "LhasaApso", "Construed", "Offshoots", "LaysWaste", "Minority", "Giraffe", "Letdown", "Aimless", 
					"Dauphin", "WaddyWood", "EstesPark", "Lather", "Leeuwarden", "Typeface", "HuỳnhTấnPhát", "Express", "TheDeep", "IWhoHaveNothing", 
					"Pharaoh", "Powhatan", "Import", "NotSoMany", "Grotto", "Parcel", "Oppressed", "Intense", "Ninhydrin", "Tapioca");

var sWurdzString = "MEDITATIONAMETHYSTLHASAAPSOCONSTRUEDOFFSHOOTSLAYSWASTEMINORITYGIRAFFELETDOWNAIMLESSDAUPHINWADDYWOODESTESPARKLATHERLEEUWARDEN" +
					"TYPEFACEHUYNHTANPHATEXPRESSTHEDEEPIWHOHAVENOTHINGPHARAOHPOWHATANIMPORTNOTSOMANYGROTTOPARCELOPPRESSEDINTENSENINHYDRINTAPIOCA";

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("Violin solo from Massenet's <i>Thaïs</i>; Jobim bossa nova song", "February birthstone", "Tibetan monastery sentinel dog (2 wds.)", 
					"Interpreted, understood", "Scions, derivatives, by-products", "Completely destroys, as lands or cities in a war (2 wds.)", 
					"<i>The ___ Report</i>, Philip K. Dick short story (1956) made into a 2002 movie", "Camelopard", 
					"Anticlimax, disappointment (1 wd.); what Rapunzel did with her hair (2 wds.)", "Without a goal", 
					"French counterpart to the Prince of Wales or the Prince of Brazil (in the 18th cent.) ", 
					"US Architect (1869-1944) of the Woodrow Wilson House (first, last name)", 
					"Colorado town featuring a hotel said to have inspired Stephen King's <i>The Shining</i> (2 wds.)", 
					"Foam, froth; Jefferson Airplane song about a 30th birthday", "Capital city of Friesland", "Garamond, Aldus, or Arial, e.g.", 
					"Communist South Vietnamese president 1975-6 (full name)", "State, communicate, represent; by rapid means", 
					"Peter Benchley's second novel, after <i>Jaws</i> (2 wds.)", "1963 Ben E. King song, covered by Tom Jones and many others  (4 wds.)", 
					"Tutankhamun or Sneferu", "Native American tribe that met the Jamestown settlers in 1607", "Bring in; implicit meaning; consequence", 
					"Fewer than you might expect (3 wds.)", "Cave shrine, artifical garden cave, scenic chamber in a cave", "Package, or piece of land", 
					"\"...art thou but/ A dagger of the mind, a false creation,/ Proceeding from the heat-____ brain?\" (Macbeth)", 
					"Extreme; highly concentrated; of a person, earnest or fervent", "Chemical used to detect fingerprints (produces deep blue color with proteins)", 
					"Extract of cassava pulp");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 1, 1, 1, 1,   2, 3, 1, 2, 1,   2, 2, 3, 2, 1,   1, 2, 2, 2, 2,  1, 2, 1, 1, 2,  1, 3, 2, 2, 1 ); // 30 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 (42, 209, 126, 98, 131, 54, 229, 201, 94, 186, 220, 16, 4, 50, 23, 109, 206, 183, 217, 230, 49, 129, 179, 141, 100, 82, 158, 235, 138, 
							96, 51, 239, 33, 25, 231, 198, 45, 169, 238, 194, 150, 155, 208, 108, 30, 167, 130, 37, 81, 125, 6, 149, 184, 19, 221, 227, 3, 241, 142, 
							188, 39, 58, 13, 133, 9, 226, 148, 156, 29, 139, 69, 8, 197, 151, 59, 173, 215, 145, 159, 57, 52, 190, 74, 84, 17, 21, 65, 161, 28, 111, 
							172, 31, 122, 112, 10, 46, 147, 127, 137, 34, 78, 207, 43, 246, 102, 64, 157, 18, 104, 110, 71, 123, 192, 212, 140, 77, 73, 166, 176, 244, 
							205, 170, 38, 92, 135, 116, 26, 128, 165, 185, 225, 67, 60, 103, 213, 196, 20, 32, 144, 12, 66, 114, 182, 97, 87, 53, 24, 193, 204, 200, 
							232, 117, 44, 211, 36, 199, 222, 143, 224, 240, 63, 175, 72, 234, 210, 115, 163, 1, 47, 132, 11, 219, 154, 233, 181, 90, 146, 195, 2, 48, 
							93, 15, 5, 187, 160, 191, 80, 180, 218, 178, 120, 237, 245, 113, 228, 171, 56, 40, 101, 214, 105, 177, 242, 202, 134, 76, 174, 89, 41, 119, 
							61, 106, 86, 236, 216, 168, 79, 27, 88, 83, 22, 153, 121, 70, 91, 99, 62, 152, 35, 7, 243, 203, 107, 68, 75, 136, 164, 223, 118, 0, 14, 85, 
							189, 95, 124, 55, 162);
								
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/Malcolm_Gladwell" target="_blank">Malcolm Gladwell</a>: <a href="http://www.amazon.com/gp/product/0316346624?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0316346624" target="_blank">The Tipping Point</a> (How Little Things Can Make a Big Difference). ' +
					'"No one was trying to make Hush Puppies a trend. Yet, somehow, that\'s exactly what happened. The shoes passed a certain point in popularity and they tipped. How does a thirty-dollar pair of shoes go from a handful of downtown Manhattan hipsters and designers to every mall in America in the space of two years?"';
					
						
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 = "93glad";

