//                             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 = "A buccaneer-scholar is anyone whose love of learning is not muzzled yoked or shackled by any institution or authority "
					+ "whose mind is driven to wander and find its own voice and place in the world Whenever I meet people who think for "
					+ "themselves I see them as fellow buccaneers  "; // 2 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 = "ABUCCANEERSCHOLARISANYONEWHOSELOVEOFLEARNINGISNOTMUZZLEDYOKEDORSHACKLEDBYANYINSTITUTIONORAUTHORITYWHOSEMINDISDRIVENTO"
					+ "WANDERANDFINDITSOWNVOICEANDPLACEINTHEWORLDWHENEVERIMEETPEOPLEWHOTHINKFORTHEMSELVESISEETHEMASFELLOWBUCCANEERS";

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 ("Brownian", "AlephZero", "Cynicism", "Hotshot", "Scrubs", "Endymion", "Cortisone", "Rhizome", "Eleven", "Tweaked", 
						"Sleuthing", "Offended", "Fished", "Avalon", "Boethius", "Unhorsed", "CatFeet", "Chopin", "Ankara", "Newlyweds", 
						"Entwines", "Empower", "Rivulets", "Solemnity", "Croakily", "Helvetia", "Olivine", "Lowdown", "Arcades", "Rodanthe");

var sWurdzString = "BROWNIANALEPHZEROCYNICISMHOTSHOTSCRUBSENDYMIONCORTISONERHIZOMEELEVENTWEAKEDSLEUTHINGOFFENDEDFISHEDAVALONBOETHIUSUNHORSED"
					+ "CATFEETCHOPINANKARANEWLYWEDSENTWINESEMPOWERRIVULETSSOLEMNITYCROAKILYHELVETIAOLIVINELOWDOWNARCADESRODANTHE";

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("Type of random motion of small particles in fluid", "Smallest infinite cardinal number (2 wds.; var.)", 
					"Disenchantment, suspicion", "Virtuoso, star; time-sensitive delivery; type of firefighting crew", "Medical-themed TV series", 
					"Mythological person, title of poems by Keats, Longfellow, and Wilde", "Anti-inflammatory hormone", "Ginger, e.g.", 
					"Smallest positive integer having three syllables", "Twisted or pulled sharply; made a fine adjustment", 
					"Investigating, as a detective", "Insulted, displeased", "Angled", "City on Santa Catalina Island", 
					"6th century philosopher, executed by Theodoric the Great", "Forced off one's mount; toppled", 
					"\"The fog comes / on little _____\" (Sandburg; 2 wds.)", "Pianist and composer (1810-1849)", "Capital of Turkey", 
					"Recently married couple", "Twists together, interlaces", "Give strength, authority, or ability to one", "Small streams", 
					"Quality of being serious and dignified", "In a deep, hoarse manner (of a voice)", "Switzerland (Lat.)", 
					"Common yellow-green mineral", "Dirty, rotten; inside story, scoop", "Places where video games and pinball machines might be found", 
					"\"Nights in ____,\" 2008 film");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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 = '(James Marcus) Bach: <a href="http://www.amazon.com/gp/product/1439109087?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1439109087" target="_blank">Secrets of a Buccaneer-Scholar</a> (How Self-Education and the Pursuit of Passion Can Lead to a Lifetime of Success). '
					+'"A buccaneer-scholar is anyone whose love of learning is not muzzled, yoked, or shackled by any institution or authority; whose mind is driven to wander and find its own voice and place in the world. ... Whenever I meet people who think for themselves, I see them as fellow buccaneers."';
					
						
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 = "61bucc";

