//                             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 = "Timothy Leary had a foreboding feeling the first time he entered the cage This time he was just visiting By the end " +
					"of the decade Leary would walk into another prison and find the cell door slammed shut behind him By then he would be a " +
					"real revolutionary the guy Richard Nixon would call the most dangerous man in America   "; // 3 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 = "TIMOTHYLEARYHADAFOREBODINGFEELINGTHEFIRSTTIMEHEENTEREDTHECAGETHISTIMEHEWASJUSTVISITINGBYTHEENDOFTHEDECADELEARYWOULDWALK" +
					"INTOANOTHERPRISONANDFINDTHECELLDOORSLAMMEDSHUTBEHINDHIMBYTHENHEWOULDBEAREALREVOLUTIONARYTHEGUYRICHARDNIXONWOULDCALLTHEMOSTDANGEROUSMANINAMERICA";

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 ("Lightheaded", "Aflatoxin", "TomSawyer", "Tillerman", "Imbibed", "NowAndThen", "HalfHidden", "Ambassador", "Rethought", 
					"Vehemently", "AlludeTo", "RoughRider", "Dehydration", "PettyTheft", "Scariest", "Yankee", "Commonwealth", "HealthFood", "Enjoyed", 
					"Dishwasher", "Eleuthera", "LudwigMies", "Inebriation", "Cervantes", "Cuneiform", "Longitude", "Unsightly", "Boccherini");

var sWurdzString = "LIGHTHEADEDAFLATOXINTOMSAWYERTILLERMANIMBIBEDNOWANDTHENHALFHIDDENAMBASSADORRETHOUGHTVEHEMENTLYALLUDETOROUGHRIDERDEHYDRATIONPETTYTHEFT" +
					"SCARIESTYANKEECOMMONWEALTHHEALTHFOODENJOYEDDISHWASHERELEUTHERALUDWIGMIESINEBRIATIONCERVANTESCUNEIFORMLONGITUDEUNSIGHTLYBOCCHERINI";

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("Dizzy, slightly faint", "Poisonous substance found in moldy nuts and seeds", "Twain character (full name)", 
					"<i>Tea for the ___</i> (Cat Stevens)", "Drank (usu. alcohol)", "From time to time (3 wds.)", "Partly obscured (hyph.)", 
					"Official representative of a foreign country", "Considered again", "In a forceful or intense manner", "Hint at (2 wds.)", 
					"Theodore Roosevelt, in the Spanish-American War (2 wds.)", "Desert danger", "A little stealing (2 wds.)", "Most frightening", 
					"Person from the USA, or sometimes New England", "Kentucky, Massachusetts, Pennsylvania, or Virginia", 
					"Alfalfa sprouts, wheat germ, or yogurt, but not french fries (2 wds.)", "Took pleasure in, relished", 
					"George Orwell worked in Paris as one of these for a while", "Long, thin island in the Bahamas", 
					"__ __ van der Rohe, architect known for saying \"Less is more\" (2 wds.)", "Drunkenness", "Quixote creator", 
					"Wedge-shaped, like some ancient writing", "Zero passes through Greenwich", "Not pleasant to look at", 
					"Italian composer and cellist (1743-1805)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 2, 1, 1, 1,   1, 1, 2, 1, 1,   1, 2, 1, 1, 1,   2, 2, 2, 1, 2,  1, 2, 1, 1, 1,  1, 1, 2 ); // 28 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 (113, 23, 59, 167, 126, 89, 27, 136, 219, 236, 229, 116, 139, 198, 107, 234, 238, 222, 168, 84, 88, 223, 173, 133, 
							156, 110, 212, 104, 246, 207, 30, 117, 233, 166, 194, 250, 217, 243, 81, 67, 86, 1, 187, 35, 93, 120, 197, 71, 15, 48, 
							114, 54, 97, 147, 31, 144, 72, 148, 36, 216, 83, 99, 103, 44, 135, 9, 158, 20, 231, 76, 249, 102, 138, 183, 205, 131, 
							257, 164, 235, 17, 75, 32, 177, 41, 78, 100, 12, 19, 43, 68, 179, 200, 149, 6, 123, 185, 7, 248, 14, 181, 61, 111, 129, 
							134, 211, 244, 69, 51, 221, 150, 90, 10, 53, 159, 45, 87, 22, 190, 255, 121, 66, 226, 203, 130, 191, 65, 82, 206, 40, 
							162, 56, 95, 240, 64, 215, 251, 38, 132, 98, 154, 4, 175, 13, 137, 118, 195, 245, 260, 247, 256, 237, 94, 141, 115, 178, 
							204, 228, 49, 55, 34, 60, 261, 105, 0, 5, 26, 202, 151, 186, 50, 254, 74, 125, 109, 70, 241, 142, 79, 73, 180, 225, 58, 
							239, 62, 8, 258, 188, 29, 128, 184, 77, 208, 47, 218, 242, 193, 199, 160, 182, 119, 25, 2, 63, 209, 39, 214, 169, 52, 
							165, 108, 201, 192, 33, 37, 152, 252, 57, 46, 18, 196, 189, 24, 176, 145, 80, 101, 112, 220, 91, 172, 16, 122, 153, 157, 
							232, 21, 124, 85, 259, 143, 163, 170, 28, 227, 92, 161, 140, 210, 171, 96, 155, 11, 174, 3, 230, 146, 127, 106, 213, 42, 
							224, 253);
								
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/Don_Lattin" target="_blank">(Don) Lattin</a>: <a href="http://www.amazon.com/gp/product/0061655937?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0061655937" target="_blank">(The) Harvard Psychedelic Club</a> (How Timothy Leary, Ram Dass, Huston Smith, and Andrew Weil Killed the Fifties and Ushered in a New Age for America). ' +
					'"Timothy Leary had a foreboding feeling the first time he entered the cage, (through the imposing metal doors, and into the cell block. His surroundings seemed both strange and familiar.) This time he was just visiting. (He was a Harvard researcher with revolutionary ideas about how to reform the American prison system.) By the end of the decade, Leary would walk into another prison and find the cell door slammed shut behind him. By then, he would be a real revolutionary, the guy Richard Nixon would call \'the most dangerous man in America.\'"';
					
						
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 = "91lear";

