//                             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 = "The blues especially in its early years with its beginnings in rural folk and oral traditions simply has no "
					+ "hard-and-fast recorded history For each blues master we know of for each Bessie Smith Robert Johnson and "
					+ "Muddy Waters it is possible that there is another unknown unrecorded master whose voice will never be heard   "; // 4 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 = "THEBLUESESPECIALLYINITSEARLYYEARSWITHITSBEGINNINGSINRURALFOLKANDORALTRADITIONSSIMPLYHASNOHARDANDFASTRECORDEDHISTORY"
					+ "FOREACHBLUESMASTERWEKNOWOFFOREACHBESSIESMITHROBERTJOHNSONANDMUDDYWATERSITISPOSSIBLETHATTHEREISANOTHERUNKNOWNUNRECORDED"
					+ "MASTERWHOSEVOICEWILLNEVERBEHEARD";

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.
var aWurdz = new Array ("CountNoses", "Redwoods", "Awkwardest", "InkSlinger", "Ghostwriter", "Abscond", "Windjammer", "Manifesto", 
						"IllFavoured", "LathHouse", "LundysLane", "Effrontery", "Rocinante", "Theobald", "Hairbreadth", "Imbricated", 
						"Stravinsky", "Hearthstone", "Ostensibly", "Useless", "Sachet", "Endlessly", "Ophiophobes", "NumberTwo", 
						"FairWeather", "IrishHarp", "Ricinolein", "EasyRider"); // 28 total

var sWurdzString = "COUNTNOSESREDWOODSAWKWARDESTINKSLINGERGHOSTWRITERABSCONDWINDJAMMERMANIFESTOILLFAVOUREDLATHHOUSELUNDYSLANEEFFRONTERY"
					+ "ROCINANTETHEOBALDHAIRBREADTHIMBRICATEDSTRAVINSKYHEARTHSTONEOSTENSIBLYUSELESSSACHETENDLESSLYOPHIOPHOBESNUMBERTWO"
					+ "FAIRWEATHERIRISHHARPRICINOLEINEASYRIDER";

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("Take census (2 wds.)", "The northernmost US grove of these is in Alfred A. Loeb State Park", "Least graceful", 
					"Writer, newspaper reporter (slang; hyph.)", "Paid but uncredited author", "Make off", "Large sailing ship", 
					"Public declaration of intentions, motives, etc.", "\"An __ thing, sir, but mine own.\" (hyph.; As You Like It, act 3 sc. 5)", 
					"Structure used to temporarily protect plants (2 wds.)", "1814 Canadian battlefield (2 wds.)", "Shameless audacity", 
					"Quixote's steed", "Patron saint of charcoal-burners", "Short distance; narrow gap", "Overlapped like roof shingles", 
					"Petrouchka composer", "Home, figuratively", "Apparently", "Unavailing", "Small perfumed bag", "Forever", 
					"Those with an excessive fear of snakes", "Patrick McGoohan's interrogator (The Prisoner; 2 wds.)", 
					"Failing in difficult times (hyph.)", "Clairseach (2 wds.)", "Chief constituent of castor oil", "Dennis Hopper film (2 wds.)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 2, 1, 1, 1,   1, 1, 2, 2, 1,   1, 1, 1, 1, 1,   1, 1, 1, 1, 1,   1, 1, 1, 2, 1,  1, 1, 1  );
// 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 (120, 160, 53, 136, 187, 87, 228, 22, 153, 208, 52, 214, 230, 221, 103, 88, 107, 154, 145, 138, 218, 239, 
							14, 31, 71, 23, 86, 111, 79, 94, 60, 193, 16, 34, 210, 48, 41, 184, 42, 147, 116, 185, 0, 133, 143, 13, 68, 
							237, 205, 181, 161, 129, 146, 166, 219, 174, 33, 74, 19, 264, 165, 119, 155, 233, 8, 229, 80, 70, 173, 188, 
							96, 183, 126, 38, 75, 50, 67, 59, 140, 24, 244, 211, 216, 257, 248, 105, 251, 90, 198, 260, 240, 142, 223, 
							189, 106, 4, 124, 44, 92, 28, 78, 252, 66, 171, 243, 259, 57, 115, 69, 245, 62, 164, 29, 225, 179, 113, 58, 
							247, 72, 51, 97, 168, 35, 125, 21, 89, 144, 64, 40, 172, 196, 232, 199, 262, 246, 91, 258, 100, 231, 55, 95, 
							236, 213, 152, 175, 195, 117, 46, 227, 85, 157, 11, 63, 32, 73, 25, 61, 255, 186, 47, 9, 135, 114, 1, 118, 
							30, 163, 182, 84, 192, 202, 220, 76, 134, 137, 151, 99, 226, 253, 7, 37, 3, 82, 17, 5, 110, 101, 15, 256, 
							169, 150, 39, 128, 102, 108, 197, 201, 206, 45, 177, 56, 149, 235, 98, 123, 83, 139, 10, 203, 250, 191, 81, 
							121, 112, 148, 131, 242, 222, 176, 127, 122, 204, 65, 212, 180, 170, 141, 209, 194, 104, 249, 6, 200, 130, 
							158, 261, 238, 20, 159, 109, 49, 167, 36, 234, 132, 190, 263, 207, 12, 18, 224, 241, 26, 254, 43, 217, 2, 
							93, 77, 27, 54, 156, 178, 162, 215);
								
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 = 'Craig Awmiller: <a href="http://www.amazon.com/gp/product/0756778263?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0756778263" target="_blank">This House on Fire</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0756778263" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> (The Story Of The Blues). '
					+'"The blues -- especially in its early years, with its beginnings in rural, folk, and oral traditions -- simply has no hard-and-fast recorded history. For each blues master we know of, for each Bessie Smith, Robert Johnson, and Muddy Waters, it is possible that there is another unknown, unrecorded master whose voice will never be heard."';
					
						
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 = "29bluz";
