//                             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 = "Economists love incentives They love to dream them up and enact them study them and tinker with them The typical "
					+ "economist believes the world has not yet invented a problem that he cannot fix if given a free hand to design the "
					+ "proper incentive scheme  "; // 2 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 = "ECONOMISTSLOVEINCENTIVESTHEYLOVETODREAMTHEMUPANDENACTTHEMSTUDYTHEMANDTINKERWITHTHEMTHETYPICALECONOMISTBELIEVESTHEWORLD"
					+ "HASNOTYETINVENTEDAPROBLEMTHATHECANNOTFIXIFGIVENAFREEHANDTODESIGNTHEPROPERINCENTIVESCHEME";

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 ("Levitate",  "Eindhoven", "Vehement", "Ichthyotoxin",  "Tempted",  "Travertine", "Disparpled",  "Udometer", "Billow",  
						"Navigates", "Enchantment",  "Rhythm", "Fettuccine",  "Restricts",  "EpsomSalts", "Affection",  "Kenneth",   "Obeyed",  
						"Nomothetic", "OnTheMoney", "Methane", "Inveighed", "CowlShaped", "Shiva");

var sWurdzString = "LEVITATEEINDHOVENVEHEMENTICHTHYOTOXINTEMPTEDTRAVERTINEDISPARPLEDUDOMETERBILLOWNAVIGATESENCHANTMENTRHYTHMFETTUCCINERESTRICTS"
					+ "EPSOMSALTSAFFECTIONKENNETHOBEYEDNOMOTHETICONTHEMONEYMETHANEINVEIGHEDCOWLSHAPEDSHIVA";

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("Raise or float without apparent support" ,"Dutch city where Philips made light bulbs in 1891", "Intense, forceful",
						"Poisonous substance in eel blood", "Enticed", "Type of limestone used by the Romans as building material", 
						"\"...now is this realm wholly mischieved, and the noble fellowship of the Round Table shall be ___\" (Malory, Le Morte d'Arthur)",
						"Rain gauge", "Large wave; to swell or bulge", "Plans or guides the way", "Magical spell", 
						"Beat", "Pasta in flat strips wider than linguine", "Places limits on",
						"Hydrated magnesium sulfate (2 wds.)" , "Fondness, tender attachment", "Middle name of economist Galbraith (1908-2006)", 
						"Carried out orders", "Relating to lawmaking or the discovery of universal laws", "Exactly right (3 wds.)", 
						"Simple hydrocarbon", "Protested bitterly","In the form of a hood (hyph.)", "Hindu god, or Jewish ritual of mourning");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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 = '(Steven D.) Levitt & (Stephen J.) Dubner: <a href="http://www.amazon.com/gp/product/0061234001?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0061234001" target="_blank">Freakonomics</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0061234001" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. '
					+'"Economists love incentives. They love to dream them up and enact them, study them and tinker with them. The typical economist believes the world has not yet invented a problem that he cannot fix if given a free hand to design the proper incentive scheme."';
					
						
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 = "21just";

