//                             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 = "For years the Netherlanders secretly cultivated coffee in Suriname They took great care to prevent Brazil from "
					+ "acquiring any beans The whole enterprise foundered when a Brazilian espionage mission managed to smuggle the "
					+ "bean out of the country         "; // 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 = "FORYEARSTHENETHERLANDERSSECRETLYCULTIVATEDCOFFEEINSURINAMETHEYTOOKGREATCARETOPREVENTBRAZILFROMACQUIRINGANYBEANS"
					+ "THEWHOLEENTERPRISEFOUNDEREDWHENABRAZILIANESPIONAGEMISSIONMANAGEDTOSMUGGLETHEBEANOUTOFTHECOUNTRY";

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 ("Watergate", "Housefly", "InnerEar", "Tariff", "Environment", "Beech", "Operettas", "Urbanite", "Curtain", 
					"Kvetched", "Equestrian", "Trolley", "Haphazard", "Effigies", "Ursine", "Norsemen", "Detach", "Utensil", "Topaz", 
					"Concedes", "HenryMorgan", "Audiology", "Beamish", "LeftBower", "Entomology", "Sargent");

var sWurdzString = "WATERGATEHOUSEFLYINNEREARTARIFFENVIRONMENTBEECHOPERETTASURBANITECURTAINKVETCHEDEQUESTRIANTROLLEYHAPHAZARDEFFIGIES"
					+ "URSINENORSEMENDETACHUTENSILTOPAZCONCEDESHENRYMORGANAUDIOLOGYBEAMISHLEFTBOWERENTOMOLOGYSARGENT";

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("Hotel, scene of a famous 1972 burglary", "Musca domestica", "Sense of balance location (2 wds.)", "Tax or duty", 
					"Green party concern", "Deciduous tree, its name also meant 'book' in Old English", "Gilbert and Sullivan works", 
					"City dweller", "Novel about Hercule Poirot's last case", "Complained constantly (Yiddish)", 
					"Type of nomad, statue, or Olympic event", "Street car", "Depending on chance", "Crude likenesses, often for burning", 
					"Bearlike", "Vikings", "Take off", "Implement", "Gemstone; 1969 Hitchcock film", "Allows; resigns", 
					"Welsh pirate, subject of John Steinbeck's first novel (full name)", "Study of hearing disorders", 
					"Adjective describing a jabberwock slayer", "Second-highest trump card in euchre (2 wds.)", "Study of second Word, e.g.", 
					"He painted three portraits of R. L. Stevenson");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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


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

var iPuzzleLeftCoord = iCluesLeftCoord + 470;	// 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 = '(Colin) White & (Laurie) Boucke: <a href="http://www.amazon.com/gp/product/1888580445?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1888580445" target="_blank">The UnDutchables</a> (An Observation of the Netherlands, its Culture and its Inhabitants). '
					+'"For years the Netherlanders secretly cultivated coffee in Suriname. They took great care to prevent Brazil from acquiring any beans. The whole enterprise foundered when a Brazilian espionage mission managed to smuggle the bean out of the country."';
					
						
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 = "71undu";
