//                             This file is copyright 2009 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 = "Meanwhile in Europe the Enlightenment was a reasonable time Bach was the most famous composer in the world and "
					+ "so was Handel Handel was half German half Italian and half English He was very large         "; // 9 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 = "MEANWHILEINEUROPETHEENLIGHTENMENTWASAREASONABLETIMEBACHWASTHEMOSTFAMOUSCOMPOSERINTHEWORLDANDSOWASHANDELHANDELWASHALF"
					+ "GERMANHALFITALIANANDHALFENGLISHHEWASVERYLARGE";

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 ("LechWalesa", "Earthworm", "Dharma", "Edwardian", "Rainbow", "Enthusiasm", "RedHot", "Swagmen", 
						"TienShan", "Utah", "DownEast", "Evenfall", "Noise", "Thames", "Bagel", "Limoges", "Oliphant", 
						"OneHalf", "Phenyl", "Elsewhen", "Raffia", "SmallChange");

var sWurdzString = "LECHWALESAEARTHWORMDHARMAEDWARDIANRAINBOWENTHUSIASMREDHOTSWAGMENTIENSHANUTAHDOWNEASTEVENFALLNOISETHAMES"
					+ "BAGELLIMOGESOLIPHANTONEHALFPHENYLELSEWHENRAFFIASMALLCHANGE";

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("Poland solidarity leader (full name)", "Member of genus Lumbricus", "The __ Bums (Kerouac)", 
						"Period from 1901-1910", "\"...add another hue Unto the __\" (King John, act IV sc. ii)", 
						"Zeal", "Sizzling, glowing (hyph.)", "Tramps, hoboes (Australian)", "Celestial Mountains on the Silk Road (2 wds.)", 
						"Beehive state", "Towards Maine from Boston (2 wds.)", "Dusk (poet.)", "Meaningless sound or data", "London's river", 
						"Doughnut-shaped roll", "French city known for porcelain", "Am. editorial cartoonist, Pulitzer prize 1966", 
						"Fifty percent (2 wds.)", "Chemical group containing 6 carbon and 5 hydrogen atoms", "At another time (obs.)", 
						"Fiber from a type of palm", "Something insignificant or trifling (2 wds.)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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

var iPuzzleLeftCoord = iCluesLeftCoord + 490;	// 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 = '(Richard) Lederer: (The World According to) Student Bloopers (in <a href="http://www.amazon.com/gp/product/044020352X?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=044020352X" target="_blank"><strong>Anguished English</strong></a>). '
					+'"Meanwhile in Europe, the Enlightenment was a reasonable time... Bach was the most famous composer in the world, and so was Handel. Handel was half German, half Italian, and half English. He was very large."';
					
						
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 = "46more";
