//                             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 = "The code breaks Perhaps this is best defined as the point when the likely leads appear faster than they can be followed "
					+ "up It is like the initiation of a chain reaction in atomic physics once the critical threshold is passed the reaction "
					+ "propagates itself         "; // 9 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 = "THECODEBREAKSPERHAPSTHISISBESTDEFINEDASTHEPOINTWHENTHELIKELYLEADSAPPEARFASTERTHANTHEYCANBEFOLLOWEDUPITISLIKETHE"
					+ "INITIATIONOFACHAINREACTIONINATOMICPHYSICSONCETHECRITICALTHRESHOLDISPASSEDTHEREACTIONPROPAGATESITSELF";

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 ("Chitchat", "Hestia", "Aspiring", "Defeated", "Whitewash", "Isolates", "Confit", "Keepsakes", "Dolph", "Epitaph", 
					"Counsels", "Inhibits", "Pirated", "Hockey", "Elephant", "Raphael", "Macabre", "Enlisted", "Niftiest", "Telstar", "Opiates", 
					"Feisty", "LastDitch", "Inches", "Notion", "Enforcer", "Apache", "Rhyolite", "Borodin");

var sWurdzString = "CHITCHATHESTIAASPIRINGDEFEATEDWHITEWASHISOLATESCONFITKEEPSAKESDOLPHEPITAPHCOUNSELSINHIBITSPIRATEDHOCKEYELEPHANTRAPHAELMACABRE"
					+ "ENLISTEDNIFTIESTTELSTAROPIATESFEISTYLASTDITCHINCHESNOTIONENFORCERAPACHERHYOLITEBORODIN";

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("Small talk", "Greek goddess of the hearth", "Hopeful, intending to achieve; wannabe", "Vanquished", 
					"Mixture used for painting walls; cover-up", "Quarantines, sequesters; obtains in a pure form", 
					"Meat cooked and preserved in its own fat (Fr.)", "Mementoes, souveneirs", "Director and He-Man Lundgren", 
					"W.B. Yeats' reads: \"Cast a cold Eye/ On Life, on Death./ Horseman, pass by.\"", "Advises", "Holds back, restrains, hampers", 
					"Copied material for profit without permission", "Field or ice", "African, Asian, Sri Lankan, Sumatran, or Borneo pygmy", 
					"Italian Renaissance painter (1483-1520)", "Word often associated with \"Danse\"", "Joined the military", "Most stylish or handy", 
					"Early communications satellite; instrumental pop hit of 1962", "Morphine, codeine, thebaine", "Spirited and gutsy, or touchy and aggressive", 
					"Final, usu. desperate act to achieve (with attempt or effort; hyph.)", "Goes slowly, creeps; baseball is sometimes said to be a game of this", 
					"Idea, belief, impulse", "Third \"Dirty Harry\" film (with \"The\")", "Geronimo, e.g.", "Type of igneous rock; southern Nevada ghost town", 
					"Russian composer and chemist (1833-1887)");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (1, 1, 1, 1, 1,   2, 2, 1, 1, 2,   1, 1, 2, 1, 2,   1, 1, 1, 1, 2,  1, 2, 2, 2, 1,  1, 1, 2, 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 (132, 172, 102, 140, 124, 157, 79, 191, 109, 75, 38, 81, 22, 123, 62, 19, 13, 176, 169, 127, 112, 200, 97, 35, 210, 170, 10, 
							29, 107, 183, 47, 78, 205, 162, 130, 95, 86, 148, 52, 113, 25, 119, 54, 131, 167, 155, 151, 159, 193, 45, 32, 118, 20, 11, 27, 
							61, 178, 204, 65, 106, 6, 23, 5, 141, 209, 66, 146, 203, 195, 137, 133, 72, 18, 168, 150, 173, 98, 136, 177, 83, 104, 207, 163, 
							34, 185, 115, 88, 134, 202, 171, 99, 149, 160, 189, 74, 14, 30, 125, 197, 164, 56, 31, 84, 158, 174, 96, 42, 82, 201, 153, 51, 
							187, 179, 145, 16, 69, 57, 166, 142, 116, 3, 165, 26, 196, 9, 41, 87, 93, 111, 180, 156, 49, 175, 128, 55, 90, 101, 44, 208, 73, 
							108, 184, 89, 60, 12, 0, 37, 8, 4, 198, 161, 139, 117, 68, 28, 71, 2, 192, 103, 39, 59, 92, 17, 181, 206, 63, 33, 46, 85, 1, 105, 
							120, 144, 21, 110, 64, 50, 94, 114, 143, 135, 194, 182, 80, 122, 91, 15, 190, 186, 129, 126, 67, 199, 154, 48, 188, 70, 40, 147, 
							121, 58, 100, 77, 53, 7, 152, 76, 43, 36, 24, 138);
								
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/John_Chadwick" target="_blank">(John) Chadwick</a>: <a href="http://www.amazon.com/gp/product/0521398304?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0521398304" target="_blank">(The) Decipherment of Linear B</a>. '
					+'"The code \'breaks\'. Perhaps this is best defined as the point when the likely leads appear faster than they can be followed up. It is like the initiation of a chain reaction in atomic physics; once the critical threshold is passed, the reaction propagates itself."';
					
						
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 = "80line";

