//                             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 = "In Germany the war was an unmitigated catastrophe In Europe it was equally although in a different way catastrophic "
					+ "The peace which had settled the disputes of Germany with comparative success because passions had cooled was totally "
					+ "ineffectual in settling the problems of Europe         "; // 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 = "INGERMANYTHEWARWASANUNMITIGATEDCATASTROPHEINEUROPEITWASEQUALLYALTHOUGHINADIFFERENTWAYCATASTROPHICTHEPEACEWHICHHADSETTLED"
					+ "THEDISPUTESOFGERMANYWITHCOMPARATIVESUCCESSBECAUSEPASSIONSHADCOOLEDWASTOTALLYINEFFECTUALINSETTLINGTHEPROBLEMSOFEUROPE";

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.
var aWurdz = new Array ("Wallenstein",  "EscapeHatch", "DeathToll", "Grasshopper",  "Westphalia",  "OutOfTheWay", "Obfuscates",  "Dogpatch", "TrafficCop",  
						"Hatshepsut", "Escalante",  "Typewriter", "Hematomancy",  "Infatuated",  "Richelieu", "ThisWorld",  "YellowPine",   "YamatoE",  
						"Edifice", "Advantageous", "Rhine", "SineQuaNon", "Witticism", "Assumed", "Regensburg");

var sWurdzString = "WALLENSTEINESCAPEHATCHDEATHTOLLGRASSHOPPERWESTPHALIAOUTOFTHEWAYOBFUSCATESDOGPATCHTRAFFICCOPHATSHEPSUTESCALANTETYPEWRITERHEMATOMANCY"
					+ "INFATUATEDRICHELIEUTHISWORLDYELLOWPINEYAMATOEEDIFICEADVANTAGEOUSRHINESINEQUANONWITTICISMASSUMEDREGENSBURG";

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("Bohemian (1583-1634) who became commander of the Hapsburg army" ,"Emergency exit (2 wds.)", 
						"The  _____ of the war is estimated at 15-20% of the German population (2 wds.)",
						"\"Fairy chess\" piece that moves like a queen but only by jumping over another piece", "The Peace (or Treaty) of ____ ended the war", 
						"Off the beaten path; \"Move!\" (4 wds.)", "Confuses the issue",
						"Al Capp's fictional town", "He (or she) keeps the streets safe (2 wds.)", "She is generally regarded as one of the most successful pharaohs", 
						"The Grand Staircase-____ National Monument", "Personal computers made it obsolete", "Divination using blood", "Moonstruck, besotted",
						"French Cardinal (1585–1642) who schemed against the Hapsburgs" , 
						"\"How weary, stale, flat, and unprofitable Seem to me all the uses of ____\" (Hamlet Act I sc. 2; 2 wds.)", 
						"Loblolly, Slash, Shortleaf, Ponderosa, e.g. (2 wds.)", "Narrative style of Japanese painting characterized by continuous illustrations (hyph.)", 
						"Building, structure", "Putting one in a favorable position", "Strategically important river in western Germany",
						"Essential (Lat., 3 wds.)", "Cleverly funny or ironic remark","Supposed, without proof; adopted", 
						"City where Electors of the Holy Roman Empire met in 1630 and 1636");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

						
var aClueLines = new Array (2, 1, 2, 2, 1,   1, 1, 1, 1, 2,   1, 1, 1, 1, 2,   3, 2, 2, 1, 1,  2, 1, 1, 1, 2);
// 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 (52, 6, 59, 117, 163, 208, 188, 90, 104, 124, 1, 29, 209, 96, 192, 169, 41, 10, 165, 115, 158, 65, 119, 225, 53, 33, 40, 191, 
							181, 63, 206, 2, 78, 27, 89, 113, 109, 131, 100, 147, 210, 135, 140, 219, 171, 24, 234, 177, 13, 193, 50, 150, 190, 166, 211, 
							174, 199, 9, 69, 114, 105, 205, 139, 47, 162, 75, 231, 35, 31, 83, 203, 118, 130, 179, 233, 68, 48, 137, 189, 202, 106, 97, 37, 
							62, 200, 229, 196, 85, 108, 222, 93, 121, 88, 128, 176, 110, 168, 220, 161, 57, 64, 49, 227, 103, 16, 213, 86, 43, 28, 235, 217, 
							195, 126, 122, 15, 221, 107, 87, 3, 149, 98, 44, 136, 32, 116, 92, 226, 187, 175, 157, 84, 152, 21, 76, 72, 36, 127, 111, 81, 101, 
							185, 14, 141, 164, 218, 79, 194, 0, 230, 156, 212, 94, 25, 172, 186, 38, 232, 224, 30, 8, 198, 60, 183, 228, 12, 39, 70, 138, 129, 
							61, 18, 22, 34, 120, 182, 201, 55, 123, 207, 132, 173, 144, 159, 178, 73, 153, 148, 215, 142, 58, 133, 99, 66, 204, 54, 46, 143, 42, 
							71, 77, 167, 214, 19, 184, 56, 45, 102, 197, 145, 7, 82, 23, 51, 151, 95, 180, 74, 155, 146, 170, 125, 17, 67, 5, 134, 112, 91, 11, 
							26, 154, 80, 160, 223, 20, 4, 216);
								
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 = 260;
var iLineHeight = 23;
var iTotalCluesHeight = 0; // Calculated in initPuzzle.
var iPadFactor = 8;

var iPuzzleLeftCoord = iCluesLeftCoord + 470;	// 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 = '(C. V.) Wedgwood: <a href="http://www.amazon.com/gp/product/1590171462?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1590171462" target="_blank">The Thirty Years War</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=1590171462" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. '
					+'"In Germany the war was an unmitigated catastrophe. In Europe it was equally, although in a different way, catastrophic. The peace, which had settled the disputes of Germany with comparative success because passions had cooled, was totally ineffectual in settling the problems of Europe."';
					
						
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 = "22prob";
