// Parameters.

// Cookie name
// Change HypertextName to a name representing your hypertext.
// This name cannot include spaces, commas, or semicolons.

histCookieName = "Clues"

// Total number of nodes in the hypertext
// Change 0 to the number of nodes in your hypertext.

var deadLinkColor = document.fgColor

allRooms = ["rm-cop.htm", "rm-pen.htm", "rm-package.htm", "rm-shapes.htm", "rm-suspicious.htm", "rm-woman"]

allTrees = ["tr-cop.htm", "tr-pen.htm", "tr-package.htm", "tr-shapes.htm", "tr-tracks.htm"]

allStreets = ["st-cop.htm", "st-crime.htm", "st-man.htm", "rm-shapes.htm", "st-suspicious.htm", "st-woman"]

clue1 = ["1-tr.htm"]

clue2 = ["2-rm.htm", "2-st.htm"]

clue3 = ["3-rm.htm", "3-st.htm"]

clue4 = ["4-rm.htm", "4-tr.htm"]

clue5 = ["5-st.htm"]

clue6 = ["6-rm.htm", "6-tr.htm"]

clue7 = ["7-rm.htm", "7-st.htm", "7-tr.htm"]

clue8 = ["8-st.htm"]

clue9 = ["9-st.htm"]

clue10 = ["10-rm.htm", "10-st.htm", "10-tr.htm"]

allClues = ["1-tr.htm", "2-rm.htm", "2-st.htm", "3-rm.htm", "3-st.htm", "4-rm.htm", "4-tr.htm", "5-st.htm",  "6-rm.htm", "6-tr.htm", "7-rm.htm", "7-st.htm", "7-tr.htm", "8-st.htm", "9-st.htm", "10-rm.htm", "10-st.htm", "10-tr.htm"]

errorMessages = {
				package : "Access Error!\r\n\r\nYou reached inside yourself and your mind, that steel trap, snapped shut on your fingers. Opportunity makes good its escape. You felt sorry for it, didn't you? Deliberately let it slip away. You thought, What deserves its freedom more than Chance? Yeah, sure you did.\r\n\r\nMaybe next time you'll listen when you're told not to push the envelope.",
				pen : "Scoring Failure!\r\n\r\nThe pen is the word's weapon of choice. You missed your chance this time, but you'll go on playing. The game holds you in its comfortingly two-dimensional arms, a lover who has you cheating on reality. It grasps you by your need for number, that compensatory yardstick against which the world can almost be made to measure up.\r\n\r\nBetter luck next time.",
				shapes : "Failure of Imagination!\r\n\r\nYou want to put a good face on it, personify your aspirations, so you grasp at characters. But this is poetry, goddammit. You ignore the faint out-of-the-way signifiers at your peril. You missed the pure symbols, the unmitigated glyphs, the naked icons unafraid to mean anything but themselves. Why must things be spelled out for you only in letters you understand?",
				suspicious : "The Device C:/YOU Is Not Accessible!\r\n\r\nYou could have tripped the shutter, been captured on the sensitive silver halide of simile, left your image in the logochemistry. But no, you just had to go peripheral.\r\n\r\nNext time be more careful.",
				woman : "Value System Reboot Required!\r\n\r\nYou chose textual death over sex. How do you expect the writing to propagate under such circumstances? You think perhaps that words don't have their own desires, their procreative ambitions?\r\n\r\nBetter bone up on the words and the bees if you want the story line to go on."
				}

// These functions determine the destinations for automatically generated
// links within each area of the work; nodes are excluded if
// their corresponding clue node has already been visited

// **********
// ROOMS
// **********

function getRooms() {
	availableRooms = new Array()
	availableRooms = conditionalFilter("rm-cop.htm", !someVisited(clue10) && copCondition(), "rm-pen.htm", !someVisited(clue6) && penCondition(), "rm-package.htm", !someVisited(clue4), "rm-shapes.htm", !someVisited(clue7), "rm-suspicious.htm", !someVisited(clue2), "rm-woman.htm", !someVisited(clue3), "rm-dark.htm", notVisited("rm-dark.htm"))
	return availableRooms
}

function roomsDestination() {
	// Determine proper exit node when all nodes of Rooms are read
	var elseDestination = checkEndingStatus()
	if (elseDestination == null)
	{
		elseDestination = doorToStreet()
	}
	// Hallway2.htm is destination if a hallway hasn't yet been visited
	if (!someVisited("hallway.htm", "hallway2.htm"))
	{
		return "hallway2.htm"
	} else {
		return filteredRandom(notVisited, elseDestination, getRooms())
	}
}

function doorToStreet() {
	// If we are in city, return door-out, which leads to street;
	// if we haven't arrived at city, return Pictures2.htm
	// (version of Pictures.htm without text)
	if (visited("citystreet.htm"))
	{
		return "door-out.htm"
	} else {
		return "pictures2.htm"
	}
}

// Get destination upon first entering Rooms from the street
function doorFromStreet()
{
	// Hallway2.htm is destination if a hallway hasn't yet been visited
	if (!someVisited("hallway.htm", "hallway2.htm"))
	{
		return "hallway2.htm"
	} else {
		return "rm-empty.htm"
	}
}

