//                             This file is copyright 2009 by Michael H. Dickman. All rights reserved.


// The quote, without punctuation but with spaces and capitalization. Used to display the blank grid and the grid with solution.
var sAcrostiString = "Watanabe was known as Staff Officer for Chess since his chief duty seemed to be playing Shogi with the "
					+ "commander-in-chief Yamamoto usually beat Watanabe but on at least one occasion he had bet and lost his "
					+ "entire uniform        "; // 8 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. It is used to determine whether the puzzle has been solved.
var sSolutionString = "WATANABEWASKNOWNASSTAFFOFFICERFORCHESSSINCEHISCHIEFDUTYSEEMEDTOBEPLAYINGSHOGIWITHTHECOMMANDERINCHIEF"
					+ "YAMAMOTOUSUALLYBEATWATANABEBUTONATLEASTONEOCCASIONHEHADBETANDLOSTHISENTIREUNIFORM";

var iTotalLetters = sSolutionString.length; // Total number of letters (no spaces) in quote (and therefore Wurdz).

var aWurdz = new Array ("Tmesis", "HamSandwich", "OutOfWhack", "Maintenance", "Astute", "Surfboard", "Stogey", "Efficiencies", 
					"AsideFrom", "Obambulate", "Falsifiability", "TheLohDownOnScience", "Hayworth", "UnitsOfMass", "NewStoneAge", 
					"DaytonaBeach", "Elephant", "Rathbone");

var sWurdzString = "TMESISHAMSANDWICHOUTOFWHACKMAINTENANCEASTUTESURFBOARDSTOGEYEFFICIENCIESASIDEFROMOBAMBULATEFALSIFIABILITY"
					+ "THELOHDOWNONSCIENCEHAYWORTHUNITSOFMASSNEWSTONEAGEDAYTONABEACHELEPHANTRATHBONE";

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("Grammatical term for such constructions as fan-freakin-tastic", "Food item in danger of indictment (2 wds.)", 
					"Misaligned, inconsonant, not as it should be (3 wds.)", 
					"\"I saw him hold Lord Percy at the point with lustier ____ than I did look for ...\" (Henry IV, Part I, Act V, sc. 4)", 
					"Shrewd, savvy", "Equipment found at Malibu or Waikiki", "Cheap cigar (variant spelling)", "One room apartments", 
					"Other than (2 wds.)", "To walk about aimlessly (archaic word revived in recent political commentary)", 
					"Criterion to separate scientific hypotheses from dogma or pseudoscience", 
					"Caltech's daily one minute radio show, since 2005 (5 wds.)", "Movie star known as \"The Love Goddess\"", 
					"Pound, slug, stone, and scruple (3 wds.)", "When the ax and the hoe were invented (3 wds.)", 
					"Atlantic east coast city known for its auto races (2 wds.)", 
					"It's not good to have a white one or ignore one in the room", "Actor who played Sherlock Holmes in the 1940's");

var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 1, 2, 3, 1,   1, 1, 1, 1, 2,   2, 2, 1, 1, 1,   2, 2, 1 ); //Number of clues: 18
// 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 (170, 86, 116, 55, 97, 36, 96, 103, 87, 18, 136, 4, 160, 8, 171, 46, 165, 107, 174, 61, 85, 25, 0, 47, 16, 
							33, 11, 180, 101, 147, 159, 118, 42, 140, 132, 89, 27, 64, 122, 72, 129, 110, 133, 59, 45, 108, 29, 22, 155, 
							139, 124, 172, 60, 109, 53, 105, 75, 49, 68, 57, 24, 99, 76, 41, 93, 28, 70, 84, 176, 156, 17, 5, 163, 78, 
							154, 35, 50, 179, 142, 104, 31, 125, 153, 58, 6, 52, 66, 145, 138, 83, 30, 88, 112, 137, 44, 21, 166, 9, 63, 
							48, 161, 26, 79, 54, 81, 34, 91, 113, 162, 43, 51, 74, 119, 123, 62, 15, 10, 95, 39, 151, 175, 144, 168, 73, 
							1, 100, 14, 130, 92, 157, 82, 128, 94, 69, 106, 167, 13, 177, 102, 3, 38, 146, 169, 56, 77, 37, 19, 148, 12, 
							141, 117, 71, 173, 90, 67, 114, 121, 178, 40, 20, 127, 135, 158, 143, 152, 98, 134, 7, 65, 80, 111, 149, 2, 
							32, 120, 164, 150, 115, 23, 131, 126);
								
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 = 310;

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

var iPuzzleLeftCoord = iCluesLeftCoord + 600;	// 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 = '(Evan) Thomas:  <a href="http://www.amazon.com/gp/product/0743252225?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0743252225" target="_blank">Sea of Thunder</a> (Four Commanders and the Last Great Naval Campaign 1941-1945). '
					+'"(...Yasugi) Watanabe (who) was known as "Staff Officer for Chess," since his chief duty seemed to be playing Shogi, (Japanese chess), with the commander-in-chief. Yamamoto usually beat Watanabe, but on at least one occasion he had bet and lost his entire uniform."';
					
						
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 = "10gsig";

