//                             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 = "Quantum theory is puzzling because it challenges our standard ideas about the relationship between theory and observer "
					+ "The theory is indeed so puzzling that there is no universally accepted physical interpretation of it There is now no "
					+ "more agreement about what quantum theory means than when Einstein and Bohr first debated the question in the 1920s          "; // 10 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 = "QUANTUMTHEORYISPUZZLINGBECAUSEITCHALLENGESOURSTANDARDIDEASABOUTTHERELATIONSHIPBETWEENTHEORYANDOBSERVERTHETHEORYIS"
					+ "INDEEDSOPUZZLINGTHATTHEREISNOUNIVERSALLYACCEPTEDPHYSICALINTERPRETATIONOFITTHEREISNOWNOMOREAGREEMENTABOUTWHATQUANTUM"
					+ "THEORYMEANSTHANWHENEINSTEINANDBOHRFIRSTDEBATEDTHEQUESTIONINTHE1920S";

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 ("LedaAndTheSwan", "EquationOfState", "ElizabethanSonnet", "Strontium90", "ManInTheStreet", "Outhyperbolize", 
						"LeonidBrezhnev", "Interconnected", "Newsworthiness", "Quaternarian", "UnderTheWeather", "Asthenosphere", 
						"NotRightInTheHead", "TheoryOfBeauty", "Unoccupied", "Mephistopheles", "Gyrostabilizer", "Replicating", 
						"Adsbud", "Ventriloquism", "IshiharaTest", "TagDay", "YouMustBe21");

var sWurdzString = "LEDAANDTHESWANEQUATIONOFSTATEELIZABETHANSONNETSTRONTIUM90MANINTHESTREETOUTHYPERBOLIZELEONIDBREZHNEVINTERCONNECTED"
					+ "NEWSWORTHINESSQUATERNARIANUNDERTHEWEATHERASTHENOSPHERENOTRIGHTINTHEHEADTHEORYOFBEAUTYUNOCCUPIEDMEPHISTOPHELES"
					+ "GYROSTABILIZERREPLICATINGADSBUDVENTRILOQUISMISHIHARATESTTAGDAYYOUMUSTBE21";

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("Myth concerning the wife of Tyndareus (4 wds.)", "Mathematical description of a physical system (3 wds.)", 
					"Shakespeare poem, e.g. (2 wds.)", "Harmful fallout isotope (word, number)", "Average person (4 wds.)", 
					"Exceed in exaggeration", "USSR leader (1906-82; first and last names)", "Having several mutual relations or attachments", 
					"Notability", "Relating to the period after the Tertiary (rare)", "Not well (3 wds.)", "Upper layer of the Earth's mantle", 
					"Crazy (5 wds.)", "Aesthetics (3 wds.)", "Empty", "Faust's demon", "Device for counteracting outside forces", "Reproducing", 
					"Obsolete oath meaning \"God's blood\"", "Making sounds seem to come from elsewhere", "Color blindness screen (2 wds.)", 
					"Register your pet on National __ (2 wds.)", "Bar sign (3 wds., number)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 2, 1, 1, 1,   1, 2, 2, 1, 2,   1, 1, 1, 1, 1,   1, 1, 1, 1, 2,  1, 1, 1 ); // 23 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 (125, 176, 93, 241, 223, 210, 115, 62, 229, 159, 280, 217, 153, 284, 156, 277, 215, 26, 105, 253, 231, 194, 141, 184, 
							238, 132, 2, 266, 116, 172, 68, 180, 123, 203, 95, 279, 287, 75, 56, 3, 265, 88, 114, 237, 79, 133, 74, 211, 89, 195, 
							254, 179, 263, 122, 199, 291, 293, 234, 270, 249, 126, 224, 4, 244, 146, 41, 102, 190, 135, 82, 274, 94, 1, 251, 218, 
							233, 174, 245, 98, 258, 120, 150, 169, 18, 189, 151, 207, 214, 73, 53, 257, 269, 201, 247, 17, 130, 48, 235, 99, 30, 
							242, 220, 37, 232, 155, 283, 140, 92, 9, 166, 63, 209, 160, 38, 206, 243, 193, 81, 108, 66, 216, 86, 20, 182, 100, 250, 
							57, 221, 226, 149, 271, 137, 44, 197, 50, 11, 111, 131, 143, 222, 246, 49, 87, 147, 228, 33, 276, 196, 289, 236, 177, 
							64, 191, 173, 34, 164, 158, 106, 252, 21, 259, 28, 77, 240, 83, 175, 202, 170, 72, 85, 136, 113, 39, 260, 239, 282, 256, 
							129, 288, 104, 162, 97, 178, 54, 80, 103, 107, 200, 205, 163, 183, 262, 59, 268, 219, 278, 225, 12, 142, 84, 42, 154, 25, 
							5, 161, 248, 55, 267, 227, 40, 15, 8, 138, 294, 281, 198, 121, 188, 29, 35, 272, 148, 128, 90, 261, 60, 119, 186, 167, 213, 
							13, 36, 71, 124, 67, 51, 109, 65, 157, 168, 192, 32, 58, 187, 285, 127, 22, 91, 273, 139, 78, 16, 52, 145, 230, 286, 46, 101, 
							76, 19, 10, 0, 27, 165, 112, 6, 185, 96, 275, 144, 134, 69, 264, 255, 31, 24, 45, 171, 7, 212, 204, 118, 47, 152, 110, 181, 
							43, 208, 61, 14, 70, 23, 117, 292, 290);
								
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 = 'Lee Smolin: <a href="http://www.amazon.com/gp/product/0465078362?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0465078362" target="_blank">(Three Roads to) Quantum Gravity</a>. '
					+'"Quantum theory is puzzling because it challenges our standard ideas about the relationship between theory and observer. The theory is indeed so puzzling that there is no universally accepted physical interpretation of it. ... There is now no more agreement about what quantum theory means than when Einstein and Bohr first debated the question in the 1920s."';
					
						
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 = "62smol";