// **********
// TREES
// **********

function getTrees() {
	availableTrees = new Array()
	availableTrees = conditionalFilter("tr-cop.htm", !someVisited(clue10) && copCondition(), "tr-pen.htm", !someVisited(clue6) && penCondition(), "tr-package.htm", !someVisited(clue4), "tr-shapes.htm", !someVisited(clue7), "tr-tracks.htm", notVisited("tr-tracks.htm"))
	return availableTrees
}

function treesDestination() {
	// Determine proper exit node when all Trees nodes are read
	var elseDestination = checkEndingStatus()	
	if (elseDestination == null)
	{
		// Determine whether we're in forest or park
		if (visited("citystreet.htm"))
		{
			elseDestination = "park-exit.htm"
		} else {
			elseDestination = "road-trees.htm"
		}
	}
	// Trees.htm is destination if it hasn't yet been visited
	if (notVisited("trees.htm"))
	{
		return "trees.htm"
	} else {
		return filteredRandom(notVisited, elseDestination, getTrees())
	}
}

// **********
// STREETS
// **********

function getStreets() {
	availableStreets = new Array()
	availableStreets = conditionalFilter("st-cop.htm", !someVisited(clue10) && copCondition(), "st-crime.htm", !someVisited(clue9), "st-man.htm", !someVisited(clue5), "st-shapes.htm", !someVisited(clue7), "st-suspicious.htm", !someVisited(clue2), "st-woman.htm", !someVisited(clue3))
	return availableStreets
}

function streetsDestination() {
	// Determine proper exit node when all Streets nodes are read
	var elseDestination = checkEndingStatus()	
	if (elseDestination == null)
	{
		// Select a node from either Trees or Rooms, giving
		// preference to one set if it has nodes remaining
		// and the other set doesn't
		elseDestination = conditionalRandom(null, "park.htm", !allVisited(getTrees()) || allVisited(getRooms()), "st-door.htm", !allVisited(getRooms()) || allVisited(getTrees()))
	}
	return filteredRandom(notVisited, elseDestination, getStreets())
}

// Check to see if ending node needs to be provided
function checkEndingStatus() {
	endingNode = null
	// If all clues read, go to end.htm
	if (nbVisited(allClues) >= 10)
	{
		endingNode = "end.htm"
	} else {
		// If no more nodes left and not all clues read,
		// to to sorry.htm
		if (allVisited(getRooms()) && allVisited(getStreets()) && allVisited(getTrees()) && nbVisited(allClues) < 10)
		{
			endingNode = "sorry.htm"
		}
	}
	return endingNode
}

// Don't allow visits to pen nodes until 5 or more
// clues visited
function penCondition()
{
	if (nbVisited(allClues) >= 5)
	{
		return true
	}
}

// Don't allow visit to cop nodes until until 5 or more
// clues visited
function copCondition()
{
	if (nbVisited(allClues) >= 5)
	{
		return true
	}

}

// Don't allow clue to be visited unless
// current node has not been visited before or unless
// it has been visited from another clue
function accessClueCondition()
{
	if ((nbVisits(hist(0)) < 2) || includedIn(hist(-1), allClues))
	{
		return true
	}
}



// NEW FUNCTIONS TO ADD TO LIBRARY

// Loads the file given as a parameter; used by mapArea()
function chooseThis(destinationAlias)
{
	window.location = destinationObject[destinationAlias];
}

// Creates an area tag for an image map
function mapArea(destination, areaDefinition, cond)
{
	if (typeof(destinationObject) == "undefined")
	{
		destinationObject = new Object();
	}
	destinationObject[statusMessage] = destination;

	var text = "<AREA " + areaDefinition + " href=\"javascript: chooseThis('" + statusMessage + "')"
	text += '" ALT="' + altText + '" TITLE="' + altText + "\" onMouseOver='window.status=\"" + statusMessage + "\"; return true' onMouseOut='window.status=\"\"; return true' />";

	var arg_len = mapArea.arguments.length;

	if (arg_len == 2)
	{
		display(text);
	}
	if (arg_len == 3)
	{
	  if (cond)
	  {
		display(text);
	  }
	}

	statusMessage = "";

}

function includedIn(node, nodeArray)
{
	arrayText = nodeArray.join(", ")
	return h_member(node, arrayText)
}

function currentAudioFile ()
// Returns the file name of the file in audioFrame
{
baseDirectory = "/"
var url = parent.audioFrame.location.href;
var i = url.lastIndexOf (baseDirectory);
return (url.substring (i + baseDirectory.length, url.length));
}

function loadAudio(audioFile) {
	// If current page wasn't visited two pages ago or if a different audio file is playing,
	// load page containing audio file; load audio if current page is start.htm (but last page wasn't door.htm)
	if (((hist(-2) != hist(0)) && (currentAudioFile() != audioFile) && (currentAudioFile() != "music-intro.htm")) || (hist(0) == "start.htm" && hist(-1) != "door.htm"))
	{
		parent.audioFrame.location = audioFile
	}
}
