var printing = false; // set true to create pages suitable for printing

var thisPath = window.location.pathname;

// set debug flag if file is local
var DEBUG = thisPath.indexOf("file:") >= 0;

var isMacIE = navigator.userAgent.indexOf('MSIE 5') > 0 && navigator.userAgent.indexOf('Mac_') > 0;
var isGecko = navigator.userAgent.toLowerCase().indexOf('gecko') > 0;

var imagesDir = "../JPEGs/";
//var imagesDir = "http://images7.fotki.com/v110/photos/1/149428/1352023/";
var imagesSuffix = ".jpg";
//var imagesSuffix = ".png";
//var imagesSuffix = "-vi.jpg";

// the name of the html file containing this page.  It's the string beginning after the last 
// slash or backslash (to handle local files in Windows)
var i = thisPath.lastIndexOf('/');
var j = thisPath.lastIndexOf('\\');
if (i < j) i = j;
var thisPage = thisPath.substring(i+1);
var thisURL = window.location.toString();
var k = thisURL.indexOf('#');
var thisLabel = null; // the label in the URL (after the #)
if (k > 0) {
	thisLabel = thisURL.substring(k+1);
}

// following wasn't really necessary to define; thought required to fix a bug
var dotdot = thisURL.substr(0, thisURL.substr(0, thisURL.lastIndexOf('/')).lastIndexOf('/') + 1); // the absolute value of "../"

// the index of this file in pages array or -1
var thisIndex = -1;

var missingImages = new Array();
var missingFullImages = new Array();
var missingIndex = 0;
var missingFullIndex = 0;

// This must correspond to the names of the files in the catalog directory
var pages = new Array(new Array("aa", "ar"),
					  new Array("as", "as"),
					  new Array("az", "be"),
					  new Array("bi", "bl"),
					  new Array("bo", "bz"),
					  new Array("ca", "ce"),
					  new Array("ch", "ci"),
					  new Array("cl", "co"),
					  new Array("cr", "cz"),
					  new Array("da", "do"),
					  new Array("dr", "fz"),
					  new Array("ga", "ga"),
					  new Array("gb", "gr"),
					  new Array("gr", "gr"),
					  new Array("ha", "hz"),
					  new Array("ia", "kn"),
					  new Array("la", "li"),
					  new Array("lo", "me"),
					  new Array("mi", "nz"),
					  new Array("pa", "pl"),
					  new Array("po", "rz"),
					  new Array("sa", "sh"),
					  new Array("sk", "so"),
					  new Array("sp", "th"),
					  new Array("to", "ve"),
					  new Array("vi", "zz"));
var homePage = "../wildflowers.html";

// set thisIndex to the index of this page in pages or -1, based on the file name
if (thisPage.length == 10 && thisPage.charAt(2) == '-' && 
		thisPage.substring(5) == '.html')  {
	first = thisPage.substring(0,2);
	for (i = 0; i < pages.length; i++) {
		if (first == pages[i][0]) {
			if (pages[i][1] != thisPage.substring(3,5)) {
				alert("Page " + thisPage + ' matches "' + first + 
					'" in pages array but not the 2nd part of the name "' + pages[i][1]);
			}
			thisIndex = i;
			break;
		}
	}				
	if (thisIndex == -1) {
		alert("Page " + thisPage + " does not match any entry in pages array");
	}
}

var introLabel;		 // the a name=xxx label used for this entry on the page
var havePic = false; // true between firstPic() and fend()
var first = true;
var titleName;       // the name of this entry with formatting stripped off, for title of flower page

// Start a new flower with the optional specified alternate label.
// If specified, it must begin with uppercase letter.
// Surround primary part of name with <>
// Surround non-name parts with []
function title(name, latin, family, altLabel) {
	titleName = getTitleName(name);
	parsedName = parseName(name, false);
	intro(getLabel(introLabel, altLabel));
	finishTitle(parsedName, latin, decodeFamily(family));
}

