//                             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 = "Misuse of garlic is a crime Old garlic burnt garlic garlic cut too long ago and garlic that has been tragically "
					+ "smashed through one of those abominations the garlic press are all disgusting Smash it with the flat of your knife "
					+ "blade if you like but dont put it through a press"; // 0 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 = "MISUSEOFGARLICISACRIMEOLDGARLICBURNTGARLICGARLICCUTTOOLONGAGOANDGARLICTHATHASBEENTRAGICALLYSMASHEDTHROUGHONEOFTHOSE"
					+ "ABOMINATIONSTHEGARLICPRESSAREALLDISGUSTINGSMASHITWITHTHEFLATOFYOURKNIFEBLADEIFYOULIKEBUTDONTPUTITTHROUGHAPRESS";

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 ("Boasted", "Oligarchy", "Umbrosity", "Refragate", "DouglasFir", "Alioth", "Insight", "Nutmeg", "Kookaburra", 
						"Illogical", "Thaddeus", "ConSpirito", "Holmium", "Eightball", "Nesbit", "Casualness", "Onslaught", "NightCourt", 
						"Falangist", "Ideograph", "Dragonfly", "Earshot", "Newsflash", "Tourist", "Imperfect", "Acetic", "Lethargic");

var sWurdzString = "BOASTEDOLIGARCHYUMBROSITYREFRAGATEDOUGLASFIRALIOTHINSIGHTNUTMEGKOOKABURRAILLOGICALTHADDEUSCONSPIRITOHOLMIUMEIGHTBALL"
				+ "NESBITCASUALNESSONSLAUGHTNIGHTCOURTFALANGISTIDEOGRAPHDRAGONFLYEARSHOTNEWSFLASHTOURISTIMPERFECTACETICLETHARGIC";

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("Talked with excessive pride", "Rule by the few", "Shadiness", "To oppose (rare)", "Common softwood (2 wds.)", 
					"Big Dipper star", "Understanding", "Moluccan evergreen spice", "Laughing bird", "Mr. Spock's complaint", 
					"__ Kosciuszko, Revolutionary War hero", "Lively, with animation (musical direction; 2 wds.)", "Element named for Swedish capital", 
					"Pool game", "Florodora girl Evelyn", "Informality", "Furious attack", "80's TV show starring Harry Anderson (2 wds.)", 
					"Spanish fascist", "Chinese character", "Odonata anisoptera, e.g.", "Hearing distance", "Bulletin", "Pleasure traveler", "Flawed", 
					"Vinegar acid", "Sluggish");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 1, 1, 1, 1,   1, 1, 1, 1, 1,   1, 2, 1, 1, 1,   1, 1, 2, 1, 1,  1, 1, 1, 1, 1,  1, 1   ); // 27 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 (31, 60, 43, 94, 168, 5, 189, 105, 23, 119, 8, 115, 66, 41, 74, 177, 216, 0, 186, 82, 101, 152, 19, 174, 
							90, 180, 21, 109, 27, 159, 130, 16, 212, 143, 24, 175, 3, 84, 196, 188, 113, 171, 46, 10, 173, 146, 162, 
							194, 73, 111, 68, 80, 4, 154, 103, 161, 50, 106, 179, 209, 118, 199, 57, 198, 55, 22, 181, 75, 116, 208, 
							44, 100, 83, 183, 45, 39, 52, 64, 148, 86, 58, 28, 211, 218, 37, 63, 97, 190, 201, 223, 47, 215, 34, 157, 
							136, 85, 38, 191, 51, 108, 213, 124, 54, 158, 40, 32, 20, 78, 210, 25, 128, 206, 200, 72, 133, 89, 205, 129, 
							149, 77, 14, 70, 69, 141, 15, 195, 121, 88, 155, 96, 224, 160, 178, 125, 140, 145, 93, 49, 59, 167, 163, 182, 
							123, 217, 95, 81, 48, 117, 102, 142, 110, 184, 26, 11, 144, 120, 42, 134, 91, 35, 1, 147, 185, 204, 156, 137, 
							9, 220, 104, 203, 221, 131, 150, 6, 56, 176, 187, 193, 79, 61, 33, 126, 71, 53, 166, 62, 114, 164, 2, 192, 172, 
							219, 139, 99, 122, 112, 151, 18, 165, 76, 202, 197, 92, 207, 170, 214, 7, 222, 13, 98, 65, 30, 107, 127, 12, 
							135, 67, 138, 153, 169, 87, 132, 36, 29, 17);
								
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 = '(Anthony) Bourdain: <a href="http://www.amazon.com/gp/product/0060899220?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0060899220" target="_blank">Kitchen Confidential</a> (Adventures in the Culinary Underbelly). '
					+'"Misuse of garlic is a crime. Old garlic, burnt garlic, garlic cut too long ago and garlic that has been tragically smashed through one of those abominations, the garlic press, are all disgusting. Smash it, with the flat of your knife blade if you like, but don\'t put it through a press."';
					
						
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 = "48opin";
