//                             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 = "Most people know about the Gulf Stream crossing the Atlantic in ten or so years But ocean currents have a third "
					+ "dimension with cold salty brine plunging to the depths of Davy Jones returning to the surface centuries later "
					+ "on the other side of the world"; // 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 = "MOSTPEOPLEKNOWABOUTTHEGULFSTREAMCROSSINGTHEATLANTICINTENORSOYEARSBUTOCEANCURRENTSHAVEATHIRDDIMENSIONWITHCOLDSALTY"
					+ "BRINEPLUNGINGTOTHEDEPTHSOFDAVYJONESRETURNINGTOTHESURFACECENTURIESLATERONTHEOTHERSIDEOFTHEWORLD";

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 ("Ruthless", "Onychoid", "Bosh", "Earwigs", "Roulette", "Tortoises", "Krumhorn", "Ablution", "Navarchy", "Duende", 
						"Effaces", "LongJump", "Withheld", "Angst", "Tessitura", "Enfield", "Rottenness", "Farctate", "Rhinitis", "Oppugned", 
						"Monotone", "Hoodwort", "Ecstatic", "Attain", "Vergency", "Ethelbert", "Norphlet");

var sWurdzString = "RUTHLESSONYCHOIDBOSHEARWIGSROULETTETORTOISESKRUMHORNABLUTIONNAVARCHYDUENDEEFFACESLONGJUMPWITHHELDANGSTTESSITURAENFIELD"
					+ "ROTTENNESSFARCTATERHINITISOPPUGNEDMONOTONEHOODWORTECSTATICATTAINVERGENCYETHELBERTNORPHLET";

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("Without pity", "Fingernail-like", "Nonsense, balderdash", "Forficula auricularia and others", "Wheeled game of chance", 
					"Certain long-lived Galapagos inhabitants", "Medieval double-reeded instrument", "Cleansing", "Nautical skill or experience (obs.)", 
					"Goblin, spirit, magic (Sp.)", "Wipes out, expunges", "Current Men's world record is 8.95 meters (2 wds.)", "Restrained; deducted, as from income", 
					"Dread", "General pitch range of a musical part", "Northernmost Greater London borough; type of rifle", "Despicability", 
					"Stuffed; filled solid (rare)", "Common cold symptom", "Assailed by criticism; disputed", "Unvarying in pitch", "Scullcap", "Rapturous", 
					"Reach, accomplish", "Tendency, leaning (rare)", "Son of Eormenric", "Arkansas town between El Dorado and Smackover");
					
					
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,   2, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 2 ); // 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 (33, 151, 159, 200, 106, 130, 136, 58, 98, 55, 142, 167, 103, 68, 37, 206, 15, 56, 64, 160, 21, 166, 174, 100, 88, 122, 
							147, 182, 188, 173, 8, 42, 86, 18, 29, 102, 197, 75, 48, 34, 175, 26, 117, 108, 10, 63, 163, 31, 186, 158, 57, 52, 14, 65, 
							178, 74, 3, 123, 59, 145, 99, 46, 141, 82, 204, 73, 41, 60, 90, 17, 170, 38, 195, 132, 77, 198, 25, 62, 32, 176, 162, 45, 
							137, 153, 125, 143, 120, 93, 4, 13, 115, 27, 129, 190, 61, 119, 91, 71, 124, 156, 193, 199, 185, 191, 96, 2, 101, 126, 23, 
							148, 140, 161, 116, 165, 51, 9, 110, 139, 89, 203, 134, 53, 181, 11, 78, 5, 177, 36, 138, 85, 164, 169, 67, 179, 19, 149, 
							114, 20, 154, 47, 97, 40, 194, 80, 1, 118, 7, 66, 22, 72, 196, 107, 0, 183, 155, 12, 44, 6, 171, 84, 135, 144, 127, 131, 
							202, 16, 76, 150, 187, 69, 35, 172, 30, 180, 92, 104, 109, 128, 79, 43, 49, 184, 83, 201, 192, 39, 94, 121, 50, 112, 168, 
							157, 81, 70, 24, 113, 54, 152, 189, 95, 105, 28, 133, 87, 205, 146, 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 = 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 = 'Robert Kandel: <a href="http://www.amazon.com/gp/product/0231122454?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0231122454" target="_blank">Water from Heaven</a> (The Story of Water From the Big Bang to the Rise of Civilization, and Beyond). '
					+'"Most people know about the Gulf Stream, crossing the Atlantic in ten or so years. But ocean currents have a third dimension, with cold salty brine plunging to the depths of Davy Jones, returning to the surface centuries later on the other side of the world."';
					
						
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 = "52curr";
