//                             This file is copyright 2008 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 = "You can almost always think of a scenario in which unquestioned beliefs could be wrong Is Paris the capital "
					+ "of France Very likely it is but Its barely conceivable that our government is a totalitarian conspiracy that "
					+ "does not want its citizens to know the real capital of France"; // ? 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 = "YOUCANALMOSTALWAYSTHINKOFASCENARIOINWHICHUNQUESTIONEDBELIEFSCOULDBEWRONGISPARISTHECAPITALOFFRANCEVERYLIKELY"
					+ "ITISBUTITSBARELYCONCEIVABLETHATOURGOVERNMENTISATOTALITARIANCONSPIRACYTHATDOESNOTWANTITSCITIZENSTOKNOWTHEREALCAPITALOFFRANCE";

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

var aWurdz = new Array ("Puccini",  "OffGuard", "Unitary",  "Noose",  "Doubtless", "Sentinel",  "Tentative", "Octavian",  
						"Nichts",  "Elaborate", "Lamb",  "Aznavour",  "Brittany", "YellowAlert",  "RiceWine",   "IpsoFacto",  
						"Nonstick",  "Tailgate",  "Hairstylist",  "Shamrock", "Ostracon", "Finally", "Ricotta", "Eloquence", "Apiphobia", 
						"Swanwick", "OffWithHerHead", "Necessity");

var sWurdzString = "PUCCINIOFFGUARDUNITARYNOOSEDOUBTLESSSENTINELTENTATIVEOCTAVIANNICHTSELABORATELAMBAZNAVOURBRITTANYYELLOWALERTRICEWINEIPSOFACTO"
					+ "NONSTICKTAILGATEHAIRSTYLISTSHAMROCKOSTRACONFINALLYRICOTTAELOQUENCEAPIPHOBIASWANWICKOFFWITHHERHEADNECESSITY";

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("Italian composer (1858-1924; \"Tosca\")" ,"Unprepared (2 wds.)", "Single" ,"Deadly loop",
						"No question", "Watch keeper", "Provisional", "Young Caesar Augustus",
						"Nothing, auf Deutsch", "Complicated; explain in detail", "English essayist and critic Charles (1775-1834)", 
						"French singer, actor, composer Charles (b. 1924)" ,"Region in northwest France", "\"Elevated\" threat level (2 wds.)", 
						"Sake (2 wds.)","By that very action (Lat., 2 wds.)", "Like Teflon", "Follow too closely", 
						"Coiffeur, coiffeuse", "Ireland's national emblem", "Potsherd, used e.g. as a ballot in ancient Greece", "At last",
						"A soft Italian cheese", "Fluent or persuasive speech", "Inordinate fear of bees", "Author (b. 1950, \"Stations of the Tide\")",
						"Red Queen's shriek (4 wds.)", "It's not optional");

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

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

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 = '(William) Poundstone:  <a href="http://www.amazon.com/gp/product/0385242719?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0385242719" target="_blank">Labyrinths of Reason</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0385242719" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />.'
					+'"You can almost always think of a scenario in which unquestioned beliefs could be wrong. Is Paris the capital of France? Very likely it is, but (still, there is a sliver of doubt that never vanishes.) It\'s barely conceivable that our government is a totalitarian conspiracy that, (for reasons of its own,) does not want its citizens to know the real capital of France."';
					
						
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 = "10laby";
