//                             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 = "One thing that can be vexing to a baker or confectioner is having chocolate seize This is sometimes caused by "
					+ "overheating when the melted chocolate gets too hot and little hard lumps form in the chocolate A more common "
					+ "cause of chocolate seizing is when a small amount of liquid is accidentally added to the chocolate       "; // 7 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 = "ONETHINGTHATCANBEVEXINGTOABAKERORCONFECTIONERISHAVINGCHOCOLATESEIZETHISISSOMETIMESCAUSEDBYOVERHEATINGWHENTHEMELTED"
					+ "CHOCOLATEGETSTOOHOTANDLITTLEHARDLUMPSFORMINTHECHOCOLATEAMORECOMMONCAUSEOFCHOCOLATESEIZINGISWHENASMALLAMOUNTOFLIQUID"
					+ "ISACCIDENTALLYADDEDTOTHECHOCOLATE";

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 ("Loxahatchee", "Eclecticism", "Bobtail", "OfTheCloth", "Vaccinates", "IcemanCometh", "TheDetails", "Zealot", 
						"GhostDance", "Refinery", "Equivocated", "Actualize", "TheSword", "Bolshoi", "OldFashioned", "Outshines", 
						"Kathenotheism", "Ominously", "Fallingwater", "Conchotome", "Homecoming", "Overcast", "Cringes", "Optional", 
						"Loathsome", "Augmented", "Trachea", "Eddington");

var sWurdzString = "LOXAHATCHEEECLECTICISMBOBTAILOFTHECLOTHVACCINATESICEMANCOMETHTHEDETAILSZEALOTGHOSTDANCEREFINERYEQUIVOCATEDACTUALIZE"
					+ "THESWORDBOLSHOIOLDFASHIONEDOUTSHINESKATHENOTHEISMOMINOUSLYFALLINGWATERCONCHOTOMEHOMECOMINGOVERCASTCRINGESOPTIONAL"
					+ "LOATHSOMEAUGMENTEDTRACHEAEDDINGTON";

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("Name of river and wildlife refuge in Fla.", "Approach or technique that combines multiple theories or styles", 
					"In \"Jingle Bells,\" bells are on ____", "Clerical (referring to a person; 3 wds.)", "Gives a flu shot, e.g.", 
					"O'Neill play (2 wds. after The)", "Some say God is in these, others say it's the Devil (2 wds.)", "True believer, fanatic", 
					"19th century Native American religious movement (2 wds. after The)", "Where a substance is purified or converted into useful product", 
					"Used ambiguous language to dodge the question", "Make a reality (of something)", "What the pen is mightier than (2 wds.)", 
					"Moscow theater for opera and ballet", "So twentieth-century (hyph.)", "Upstages, overshadows", 
					"Term coined by philologist Max Mueller meaning the worship of one god at a time", "In a foreboding way", 
					"Famous house designed by Frank Lloyd Wright ", "Surgical instrument, from the Greek for cutting a shell", 
					"Fall school event welcoming back alumni", "Cloudy, dreary", "Cowers; winces", "Not required", "Detestable", 
					"Increased, added to", "Windpipe", "Astrophysicist who observed starlight bending in 1919");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 2, 1, 1, 1,   1, 2, 1, 2, 2,   2, 1, 1, 1, 1,   1, 2, 1, 2, 2,  1, 1, 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 (223, 118, 19, 166, 102, 231, 111, 253, 206, 80, 95, 16, 232, 213, 246, 117, 167, 64, 160, 71, 46, 108, 15, 191, 
							88, 248, 83, 45, 241, 255, 151, 121, 68, 159, 56, 214, 34, 125, 130, 91, 169, 33, 233, 5, 134, 193, 138, 261, 62, 
							229, 114, 173, 211, 10, 35, 82, 57, 75, 103, 127, 4, 250, 158, 61, 245, 141, 67, 215, 20, 258, 72, 199, 195, 133, 
							140, 31, 39, 123, 188, 152, 85, 139, 145, 212, 104, 38, 63, 32, 92, 36, 203, 99, 124, 153, 242, 107, 225, 84, 198, 
							17, 221, 163, 243, 238, 207, 247, 239, 180, 194, 218, 259, 146, 50, 65, 76, 11, 161, 236, 73, 101, 178, 172, 87, 26, 
							257, 192, 150, 94, 164, 137, 175, 110, 228, 222, 181, 210, 115, 78, 217, 6, 18, 135, 162, 182, 97, 204, 9, 227, 21, 
							2, 81, 28, 120, 60, 254, 184, 42, 131, 105, 47, 197, 234, 126, 79, 128, 177, 224, 156, 249, 147, 70, 136, 89, 186, 
							13, 240, 58, 200, 219, 100, 205, 48, 3, 168, 44, 12, 189, 201, 53, 142, 116, 23, 41, 154, 37, 106, 24, 170, 66, 174, 
							74, 216, 40, 208, 52, 129, 49, 29, 144, 187, 209, 230, 157, 190, 30, 98, 1, 7, 109, 183, 90, 149, 260, 69, 0, 237, 
							143, 165, 119, 185, 25, 132, 251, 196, 55, 176, 112, 96, 226, 202, 148, 43, 14, 220, 122, 235, 77, 93, 59, 256, 54, 
							252, 27, 86, 113, 244, 155, 179, 22, 8, 171, 51);
								
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 = '(David) Lebovitz: <a href="http://www.amazon.com/gp/product/1580084958?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1580084958" target="_blank">(The) Great Book of Chocolate</a>. '
					+'"One thing that can be vexing to a baker or confectioner is having chocolate seize. This is sometimes caused by overheating, when the melted chocolate gets too hot and little hard lumps form in the chocolate. A more common cause of chocolate seizing is when a small amount of liquid is accidentally added to the chocolate."';
					
						
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 = "60choc";