// Just return the simplified form of name, removing metacharacters
function getTitleName(name) {
	return name.replace(/[\][\<\>]/g,'');
}

// internal: return introLabel if altLabel is null or doesn't 
// begin with uppercase letter
function getLabel(introLabel, altLabel) {
	if (altLabel == null) return introLabel;
	c = altLabel.substr(0,1);
	if (c >= 'A' && c <= 'Z') return altLabel;
	return introLabel;
}

// internal and for index: return parsed name and set introLabel and altIntroLabel from the name
// The parsed name is the common name specified in title(), with the metacharacters processed and
// replace by appropriate HTML to appear in the catalog entry.
function parseName(name, forIndex) {
	firstBracket = name.indexOf('<'); // suffix is xxx in <xxx>
	if (firstBracket >= 0) 
		suffix = name.substr(firstBracket+1).replace(/>.*$/, '');
	else suffix = '';
	if (firstBracket == 0 && suffix != '') introLabel = suffix; // <xxx> starts the title
	else introLabel = name;   					// <xxx> doesn't start the title
	introLabel = introLabel.replace(/ /g, '_'); // replace ' ' with '_'
	i = introLabel.indexOf(',');
	if (i > 0) introLabel = introLabel.substring(0,i) + '_'; // "aaa,_bbb_[or]_ccc_<xxx>" yields "aaa_"
	j = introLabel.indexOf('[');                             // "aaa_[or]_bbb_<xxx>" yields "aaa_"
	if (j > 0) introLabel = introLabel.substring(0,j);
	if ((i >= 0 && i < firstBracket) || (j >= 0 && j < firstBracket))  // if above yields "aaa" return "aaa xxx"
		introLabel = introLabel + suffix; // <xxx> is after first , or [
	else 
		introLabel = introLabel.replace(/[<>]/g, ''); // <xxx> before , or [
	introLabel = introLabel.replace(/_$/,'');
	// Replace each <xxx> with <font>xxx<\/font>
	parsedName = name.replace(/<([^>]*)>/g, '<font color="#990033">$1<\/font>');
	// Replace each [xxx] with <\/B>xxx<B>
	//parsedName = parsedName.replace(/\[([^]]*)]/g, forIndex ? '$1' : '<\/B>$1<B>');
	parsedName = parsedName.replace(/\[([^\]]*)]/g, forIndex ? '$1' : '<\/B>$1<B>');
	if (!forIndex) parsedName = parsedName.replace(/,/g, '<\/B>,<B>');
	altIntroLabel = getLastName(name);
	// check that first name twixt <> is in proper file, unless thisPage's name is
	// of the form xy-xy.html (i.e., first and last are the same)
	if (thisIndex != -1 && pages[thisIndex][0] != pages[thisIndex][1]) {
		page = getPageForName(name, altIntroLabel);
		if (page != thisPage) alert("Flower in wrong page: " + name);
	}
	altIntroLabel = altIntroLabel.replace(/ /g,'_');
	return parsedName;
}		

// internal: write the intro stuff for a flower with the specified label
function intro(label) {
	writeLabel(label);
	if (altIntroLabel != null && altIntroLabel.length > 0 &&
		altIntroLabel != label)  { 
		// a 2nd label, if defined
		document.write('<A NAME="' + altIntroLabel + '"><\/A>');
		// plural of 2nd label
		document.write('<A NAME="' + pluralize(altIntroLabel) + '"><\/A>');
	}
	document.write('<DIV class="plant">\
			<DIV class="text">\
				<table class="name"> <tr><td class="name"><b>');
}

// internal: write the cross-ref label to an entry.  Invoke fend() if it wasn't.
function writeLabel(label) {
	if (havePic) {
		fend();  // user should have called this after last pic; but if not we will
	}
	document.write('\n<A NAME="' + label + '"><\/A>');
	document.write('\n<A NAME="' + pluralize(label) + '"><\/A>');
}

