//                             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 = "Clarity is not the prize in writing nor is it the principal mark of a good style There are occasions when obscurity "
					+ "serves a literary yearning if not a literary purpose and there are writers whose mien is more overcast than clear "
					+ "But since writing is communication clarity can only be a virtue       "; // 7 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 = "CLARITYISNOTTHEPRIZEINWRITINGNORISITTHEPRINCIPALMARKOFAGOODSTYLETHEREAREOCCASIONSWHENOBSCURITYSERVESALITERARYYEARNING"
					+ "IFNOTALITERARYPURPOSEANDTHEREAREWRITERSWHOSEMIENISMOREOVERCASTTHANCLEARBUTSINCEWRITINGISCOMMUNICATIONCLARITYCANONLYBEAVIRTUE";

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 (letters and numbers only).
var aWurdz = new Array ("Spirogyra", "Tarrytown", "Respect", "Urgently", "Nicotine", "Kashmir", "Eviction", "Bowdoin", "Warrior", "Hairspray", 
					"Irritants", "Tutelary", "Erratic", "Taiwan", "Honduras", "Epsilon", "Evasion", "Lichens", "Esoterica", "Mischief", 
					"Entrelac", "November", "Trapeze", "Swimsuit", "OceanCity", "Friction", "Sublime", "Thinner", "YearsAgo", "Lethargy", "Election");

var sWurdzString = "SPIROGYRATARRYTOWNRESPECTURGENTLYNICOTINEKASHMIREVICTIONBOWDOINWARRIORHAIRSPRAYIRRITANTSTUTELARYERRATICTAIWANHONDURASEPSILON"
					+ "EVASIONLICHENSESOTERICAMISCHIEFENTRELACNOVEMBERTRAPEZESWIMSUITOCEANCITYFRICTIONSUBLIMETHINNERYEARSAGOLETHARGYELECTION";

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("Green freshwater alga, source of a jazz group name", "\"In ___ , there did dwell A lovely girl I knew her well...\"", 
					"Aretha Franklin signature song", "Pressingly, with high priority", "Tobacco alkaloid", "Area of conflict between India and Pakistan", 
					"Removal of a tenant by the landlord", "____ College alumni include Franklin Pierce, Hawthorne and Longfellow", 
					"\"The 13th ___\", 1999 film based on Michael Crichton's \"Eaters of the Dead\"", "1988 PG-rated film by John Waters", 
					"Substances causing minor discomfort", "Serving as a protector, guardian, or patron", "Irregular, unpredictable", 
					"Formerly Formosa", "Its capital city is Tegucigalpa", "Fifth letter of the Greek alphabet", "Avoidance", 
					"Composite plants containing fungi and algae or cyanobacteria", "Rare or highly specialized items or knowledge ", 
					"Shenanigans, troublemaking", "Knitting technique used to create a textured diamond pattern", 
					"Month, starting on the same day of the week as March", "Horizontal bar hanging by two ropes", 
					"One-piece or trunks, e.g.", "Maryland sea resort town, eastern terminus of U.S. 50 (2 wds.)", 
					"Resistance, drag; animosity, conflict", "Inspiring awe; change from solid to vapor", "Stephen King novel about a Gypsy curse", 
					"\"It was twenty ____ today Sgt. Pepper taught the band to play...\" (2 wds.)", "Sluggishness, lack of energy", "Method of choice");
					
					
var iCluNum = aClues.length;	// Number of Clues (and therefore, Wurdz).

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

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

var iPuzzleLeftCoord = iCluesLeftCoord + 490;	// 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) Strunk (Jr. and) E. B. White: <a href="http://www.amazon.com/gp/product/0205313426?ie=UTF8&tag=puzzlebook-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0205313426" target="_blank">The Elements of Style</a><img src="http://www.assoc-amazon.com/e/ir?t=puzzlebook-20&l=as2&o=1&a=0205313426" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. '
					+'"Clarity is not the prize in writing, nor is it the principal mark of a good style. There are occasions when obscurity serves a literary yearning, if not a literary purpose, and there are writers whose mien is more overcast than clear. But since writing is communication, clarity can only be a virtue."';
					
						
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 = "37word";
