window.name="1up";
os=navigator.platform;
browser=navigator.appName;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// start() - GENERAL FUNCTION - called by the HTML document once loaded.
function start() {
	loadData();
	drawTree();
	checkPrefs();
}

function checkPrefs(){
	targetFrame = top.right.window.document;
	if (os.substr(0,3)=="Mac"){
		// select the Mac look and feel
		targetFrame.prefs.elements[0].click();
	} else {
		// select the Windoze look and feel
		targetFrame.prefs.elements[1].click();
	}
	if (browser.substr(0,3)=="Net"){
		// select the Communicator look and feel
		targetFrame.prefs.elements[2].click();
	} else {
		// select the IE look and feel
		targetFrame.prefs.elements[3].click();
	}
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// drawTree() - GENERAL FUNCTION - starts the recursive tree drawing process by first writing
//					     the root node, and then all subordinate branches.

function drawTree() {
	outputFrame = top.body.window.document;
//	outputFrame = "body";
	outputFrame.open("text/html");
	outputFrame.write("<HTML>\n<BODY BGCOLOR='" + backgroundColor + "' BACKGROUND='" + backgroundImage + "' LINK='" + linkColor + "' ALINK='" + aLinkColor + "' VLINK='" + vLinkColor + "' onLoad=\"if (top==self) top.location.href='/info_center/finder_explorer.html';\">\n");
	outputFrame.write("<FONT FACE='" + omenTreeFont + "' SIZE=" + omenTreeFontSize + " COLOR='" + textColor + "'>\n");
	outputFrame.write(prefixHTML + "\n<NOBR>\n");
	if (treeData[1].target == "") {var targetFrame = defaultTargetFrame} else {var targetFrame = treeData[1].target}
	if (treeData[1].icon == "") {var imageString = defaultImageURL + 'img-globe-' + structureStyle + '.gif'} else {imageString = defaultImageURL + treeData[1].icon}
	outputFrame.write("<A HREF='" + treeData[1].url + "' TARGET='" + targetFrame + "'; return true\"><IMG SRC='" + imageString + "' WIDTH=16 HEIGHT=16 ALIGN=TEXTTOP BORDER=0 ALT='Click to visit this page'></A>&nbsp;<B>" + treeData[1].name + "</B><BR>\n");
	drawBranch("root","");
	outputFrame.write("</NOBR>\n" + suffixHTML + "\n");
	outputFrame.write("</FONT>\n</BODY>\n</HTML>");
	outputFrame.close();
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// drawBranch() - GENERAL FUNCTION - used by the drawTree() function to recursively draw all
//						 visable nodes in the tree structure.

function drawBranch(startNode,structureString) {
	var children = extractChildrenOf(startNode);
	var currentIndex = 1;
	while (currentIndex <= children.length) {
		outputFrame.write(structureString);
		if (children[currentIndex].type == 'link') {
			if (children[currentIndex].icon == "") {
				var imageString = defaultImageURL + defaultLinkIcon;
			}
			else {var imageString = defaultImageURL + children[currentIndex].icon}
			if (children[currentIndex].target == "") {
				var targetFrame = defaultTargetFrame;
			}
			else {var targetFrame = children[currentIndex].target}
			if (currentIndex != children.length) {
				outputFrame.write("<IMG SRC='" + defaultImageURL + "img-branch-cont-" + structureStyle + ".gif' WIDTH=19 HEIGHT=16 ALIGN=TEXTTOP>")
			}
			else {
				outputFrame.write("<IMG SRC='" + defaultImageURL + "img-branch-end-" + structureStyle + ".gif' WIDTH=19 HEIGHT=16 ALIGN=TEXTTOP>")
			}
			outputFrame.write("<A HREF='" + children[currentIndex].url + "' TARGET='" + targetFrame + "'; return true\"><IMG SRC='" + imageString + "' WIDTH=16 HEIGHT=16 ALIGN=TEXTTOP BORDER=0 ALT='Click to visit this page'></A>&nbsp;" + children[currentIndex].name + "<BR>\n")	
		}
		else {
			var newStructure = structureString;
			if (children[currentIndex].iconClosed == "") {var iconClosed = "img-folder-closed-" + structureStyle + ".gif"} else {var iconClosed = children[currentIndex].iconClosed}
			if (children[currentIndex].iconOpen == "") {var iconOpen = "img-folder-open-" + structureStyle + ".gif"} else {var iconOpen = children[currentIndex].iconOpen}
			if (currentIndex != children.length) {
				if (children[currentIndex].open == 0) {
					outputFrame.write("<A HREF=\"javascript:top.toggleFolder('" + children[currentIndex].id + "',1)\" onMouseOver=\"window.status='Click to open this folder'; return true\"><IMG SRC='" + defaultImageURL + "img-plus-cont-" + structureStyle + ".gif' WIDTH=19 HEIGHT=16 ALT='Click to open this folder' ALIGN=TEXTTOP BORDER=0>")
					outputFrame.write("<IMG SRC='" + defaultImageURL + iconClosed + "' WIDTH=16 HEIGHT=16 ALT='Click to open this folder' ALIGN=TEXTTOP BORDER=0></A>&nbsp;" + children[currentIndex].name + "<BR>\n")
				}
				else {
					outputFrame.write("<A HREF=\"javascript:top.toggleFolder('" + children[currentIndex].id + "',0)\" onMouseOver=\"window.status='Click to close this folder'; return true\"><IMG SRC='" + defaultImageURL + "img-minus-cont-" + structureStyle + ".gif' WIDTH=19 HEIGHT=16 ALT='Click to close this folder' ALIGN=TEXTTOP BORDER=0>");
					outputFrame.write("<IMG SRC='" + defaultImageURL + iconOpen + "' WIDTH=16 HEIGHT=16 ALT='Click to close this folder' ALIGN=TEXTTOP BORDER=0></A>&nbsp;" + children[currentIndex].name + "<BR>\n");
					newStructure = newStructure + "<IMG SRC='" + defaultImageURL + "img-vert-line-" + structureStyle + ".gif' WIDTH=19 HEIGHT=16 ALIGN=TEXTTOP>";
					drawBranch(children[currentIndex].id,newStructure); 
				}
			}
			else {
				if (children[currentIndex].open == 0) {
					outputFrame.write("<A HREF=\"javascript:top.toggleFolder('" + children[currentIndex].id + "',1)\" onMouseOver=\"window.status='Click to open this folder'; return true\"><IMG SRC='" + defaultImageURL + "img-plus-end-" + structureStyle + ".gif' WIDTH=19 HEIGHT=16 ALT='Click to open this folder' ALIGN=TEXTTOP BORDER=0>")
					outputFrame.write("<IMG SRC='" + defaultImageURL + iconClosed + "' WIDTH=16 HEIGHT=16 ALT='Click to open this folder' ALIGN=TEXTTOP BORDER=0></A>&nbsp;" + children[currentIndex].name + "<BR>\n")
				}
				else {
					outputFrame.write("<A HREF=\"javascript:top.toggleFolder('" + children[currentIndex].id + "',0)\" onMouseOver=\"window.status='Click to close this folder'; return true\"><IMG SRC='" + defaultImageURL + "img-minus-end-" + structureStyle + ".gif' WIDTH=19 HEIGHT=16 ALT='Click to close this folder' ALIGN=TEXTTOP BORDER=0>");
					outputFrame.write("<IMG SRC='" + defaultImageURL + iconOpen + "' WIDTH=16 HEIGHT=16 ALT='Click to close this folder' ALIGN=TEXTTOP BORDER=0></A>&nbsp;" + children[currentIndex].name + "<BR>\n");
					newStructure = newStructure + "<IMG SRC='" + defaultImageURL + "img-blank.gif' WIDTH=19 HEIGHT=16 ALIGN=TEXTTOP>";
					drawBranch(children[currentIndex].id,newStructure); 
				}
			}
		}
		currentIndex++;
	}
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// toggleFolder() - GENERAL FUNCTION - opens/closes folder nodes.

function toggleFolder(id,status) {
	var nodeIndex = indexOfNode(id); 
	treeData[nodeIndex].open = status; 
	timeOutId = setTimeout("drawTree()",100)}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// indexOfNode() - GENERAL FUNCTION - finds the index in the treeData Collection of the node
//						  with the given id.

function indexOfNode(id) {
	var currentIndex = 1;
	while (currentIndex <= treeData.length) {
		if ((treeData[currentIndex].type == 'root') || (treeData[currentIndex].type == 'folder')) {
			if (treeData[currentIndex].id == id) {return currentIndex}} 
		currentIndex++} 
	return -1}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// extractChildrenOf() - GENERAL FUNCTION - extracts and returns a Collection containing all
//							  of the node's immediate children nodes.

function extractChildrenOf(node) {
	var children = new Collection();
	var currentIndex = 1; 
	while (currentIndex <= treeData.length) {
		if ((treeData[currentIndex].type == 'folder') || (treeData[currentIndex].type == 'link')) {
			if (treeData[currentIndex].parent == node) {
				children.add(treeData[currentIndex])}}
		currentIndex++} 
	return children}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Collection() - OBJECT - a dynamic storage structure similar to an Array.

function Collection() {
	this.length = 0; 
	this.add = add; 
	return this}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// add() - METHOD of Collection - adds an object to a Collection.

function add(object) {
	this.length++; 
	this[this.length] = object}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// RootNode() - OBJECT - represents the top-most node of the hierarchial tree.

function RootNode(id,name,url,target,icon) {
	this.id = id;
	this.name = name;
	this.url = url;
	this.target = target;
	this.icon = icon;
	this.type = 'root';
	return this}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// FolderNode() - OBJECT - represents a node which branches to contain other nodes.

function FolderNode(id,parent,name,iconClosed,iconOpen) {
	this.id = id;
	this.parent = parent;
	this.name = name;
	this.iconClosed = iconClosed;
	this.iconOpen = iconOpen;
	this.type = 'folder';
	this.open = 0;
	return this}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// LinkNode() - OBJECT - a node that represents a link using a URL.

function LinkNode(parent,name,url,target,icon) {
	this.parent = parent;
	this.name = name;
	this.url = url;
	this.target = target;
	this.icon = icon;
	this.type = 'link';
	return this}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// loadData() - GENERAL FUNCTION - user defined data and variables exist in this function.

function loadData() {
	structureStyle = 2;
	backgroundColor = '#FFFFFF';
	textColor = '#666666';
	linkColor = '#0000FF';
	aLinkColor = '#FF00FF';
	vLinkColor = '#FF0000';
	defaultLinkIcon = 'img-nspage.gif';
	omenTreeFont = 'Arial,Helvetica';  // the font used for the menu
	omenTreeFontSize = 1;                                // its size - don't make it too big!
	backgroundImage = '';
	prefixHTML = "";
	suffixHTML = "";
	defaultTargetFrame = '1up';      // the name of the frame that links will load into by default 
	defaultImageURL = 'finder_imgs/';	// the remote URL or path where the OmenTree images are located

	treeData = new Collection();

   // Root Node
	treeData.add(new RootNode('root','1up Home','/','','img-1up.gif'));

	// Literature Section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		treeData.add(new FolderNode('Literature','root','Literature','',''));
			treeData.add(new LinkNode('Literature','Index','/literature/literature.html','',''));
			treeData.add(new LinkNode('Literature','Poetry','/literature/poetry.html','',''));
			treeData.add(new LinkNode('Literature','Essays','/literature/essays.html','',''));
			treeData.add(new LinkNode('Literature','1up Quotes','/literature/quotes.html','',''));

	// Photos Section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		treeData.add(new FolderNode('Photos','root','Photos','',''));
			treeData.add(new LinkNode('Photos','Index','/photos/photos.html','',''));
			treeData.add(new LinkNode('Photos','Detroit Zoo','/photos/detroit_zoo.html','',''));
			treeData.add(new LinkNode('Photos','Michigan','/photos/michigan.html','',''));
			treeData.add(new LinkNode('Photos','QuickTimeVR','/photos/quicktime_vr.html','',''));
			treeData.add(new LinkNode('Photos','Travel','/photos/travel.html','',''));
			treeData.add(new LinkNode('Photos','Plymouth Canton Marching Band','/photos/pcmb.html','',''));

	// Music Section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		treeData.add(new FolderNode('Music','root','Music','',''));
			treeData.add(new LinkNode('Music','Index','/music/music.html','',''));
			treeData.add(new LinkNode('Music','Simplicitude','/music/simplicitude.html','',''));
			treeData.add(new LinkNode('Music','Times 7','/music/times_7.html','',''));
			treeData.add(new LinkNode('Music','Rhev21','/music/rhev21.html','',''));
			treeData.add(new LinkNode('Music','Emily','/music/emily.html','',''));
			treeData.add(new LinkNode('Music','Other Music','/music/other_music.html','',''));

	// Algonquin Section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		treeData.add(new FolderNode('Algonquin','root','Algonquin','',''));
			treeData.add(new LinkNode('Algonquin','Index','/algonquin/algonquin.html','',''));
			treeData.add(new FolderNode('VirtualTours','Algonquin','Virtual Tours','',''));
				treeData.add(new LinkNode('VirtualTours','Index','/algonquin/virtual_tours.html','',''));
				treeData.add(new LinkNode('VirtualTours','1994 Virtual Tour','/algonquin/vt1994start.html','',''));
				treeData.add(new LinkNode('VirtualTours','1999 Virtual Tour','/algonquin/vt1999start.html','',''));
				treeData.add(new LinkNode('VirtualTours','2000 Virtual Tour','/algonquin/vt2000start.html','',''));
				treeData.add(new LinkNode('VirtualTours','2002 Virtual Tour','/algonquin/vt2002start.html','',''));
			treeData.add(new FolderNode('Animals','Algonquin','Animals','',''));
				treeData.add(new LinkNode('Animals','Index','/algonquin/animals.html','',''));
				treeData.add(new LinkNode('Animals','Moose','/algonquin/moose.html','',''));
				treeData.add(new LinkNode('Animals','Mammals','/algonquin/mammals.html','',''));
				treeData.add(new LinkNode('Animals','Amphibians & Reptiles','/algonquin/amphibians___reptiles.html','',''));
				treeData.add(new LinkNode('Animals','Insects & Bugs','/algonquin/insects___bugs.html','',''));
			treeData.add(new FolderNode('Birds','Algonquin','Birds','',''));
				treeData.add(new LinkNode('Birds','Index','/algonquin/birds.html','',''));
				treeData.add(new LinkNode('Birds','Loons','/algonquin/loons.html','',''));
				treeData.add(new LinkNode('Birds','Herons','/algonquin/herons.html','',''));
				treeData.add(new LinkNode('Birds','Other Birds','/algonquin/other_birds.html','',''));
			treeData.add(new FolderNode('Flora','Algonquin','Flora','',''));
				treeData.add(new LinkNode('Flora','Index','/algonquin/flora.html','',''));
				treeData.add(new LinkNode('Flora','Flowers','/algonquin/flowers.html','',''));
				treeData.add(new LinkNode('Flora','Fruit','/algonquin/fruit.html','',''));
				treeData.add(new LinkNode('Flora','Fungii','/algonquin/fugnii.html','',''));
				treeData.add(new LinkNode('Flora','Other Flora','/algonquin/other_flora.html','',''));
			treeData.add(new FolderNode('Scenery','Algonquin','Scenery','',''));
				treeData.add(new LinkNode('Scenery','Index','/algonquin/scenery.html','',''));
				treeData.add(new LinkNode('Scenery','Waterfalls & Rapids','/algonquin/waterfalls.html','',''));
				treeData.add(new LinkNode('Scenery','Sunrise & Sunset','/algonquin/sunrise_sunset.html','',''));
				treeData.add(new LinkNode('Scenery','Features & Characteristics','/algonquin/features.html','',''));
				treeData.add(new LinkNode('Scenery','Favorites','/algonquin/favorites.html','',''));

	// Diecast Section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		treeData.add(new FolderNode('Diecast','root','Diecast','',''));
			treeData.add(new LinkNode('Diecast','Index','/diecast/diecast.html','',''));
			treeData.add(new LinkNode('Diecast','Matchbox','/diecast/matchbox.html','',''));
			treeData.add(new LinkNode('Diecast','Playing Mantis','/diecast/playing_mantis.html','',''));
			treeData.add(new LinkNode('Diecast','Hotwheels','/diecast/hotwheels.html','',''));
			treeData.add(new LinkNode('Diecast','Other','/diecast/other.html','',''));
			treeData.add(new LinkNode('Diecast','Search','/diecast/dc_search.html','',''));

	// Geneology Section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		treeData.add(new FolderNode('Geneology','root','Geneology','',''));
			treeData.add(new LinkNode('Geneology','Index','/geneology/geneology.html','',''));
			treeData.add(new LinkNode('Geneology','Forward','/geneology/forward.html','',''));
			treeData.add(new LinkNode('Geneology','Coat of Arms','/geneology/crest.html','',''));
			treeData.add(new LinkNode('Geneology','History','/geneology/history.html','',''));
			treeData.add(new LinkNode('Geneology','Tree','/geneology/tree.html','',''));

	// Info Center Section ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		treeData.add(new FolderNode('Info_Center','root','Info Center','',''));
			treeData.add(new LinkNode('Info_Center','Contents','/info_center/contents.html','',''));
			treeData.add(new LinkNode('Info_Center','Finder/Explorer','/info_center/finder_explorer.html','',''));
			treeData.add(new LinkNode('Info_Center','Search','/info_center/search.html','',''));
			treeData.add(new LinkNode('Info_Center','Contact','/info_center/contact.html','',''));
			treeData.add(new LinkNode('Info_Center','Purpose','/info_center/purpose.html','',''));
			treeData.add(new LinkNode('Info_Center','Resum&eacute;','/info_center/resume.html','',''));
			treeData.add(new LinkNode('Info_Center','Related Links','/info_center/related_links.html','',''));
}

function setOS(value) {
	structureStyle = value;
}
function setBrowser(value){
	defaultLinkIcon = value;
}
function setFontFace(value){
	omenTreeFont = value;
}
function setFontSize(value){
	omenTreeFontSize = value;
}
