//                             This file is copyright 2008 by Michael H. Dickman. All rights reserved.


// The quote, without punctuation but with spaces and capitalization. Used to display the blank grid and the grid with solution.
var sAcrostiString = "Hes left his boat behind the Spaniard said Hes jumped onto our rope Hes starting after us I can feel "
					+ "him Fezzik said His body weight on the rope Hell never catch up the Sicilian cried Inconceivable "
					+ "You keep using that word the Spaniard snapped I dont think it means what you think it does"; // Zero 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. It is used to determine whether the puzzle has been solved.
var sSolutionString = "HESLEFTHISBOATBEHINDTHESPANIARDSAIDHESJUMPEDONTOOURROPEHESSTARTINGAFTERUSICANFEELHIMFEZZIKSAID"
					+ "HISBODYWEIGHTONTHEROPEHELLNEVERCATCHUPTHESICILIANCRIEDINCONCEIVABLEYOUKEEPUSINGTHATWORDTHESPANIARDSNAPPED"
					+ "IDONTTHINKITMEANSWHATYOUTHINKITDOES";

var iTotalLetters = sSolutionString.length; // Total number of letters (no spaces) in quote (and therefore Wurdz).

var aWurdz = new Array ("WhippedUp",  "InStepWith", "Livestock",  "Lightyear",  "Inhibited", "Adhesives",  "Manhattan", "Griffith",  
						"Offenbach",  "LhasaApso", "Deathwish",  "Mooning",  "Adjourned", "Neophytes",  "Photosphere",   "Rotundity",  
						"Ionosphere",  "Nietzsche",  "Cozened",  "Erudite", "Skittish", "Skulked", "Bacteria", "Ruminate", "Indochina", 
						"Dubliners", "Escalate");

var sWurdzString = "WHIPPEDUPINSTEPWITHLIVESTOCKLIGHTYEARINHIBITEDADHESIVESMANHATTANGRIFFITHOFFENBACHLHASAAPSODEATHWISHMOONINGADJOURNED"
					+ "NEOPHYTESPHOTOSPHEREROTUNDITYIONOSPHERENIETZSCHECOZENEDERUDITESKITTISHSKULKEDBACTERIARUMINATEINDOCHINADUBLINERSESCALATE";

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("Prepared quickly (2 wds.)" ,"Synchronized, matching, agreeing (3 wds.)", "Farm animals" ,"\"Toy Story\" hero Buzz",
						"Hindered, restrained", "Glues", "Borough or mixed drink", "Actress Melanie (Body Double; Working Girl)",
						"Composer (1819-1880; \"Tales of Hoffmann\")", "Tibetan dog breed (2 wds.)", "Song title (The Police, 1979; \"Reggatta de Blanc\")", 
						"Dreamily infatuated" ,"Stopped, to be resumed later", "Beginners", "Luminous envelope of a star",
						"Sphericity", "Layer in sky able to reflect radio waves", "Philosopher (1844-1900; \"Beyond Good and Evil\")", 
						"Tricked, cheated", "Having much knowledge or learning", "Frisky, capricious, wary", "Moved furtively",
						"Prokaryote microorganisms", "Contemplate deeply and repeatedly", "Southeast Asia region", "James Joyce short story collection",
						"Increase rapidly; become more intense");

var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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

var iPuzzleLeftCoord = iCluesLeftCoord + 435;	// Distance of puzzle grid from left side.
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 = 'William Goldman: <a href="http://www.amazon.com/gp/product/0156035219?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0156035219" target="_blank">(The) Princess Bride</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0156035219" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />.'
					+'"He\'s left his boat behind," the Spaniard said. "He\'s jumped onto our rope. He\'s starting after us." "I can feel him," Fezzik said. "His body weight on the rope." "He\'ll never catch up!" the Sicilian cried. "Inconceivable!" "You keep using that word!" the Spaniard snapped. "I don\'t think it means what you think it does."';
					
						
var iInstructionsTop = (iBoxHeight * iBoxDown) + iPuzzleTopCoord + 30; // Thirty pixels below the bottom of the puzzle.
var iInstructionsLeft = iPuzzleLeftCoord;
var iInstructionsWidth = iBoxAcross * iBoxWidth; // Width of grid, approx.
var iInstructionsHeight = 50; // May need to be changed depending on puzzle.

var sPuzzleCode = "9princ";
