//                             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 = "There are so many orders of magnitude separating atoms from fluids brains or societies that vastly different "
					+ "models and methods are quite naturally employed in each realm Psychologists do not need to invoke quantum "
					+ "mechanics to maintain that in their field the observer affects the observed          "; // 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 = "THEREARESOMANYORDERSOFMAGNITUDESEPARATINGATOMSFROMFLUIDSBRAINSORSOCIETIESTHATVASTLYDIFFERENTMODELSANDMETHODSAREQUITE"
					+ "NATURALLYEMPLOYEDINEACHREALMPSYCHOLOGISTSDONOTNEEDTOINVOKEQUANTUMMECHANICSTOMAINTAINTHATINTHEIRFIELDTHEOBSERVER"
					+ "AFFECTSTHEOBSERVED";

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 ("Stuyvesant", "Offbeat", "Kettledrummer", "Animadversion", "LydianMode", "Frequency", "Amsterdam", "Steadfast", 
						"Heterochthonous", "InAFog", "Octahedron", "Narcoleptic", "Ascribe", "BoehmSystem", "Limped", "ElysianFields", 
						"Nonsteroidal", "OutOfTheQuestion", "Nitromethane", "Silverstar", "Ergotism", "Nightlife", "Siddhartha", "Evaporate");

var sWurdzString = "STUYVESANTOFFBEATKETTLEDRUMMERANIMADVERSIONLYDIANMODEFREQUENCYAMSTERDAMSTEADFASTHETEROCHTHONOUSINAFOGOCTAHEDRONNARCOLEPTIC"
				+ "ASCRIBEBOEHMSYSTEMLIMPEDELYSIANFIELDSNONSTEROIDALOUTOFTHEQUESTIONNITROMETHANESILVERSTARERGOTISMNIGHTLIFESIDDHARTHAEVAPORATE";

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("Last governor of New Netherlands (1592-1672)", "Odd", "Tympanist", "Criticism or censure", "Natural scale from F to F (2 wds.)", 
					"\"Kenneth, what's the __?\"", "City on the IJ", "Unwavering", "Not indigenous", "Perplexed, lost (3 wds.)", 
					"Platonic solid with six vertices", "Subject to frequent and uncontrollable periods of sleep", "Attribute", 
					"Method of keying and fingering a flute or clarinet (2 wds.)", "Favored a leg", "Paradise (2 wds.)", 
					"Type of anti-inflammatory drug such as aspirin", "Not to be considered (4 wds.)", 
					"Liquid used as solvent, rocket fuel and gasoline additive", "U.S. military award for gallantry in action (2 wds.)", 
					"Condition caused by eating fungus-infected grain products", "Activities after sundown", "Hesse novel", 
					"Disappear into thin air");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 1, 1, 1, 1,   1, 1, 1, 1, 1,   1, 2, 1, 2, 1,   1, 2, 1, 2, 2,  2, 1, 1, 1 ); // 24 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 (8, 166, 112, 82, 77, 89, 55, 108, 177, 216, 191, 228, 21, 238, 182, 58, 203, 172, 135, 196, 73, 123, 95, 83, 
							226, 52, 143, 181, 164, 47, 136, 39, 153, 44, 121, 157, 170, 71, 3, 107, 53, 48, 205, 51, 124, 244, 26, 5, 195, 
							10, 20, 100, 115, 85, 18, 222, 174, 119, 2, 162, 147, 13, 36, 126, 64, 161, 208, 88, 16, 202, 192, 72, 0, 131, 
							98, 94, 50, 117, 45, 178, 217, 110, 91, 213, 57, 158, 183, 74, 37, 1, 62, 99, 9, 28, 221, 67, 159, 78, 211, 129, 
							152, 14, 188, 206, 227, 148, 87, 106, 241, 237, 134, 169, 11, 120, 231, 160, 81, 173, 33, 27, 204, 66, 23, 97, 
							137, 15, 194, 220, 230, 56, 219, 68, 207, 22, 154, 130, 189, 234, 240, 101, 150, 70, 180, 127, 140, 215, 225, 
							142, 146, 156, 113, 185, 25, 86, 212, 218, 122, 132, 61, 90, 167, 199, 79, 190, 236, 63, 43, 38, 29, 141, 128, 
							171, 175, 69, 93, 46, 42, 138, 102, 111, 179, 243, 19, 232, 84, 65, 116, 12, 187, 155, 139, 151, 49, 7, 80, 104, 
							193, 60, 32, 145, 59, 96, 242, 4, 223, 31, 118, 75, 210, 17, 35, 24, 105, 200, 133, 233, 92, 186, 168, 40, 235, 
							114, 214, 198, 229, 163, 239, 209, 165, 54, 201, 176, 109, 76, 184, 197, 125, 224, 34, 144, 149, 6, 41, 103, 30);
								
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 = '(Alan) Sokal (and Jean Bricmont): <a href="http://www.amazon.com/gp/product/0312204078?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0312204078" target="_blank">Fashionable Nonsense</a> (Postmodern Intellectuals\' Abuse of Science). '
					+'"...there are so many orders of magnitude separating atoms from fluids, brains, or societies that vastly different models and methods are quite naturally employed in each realm... Psychologists ...do not need to invoke quantum mechanics to maintain that in their field \'the observer affects the observed;\' (this is a truism, irrespective of the behavior of electrons or atoms.)"';
					
						
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 = "55unce";
