//                             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 = "Adagio for Strings A transcription of the slow movement of Samuel Barbers String Quartet made by the composer for "
					+ "Arturo Toscanini and the NBC symphony It was performed for the first time in New York on November 5 1938 and it "
					+ "subsequently has become not only the most popular piece by Barber but probably the most frequently played short "
					+ "work by any American composer     "; // 5 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 = "ADAGIOFORSTRINGSATRANSCRIPTIONOFTHESLOWMOVEMENTOFSAMUELBARBERSSTRINGQUARTETMADEBYTHECOMPOSERFORARTUROTOSCANINIANDTHE"
					+ "NBCSYMPHONYITWASPERFORMEDFORTHEFIRSTTIMEINNEWYORKONNOVEMBER51938ANDITSUBSEQUENTLYHASBECOMENOTONLYTHEMOSTPOPULARPIECE"
					+ "BYBARBERBUTPROBABLYTHEMOSTFREQUENTLYPLAYEDSHORTWORKBYANYAMERICANCOMPOSER";

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 ("StAnthonysFire", "LetterOfMarque", "OysterMushroom", "NoughtsAndCrosses", "Irresponsibly", "Magic8Ball", "ScotchSymphony", 
					"Kimberly", "YoureWayOff", "Lampshade", "Element59", "ContractBridge", "TypewriterRibbon", "Invertebrate", "Overstatement", 
					"NewbornBabe", "Anthropophobia", "Reattempt", "YerbaMate", "Opaque", "FirstOffender", "MindYourPsAndQs", "Unlucky13", "Shopworn", 
					"Information", "CombatBoots");

var sWurdzString = "STANTHONYSFIRELETTEROFMARQUEOYSTERMUSHROOMNOUGHTSANDCROSSESIRRESPONSIBLYMAGIC8BALLSCOTCHSYMPHONYKIMBERLYYOUREWAYOFFLAMPSHADE"
					+ "ELEMENT59CONTRACTBRIDGETYPEWRITERRIBBONINVERTEBRATEOVERSTATEMENTNEWBORNBABEANTHROPOPHOBIAREATTEMPTYERBAMATEOPAQUE"
					+ "FIRSTOFFENDERMINDYOURPSANDQSUNLUCKY13SHOPWORNINFORMATIONCOMBATBOOTS";

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("Ergotism (abbr. and 2 wds.)", "License to commit acts which otherwise would be piracy (3 wds.)", 
					"Edible fungus of the species Pleurotus (2 wds.)", "Tic-tac-toe in London (3 wds.)", "Negligently", 
					"Toy that answers questions (word, number, word)", "Mendelssohn's third (2 wds.)", "South African diamond city", 
					"You aren't even close (contrac. plus 2 wds.)", "Light covering", "Praseodymium (word, number)", "Whist descendent (2 wds.)", 
					"The ink cartridge replaced this (2 wds.)", "Spineless creature", "Exaggeration", "As innocent as a __ (2 wds.)", 
					"Fear of humans", "Try again", "South American holly (Ilex paraguariensis) containing caffeine (2 wds.)", "Unfathomable", 
					"Guilty, but without a previous record (2 wds.)", "Be careful, use your best manners (5 wds.)", "Ill omen (word, number)", 
					"Used, like a demo model", "Data", "\"Your mother wears __\", humorous insult (2 wds.)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 2, 2, 1, 1,   2, 1, 1, 2, 1,   1, 1, 1, 1, 1,   1, 1, 1, 3, 1,  2, 2, 1, 1, 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 (218, 144, 110, 286, 184, 252, 37, 45, 233, 119, 92, 4, 11, 53, 224, 173, 63, 46, 133, 143, 7, 258, 254, 2, 236, 68, 
							186, 201, 88, 80, 199, 113, 139, 149, 204, 262, 49, 214, 277, 300, 165, 289, 116, 40, 69, 3, 82, 128, 21, 105, 158, 
							112, 296, 60, 124, 301, 15, 44, 35, 109, 303, 8, 146, 274, 87, 207, 20, 131, 65, 283, 266, 120, 216, 247, 14, 127, 230, 
							179, 55, 19, 36, 269, 185, 22, 276, 257, 202, 197, 103, 271, 51, 122, 114, 297, 206, 161, 164, 228, 171, 200, 272, 96, 54, 
							196, 212, 221, 241, 94, 155, 160, 294, 287, 217, 141, 6, 195, 16, 298, 268, 188, 145, 76, 182, 59, 83, 249, 73, 138, 189, 
							66, 194, 175, 177, 104, 93, 264, 278, 99, 56, 293, 213, 117, 226, 27, 1, 67, 170, 242, 250, 299, 238, 279, 291, 12, 81, 34, 
							71, 91, 24, 234, 246, 30, 111, 292, 13, 41, 90, 163, 72, 192, 240, 64, 198, 219, 260, 142, 169, 159, 244, 61, 97, 50, 10, 253, 
							75, 229, 106, 32, 108, 42, 38, 172, 85, 137, 193, 79, 180, 187, 115, 285, 295, 265, 123, 134, 255, 25, 162, 227, 33, 47, 58, 
							153, 95, 18, 78, 130, 251, 26, 215, 43, 243, 151, 284, 290, 259, 237, 225, 154, 0, 101, 231, 280, 132, 235, 261, 191, 302, 135, 
							156, 57, 9, 74, 5, 147, 48, 205, 210, 140, 263, 239, 39, 148, 167, 273, 126, 136, 98, 281, 220, 256, 70, 181, 77, 190, 62, 52, 
							29, 211, 223, 118, 282, 267, 176, 178, 150, 275, 28, 222, 129, 203, 174, 166, 107, 125, 31, 245, 23, 86, 288, 208, 183, 102, 157, 
							84, 168, 121, 248, 270, 17, 232, 100, 209, 152, 89);
								
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 = 100;


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

var iPuzzleLeftCoord = iCluesLeftCoord + 500;	// 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 = '<a href="http://en.wikipedia.org/wiki/Nicolas_Slonimsky" target="_blank">(Nicolas) Slonimsky</a>: <a href="http://www.amazon.com/gp/product/0385414218?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0385414218" target="_blank">Lectionary of Music</a>. '
					+'"Adagio for Strings: A transcription of the slow movement of Samuel Barber\'s String Quartet made by the composer for Arturo Toscanini and the NBC symphony. It was performed for the first time in New York on November 5, 1938, and it subsequently has become not only the most popular piece by Barber but probably the most frequently played short work by any American composer."';
					
						
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 = 150; // May need to be changed depending on puzzle.

var sPuzzleCode = "79slon";