// internal: form plural of the name
function pluralize(name) {
	if (name == null || name.length < 2) return '';
	if (name.substr(name.length-1,1) == 'y') return name.substr(0,name.length-1) + 'ies';
	if (name.substr(name.length-1,1) == 's') return name + 'es';
	return name + 's';
}

// internal: finish writing the intro stuff for a flower
function finishTitle(parsedName, latin, family) {
	if (latin == "") latin = "&nbsp;";
	document.write(parsedName +
				'<\/b><\/td><td class="name"><i>' + latin + '<\/i><\/td><td class="name">' +
				   family + '<\/td><\/tr><\/table><P>');
}

// Must be called at end of last pic
function fend() {
	document.write('<\/div><div class="spacer">&nbsp;<\/div>');
	havePic = false;
}

// Add a picture with optional caption.  The width parameter is obsolete.
// The idea is to position a caption div below an image such that the caption width is the same as that
// of the image.  This requires an onload handler to set that width after the image is loaded.
function pic(name, caption, width) {
	if (!havePic) firstPic(); // first pic this entry
	document.write('\n');
	image = null;
	captionID = null;
	if (caption == null) {
		document.write('<div class="float" style="padding-bottom: 5;" >');
	} else {
		// If there's a caption, create an image object for the image so we can attach attributes
		// and tags to it
		image = new Image();
		image.captionID = name + 'Caption';  // we'll be assigning this ID to the caption div below
		// Write the div containing the image using a default width of 200
		document.write('<div id="' + name + '" class="floatCaptionW" style="width: ' +  200  + 'px;">');
	} 
	
	// Don't actually set image.src because in IE, if the image is cached it will be considered loaded
	// and the onload handler down below won't run.
	if (printing) imageSrc = imagePath(name);
	else imageSrc = "../Small_JPEGs/" + name + imagesSuffix;

	document.write('<a href="' + openImageInWindowLink(name,titleName) + '" ' +
					'onclick="return zoomClick(this,event);" ' +
				   'onmouseover="zoomPreload(this); return true;" '); 
	if (caption != null) document.write(' title="' + titleName + ': ' + normalizeCaption(caption) + '"');
	else document.write(' title="' + titleName + '"');
	document.write('>' +
				   '<img name=' + name + ' src="' + imageSrc + '" alt="' + name + '" ' +
				   'class="flower" onerror="useFullImage(\''+name+'\')"');
	if (printing) document.write(' height=300 vspace=5');
	else document.write('><\/a> ');

	if (caption != null) {
		document.write('<div id="' + image.captionID + 
		    '" style="top: ' + image.height + 5 + 'px; width: ' + image.width + 'px">' + caption + '<\/div>');
		    
		// Change width of the DIV containing the image and caption to correspond to the actual image when it loads
		image.onload = function() {
			// set width of enclosing div containing both image and caption.  This overrides the default 200 width set above
			element = document.getElementById(name);
			if (element == null) {
				debugAlert("Can't find image element ID=" + name);
				return;
			}
			element.style.width = this.width + "px";
			if (this.captionID == null) {
				debugAlert("CaptionID missing from image element ID=" + name);
				return;
			}
			// position top of caption immediately below the image, which depends on image height
			// and set caption width same as that of image
			element = document.getElementById(this.captionID);
			if (element == null) {
				debugAlert("Can't find caption element with ID=" + this.captionID + " for image ID=" + name);
				return;
			}
			element.style.top = this.height + "px"; 
			element.style.width = this.width + "px";
		};
		image.src = imageSrc; // Attach the image object created above to the one being referred to in the img tag
	}
	
    // document.write('<br><\/p><\/div>');
	document.write('<\/div>');
	
}

// synonym for pic; used as a marker for the key picture to
// use in identifier.  name has optional "/" in front of "last name"
function picKey(name, caption, width) {
	pic(name, caption, width);
}

