//                             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 = "Aboriginal Creation myths tell of the legendary totemic beings who had wandered over the continent in the "
					+ "Dreamtime singing out the name of everything that crossed their path birds animals plants rocks waterholes "
					+ "and so singing the world into existence"; // ? 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 = "ABORIGINALCREATIONMYTHSTELLOFTHELEGENDARYTOTEMICBEINGSWHOHADWANDEREDOVERTHECONTINENTINTHEDREAMTIMESINGINGOUT"
					+ "THENAMEOFEVERYTHINGTHATCROSSEDTHEIRPATHBIRDSANIMALSPLANTSROCKSWATERHOLESANDSOSINGINGTHEWORLDINTOEXISTENCE";

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

var aWurdz = new Array ("Bristling",  "Ripcord", "Untinted",  "Contains",  "Endorsement", "Crochet",  "Hayfever", "Adipose",  
						"Traction",  "WaxFlower", "Islamabad",  "Nonviolent",  "Throttles", "Hegemony",  "Eyebright",   "Stenosis",  
						"OnTheMarket",  "Nightshade",  "Glaciated",  "Lightened", "InHighGear", "NewtonsMethod", "Erstwhile", "Stamina");

var sWurdzString = "BRISTLINGRIPCORDUNTINTEDCONTAINSENDORSEMENTCROCHETHAYFEVERADIPOSETRACTIONWAXFLOWERISLAMABADNONVIOLENTTHROTTLESHEGEMONY"
					+ "EYEBRIGHTSTENOSISONTHEMARKETNIGHTSHADEGLACIATEDLIGHTENEDINHIGHGEARNEWTONSMETHODERSTWHILESTAMINA";

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("Standing on end; reacting angrily" ,"Parachutist's need", "Without color" ,"Controls; holds",
						"Signature on the back of a check", "Yarn handicraft", "Pollen allergy (2 wds.)", "Used for the storage of fat, as cells",
						"Pulling or gripping", "Madagascar jasmine (2 wds.)", "Capital of Pakistan", "Gandhi's style" ,"Strangles", "Dominance", 
						"Plant formerly used to treat ocular diseases","The abnormal narrowing of a passage in the body", "For sale (3 wds.)", 
						"Family of plants including tomato and tobacco", "Covered with sheets of ice", "Alleviated", "State of utmost activity (3 wds.)", 
						"Process for approximating the roots of an equation (2 wds.)",
						"Former", "Ability for prolonged effort");

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, 1, 1, 1, 1,   2, 1, 1, 1, 1,   1, 2, 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 (147, 90, 99, 164, 23, 160, 15, 103, 34, 165, 46, 159, 131, 42, 197, 182, 106, 100, 172, 148, 62, 163, 
							35, 137, 47, 56, 125, 14, 38, 6, 80, 135, 97, 210, 67, 115, 11, 151, 119, 155, 140, 190, 127, 75, 65, 16, 
							10, 109, 194, 94, 128, 161, 19, 28, 44, 118, 173, 149, 129, 150, 154, 143, 166, 185, 31, 72, 174, 13, 167, 
							29, 189, 68, 153, 60, 152, 205, 116, 26, 2, 54, 110, 120, 79, 134, 177, 92, 18, 144, 48, 156, 59, 162, 184, 
							111, 69, 206, 76, 32, 91, 51, 83, 122, 87, 142, 27, 108, 208, 9, 117, 158, 139, 12, 104, 24, 96, 133, 201, 
							40, 49, 121, 64, 1, 39, 102, 5, 146, 20, 22, 78, 70, 36, 203, 183, 4, 207, 196, 77, 202, 21, 178, 45, 58, 
							71, 168, 88, 192, 82, 50, 126, 193, 43, 179, 175, 112, 89, 204, 52, 25, 8, 211, 186, 171, 86, 136, 199, 
							198, 84, 191, 30, 107, 209, 187, 74, 63, 141, 7, 57, 200, 188, 73, 101, 212, 61, 132, 85, 114, 170, 130, 
							105, 181, 53, 93, 81, 145, 123, 176, 37, 33, 3, 98, 138, 195, 55, 124, 157, 66, 169, 41, 180, 113, 95, 17, 0);
								
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 = 'Bruce Chatwin:  <a href="http://www.amazon.com/gp/product/0140094296?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0140094296" target="_blank">The Songlines</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0140094296" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />.'
					+'"Aboriginal Creation myths tell of the legendary totemic beings who had wandered over the continent in the Dreamtime, singing out the name of everything that crossed their path -- birds, animals, plants, rocks, waterholes -- and so singing the world into existence."';
					
						
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 = "11song";