// convert a pic() caption into a normal text string that can go into a title+"foo" attribute
// replaces Javascript refs with normal text and escapes quotes
function normalizeCaption(str) {
    // Remove the Javascript from <script>ref("a flower")<\/script> and leave just "a flower"
	s = str.replace(/<script> *ref *\((["'])(.*)(\1) *\) *<\/script>/gi,"$2");
	s = s.replace(/ \//gi,' ');           // remove space-slash in front of words, which was originally in refs
	return s.replace(/"/g,'&quot;');     // make sure double quotes come out
}

// like picKey but a marker for key picture only; used only in identifier; ignore here
function key(name) { }

// return a javascript pseudo-URL that calls a function to open an image in a imageWindow
function openImageInWindowLink(name,flowerName) {
	return imagePath(name);
    //zzz return "javascript:openImageFile('" + imagePath(name) + "'" + ", '" + flowerName + "')";		
}

// return the path of an image, unquoted
function imagePath(name) {
	return imagesDir + name.substring(0,1).toLowerCase() + '/' + name + imagesSuffix;
}

var imageWindow; // window for images

// open image in imageWindow, creating it if it doesn't exist, using file at ../others/flower.html
function openImageFile(name, flowerName) {
	url = "../others/flower.html?" + name + "?" + escape(flowerName);
	if (imageWindow == null || imageWindow.closed) {
		imageWindow = window.open(url, "Flower", "resizable,height=750,width=750");
	} else imageWindow.location = url;
	imageWindow.focus();
}


// internal: use full-size image if thumbnail doesn't load
function useFullImage(name) {
	missingImages[missingIndex++] = name; // remember for error message
	url = document[name].src;
	alert("Bad URL '" + url + "'");
	url = url.replace(/^.*Small_JPEGs./, imagesDir);
	url = url.replace(/.jpg/, imagesSuffix);
	document[name].src = url;
	curImage = name;
	document[name].onerror = fullImageError;
	document[name].width=200;
}

function fullImageError() {
	if (curImage != null)
		missingFullImages[missingFullIndex++] = curImage;
	curImage = null;
}


// internal: called on first pic of entry, to end last paragraph and <\/DIV class=text> 
function firstPic() {
	subject = "Comment on " + titleName;
	document.write('\n &nbsp;<a href="mailto:morrie@thegassers.com?subject=' + subject +
		'"><img src="../GIFs/email.gif" border=0 alt="email" title="' + subject + '" ' + 
		'><\/a><\/P><\/DIV>&nbsp;');
	havePic = true;
}
	
var prevPage = null;
var nextPage = null;

function openPage(title) {
	if (thisIndex == -1 || thisIndex == 0) prevPage = homePage;
	if (thisIndex == -1 || thisIndex >= pages.length - 1) nextPage = homePage;
	if (prevPage == null) prevPage = makeFileName(thisIndex - 1);
	if (nextPage == null) nextPage = makeFileName(thisIndex + 1);
	document.write('\n<LINK rel=stylesheet type="text/css" href="../sheets/wildflower_catalog');
	if (printing) document.write("_printing");
	document.write('.css">\n' +
		'<script src="../scripts/families.js"><\/script>\n' + 
		'<title>Wildflowers of Hopkinton (' + title + ')<\/title>\n' + 
		'<\/HEAD>\n<BODY BGCOLOR="#dfe7c6" onload="setupZoom()" onclick="closeZoomIfOpen()" >\n');
	document.write('<script src="../scripts/evaluator.js"><\/script>\n');
	document.write('<script src="../scripts/FancyZoom.js" language="JavaScript" type="text/javascript"><\/script>\n');
    document.write('<script src="../scripts/FancyZoomHTML.js" language="JavaScript" type="text/javascript"><\/script>\n');
    document.write('<style>\n' + '.dragme{position:relative;}\n' + 
        '<\/style>\n');

	document.write('<META http-equiv="Content-Script-Type" content="text/javascript">');
	if (isGecko) {
	}
	if (!printing) {
		// write the navigation pane
		document.write(
			'<div style="display: block; border: 1px black solid; margin-left: 12px; margin-top: 12px;' +
		            	'font: normal bold smaller sans-serif; line-height: 1.5; padding: 3px; zindex: 700; ' +
		            	'position: absolute; background: #bae7c6;" id="navigation">' +
			'<A HREF="../wildflowers.html">Home</A><br>' +
			'<A HREF="../wildflowers.html#Lookup">Index</A><br>' +
			'<a href="../others/identifier.html">Identification Guide</a><br>' +
			'<A HREF="../others/references.html">References</A><br>' +
			'<\/div>\n');
		// write the header and forward/back buttons
		document.write(
			'<div style="display: block; float: right; margin-top: 12px; margin-right=12px; width: 80px; height: 80px;"> &nbsp; <\/div>\n' +
			'<H2><CENTER>Wildflowers of South Mill St., Hopkinton, Mass.<\/CENTER><\/H2> \n' +
			'<H3><CENTER><A HREF="' + prevPage + '">' +
			'<IMG SRC="../GIFs/sm_left_arrow.gif" BORDER="0" HSPACE="10" ALT="" style="position: relative; bottom: -6px"><\/A>'+
			  title + '<A HREF="' + nextPage +
			  '"><IMG SRC="../GIFs/sm_right_arrow.gif" BORDER="0"  style="position: relative; bottom: -6px" HSPACE="10" ALT="next"><\/A><\/CENTER><\/H3>\n' +
			  '<BR>&nbsp;'
		);
	}
}

// This is called on a click anywhere in the page
function closeZoomIfOpen() {
	if (zoomOpen) {
		zoomOut();
	}
}

/** This is the drag stuff **/

var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;
var wasdragging = false; // prevents next onclick from unzooming
var oldCursor = null;    // cursor the object had before dragging started

function movemouse(e)
{
  if (isdrag)
  {
  	newleft = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    newtop = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    dobj.style.left = newleft + 'px';
    dobj.style.top  = newtop + 'px';
    shadowBox = document.getElementById('ShadowBox');
    if (shadowBox) {
    	shadowBox.style.left = newleft - 13 + 'px';
    	shadowBox.style.top =  newtop - 8 + 'px';
    }
    wasdragging = true;
    return false;
  }
}

function selectmouse(e) 
{
  var fobj       = nn6 ? e.target : event.srcElement;

  while (fobj.tagName != 'HTML' && fobj.tagName != 'BODY' && fobj.className.indexOf("dragme") < 0)
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }

  if (fobj.className.indexOf("dragme") >= 0)
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove = movemouse;
   	oldCursor = dobj.style.cursor;  // show a move cursor on mouse down; for some reason this doesn't
   	dobj.style.cursor = 'move';     // appear until mouse is moved
    return false;
  }
}

document.onmousedown = selectmouse;

document.onmouseup=new Function("isdrag=false; if (dobj) dobj.style.cursor = oldCursor;");

/** end of the drag stuff **/

// Fix Gecko bug on page load, where it adds too much space between entries.  The fix requires resizing and repositioning
// the page to the label, but we only want to do it once so it doesn't happen on every BACK button, 
// so we save a cookie for this page that says we already did it.
function fixGeckoLoad() {
	url = window.location.href;
	if (thisLabel == null) {
		thisCookie = null;
	} else {
		thisCookie = thisPage + ".lastLink=" + thisLabel; // cookie format is aa-be.html.lastLink=Azalea
	}
	// Try to do the layout only the 1st time the page is visited.  This is hard to do reliably.
	if (thisCookie == null || document.cookie.indexOf(thisCookie) < 0) {
		// The two resizes force the re-layout.  
		resizeBy(0,-1);
		resizeBy(0,1);
		// Since we resized, we have to re-position.
		if (thisCookie != null) {
			window.location.href = url;
		}
		if (thisCookie == null) document.cookie = thisPage + ".lastLink=foo; expires=Thu, 01-Jan-70 00:00:01 GMT"; //delete
		else document.cookie = thisCookie; 
	}
}

function closePage() {
	if (havePic) fend();
	imgStuff = 'style="position: relative; bottom: -30px;"';
	if (!printing) {
		document.write('\
		<CENTER>\
		<TABLE cellspacing=5>\
			<TR>\
				<TD>\
					<A HREF="' +prevPage+ '"><IMG SRC="../GIFs/sm_left_arrow.gif" BORDER="0" ALT="Previous" ' + imgStuff +
					 '><\/A> \
				<\/TD>\
				<TD>\
				<\/TD>\
				<TD>\
					<A HREF="' +homePage + '#' + thisIndex + '"><IMG SRC="../GIFs/home.gif" BORDER="0" ALT="Home"><\/A> \
				<\/TD>\
				<TD>\
				<\/TD>\
				<TD>\
					<A HREF="' +nextPage+ '"><IMG SRC="../GIFs/sm_right_arrow.gif" BORDER="0" ALT="Next" ' + imgStuff + 
					'><\/A> \
				<\/TD>\
			<\/TR>\
			<TR>\
				<TD ALIGN="center">\
				<\/TD>\
				<TD>\
				<\/TD>\
				<TD ALIGN="center">\
					<FONT SIZE="-2"><A HREF="'+homePage+'">Home<\/A><\/FONT> \
				<\/TD>\
				<TD>\
				<\/TD>\
				<TD ALIGN="center">\
				<\/TD>\
			<\/TR>\
		<\/TABLE>\
		<\/CENTER>\
		<P>\
		<A HREF="http://www.thegassers.com">Morrie Gasser&#146;s home page<\/A> \
		<\/P>\
		<P ALIGN="center">');
		copyright();
		document.write('<\/P>\
		<script type="text/javascript">\
			printEvaluator();\
		<\/script>\
		<\/BODY>\
		<\/HTML>');
	}
	if (missingIndex > 0) {
		s = "";
		for (i = 0; i < missingIndex; i++) {
			s += '\n     ' + missingImages[i];
		}
		first = true;
		for (i = 0; i < missingFullIndex; i++) {
			if (first) s += '\nFull Images Missing: ';
			first = false;
			s += '\n     ' + missingFullImages[i];
		}
		alert("Thumbnails missing: " + s);
	}
	fixGeckoLoad();

	// Because objects on the page "move around" after the page is loaded, the position of any 
	// anchor that was specified in the URL may have changed, so we need to scroll to it again. 
	str = String(document.location);
	anchorIndex = str.indexOf('#');
	if (anchorIndex > 0) {
		anchor = str.slice(anchorIndex+1);
		hash = window.location.hash;
		if (hash != '') window.location.hash = hash; //anchorElement.scrollIntoView(true);
	}
	navPane = document.getElementById('navigation');
	//alert(document.body.clientWidth + ' ' + document.body.scrollLeft + ' ' + navPane.offsetWidth + '/' + //document.body.scrollTop);
	navPane.style.left = 20;//document.body.clientWidth + document.body.scrollLeft - navPane.offsetWidth - 20 + 'px';
	navPane.style.top = 20;//document.body.scrollTop + 20 + 'px';
}

// Insert reference to "name", optionally containing "text" instead of "name".
// "name" is the name of the label assigned to the flower, based on its name or explicit <A NAME=xx> tag.
// If indexName is specified, this is the one that determines the page on which it is found; otherwise we assume it's name.
// The name must be of the form "Smooth /Clover" where the / precedes the indexed word.  If
// no / appears, we use the last or only word.  Underscore optional.
function ref(name, indexName, text) {
	if (indexName == null) indexName = name;
	pg = getPageForName(indexName);
	if (pg == null) alert(name + " in cross reference does not fit into any page");
	else {
		name = name.replace(/\//, ''); // remove slash
		name = name.replace(/ /g, '_'); // replace space with _
		if (thisPath.indexOf("catalog" < 0)) pg = "../catalog/" + pg;
		document.write('<a href="' + pg + '#' + name + '"><b>');
		if (text == null) text = name.replace(/_/g, ' ');
		document.write(text + '<\/b><\/a>');
	}
}
// Internal: get name of html file containing the name formatted as for ref() or title()
// If altName set, use it for the name.
function getPageForName(name, altName) {
	if (name == "ornamentals") return "ornamentals.html";
	name = altName == null ? getLastName(name) : altName;
	// if name begins with "St." change it to "Sa"
	if (name.substring(0,3) == "St.") name = "sa";
	else name = name.substring(0,2).toLowerCase(); // use just 1st 2 chars
	for (i = 0; i < pages.length; i++) {
		if (name < pages[i][0]) return null;
		if (name <= pages[i][1]) return makeFileName(i);
	}
	return null;
}

// Internal: Return the part of the name that is indexed, formatted as for ref() or title()
// If name is enclosed in <>, return just that part; else return everything after the
// first '/' or last ' ' or '_'.
function getLastName(name) {
	i = name.indexOf('/');            // name begins after first / or <
	if (i < 0) i = name.indexOf('<'); 
	if (i >= 0) {
		name = name.substring(i+1);
		j = name.indexOf('>');
		if (j > 0) name = name.substring(0,j);		
	} else {
		i = name.lastIndexOf(' ');
		if (i >= 0) name = name.substring(i+1);
		else {
			i = name.lastIndexOf('_');
			if (i >= 0) name = name.substring(i+1);
		}
	}
	return name;
}	

// Internal: Get the file name corresponding to the index'th page
function makeFileName(index) {
    return pages[index][0] + '-' + pages[index][1] + '.html';
}

// Make an entry called name with cross ref to refName. 
// Syntax of name is as in title()
// Syntax of refName as in ref()
function see(name, refName) {
	parsedName = parseName(name, false);
	writeLabel(introLabel);
	document.write('<DIV class="plant"><DIV class="text" style="padding-left: 15px"><TABLE class="name"><TR><TD class="name"><b>' + parsedName + '<\/b><\/TD><TD class="name">See ');
	ref(refName);
	document.write('.<\/TD><\/TR><\/TABLE><\/DIV><div class="spacer"><\/DIV>');
}	

function outback() {
	document.write("<A href='../others/environment.html#Outback'>Outback</A>");
}

function returnToHome(doc) {
	if (doc == null) doc = document;
	return doc.write('<A HREF="../wildflowers.html">Return to home.<\/A>');
}

function returnToIndex(doc) {
	if (doc == null) doc = document;
	return doc.write('<A HREF="../wildflowers.html#Lookup">Return to index.<\/A>');
}

function copyright(doc) {
	if (doc == null) doc = document;
	if (document.URL.indexOf("wildflowers.html") < 0) pg = "../"; // hack handles copyright notice on main page
	else pg = ""; 
	return 	doc.write('<FONT SIZE="-1">Entire contents <A HREF="' + pg + 'others/copyright.html">&copy;2010<\/A> by <A HREF="http://www.thegassers.com">Morrie Gasser<\/A> except where noted.<\/FONT>');
}

function newcomb() {
	refRef("Newcomb", "newcomb");
}

function audubon() {
	refRef("Audobon", "audubon");
}

function refRef(string, key) {
	document.write('<A HREF="../others/references.html#' + key + '">' + string + '<\/A>');
}

// Future function to display edibility information
function eat(str) {
}

function debugAlert(msg) {
	if (DEBUG) alert(msg);
}
