
// *************************************************************************************
// 2 Level Menu Script Javascript
//
// Usage: In the head of your document put this script.
//        In the body of your document where you want the menu to appear put: <script>document.write(HTMLSection);</script>
//      * Each and every page must have it's own 'codes'. The SectionCode is a zero-based number
//         keyed to each major section. The order is determined in the array, NOT by the SectionCode value.
//         The SubSectionCode works in a similar way. The base-page for a section (often index.htm)
//         will have a SubSectionCode value (zero-based) of '' (null).
//         The value for SubSectionCode for the sub-sections is zero-based on the order they
//         are entered. The display order of the sub-Sections is determined in the data array,
//         NOT by the SubSectionCode value.
//         Page code example:
//                     <SCRIPT LANGUAGE="JavaScript">
//                     // JS_Menu Script
//                     // The following are vars for EACH AND EVERY PAGE.
//                     // if a sub-section is '' (null), then that section has no sub-sections.
//  change this -->    var SectionCode = '1'; // major sections 
//     and this -->    var SubSectionCode = '2'; // sub-sections
//                     </SCRIPT>
//      * Change the BaseURL to your base URL.
//      * Change SectionNumbers & SubSectionNumbers to reflect how many of each you have.

//      * Populate the section & subsection arrays. (see in-script documentation)
//
// Version: 0.92
// Date: 12JAN2005
// Author: Eric Zander (eric_zander@yahoo.com)
//
// Changes between 0.91 and 0.92:
//			BaseURL2 added.
//
// Changes between version 0.90 and 0.91:
//         Calculation of BaseURL modified to be more flexible. Script will now run from web
//         or CD or locally or wherever you want to stick it!
//
// NOTE: This script is free... please send me an email letting me know you're using it and what you think.
//       
// *************************************************************************************


// The following are vars for the script itself.
var SectionNumbers = '10'; // Total number of major sections
var SubSectionNumbers = '22'; // Total number of ALL Sub sections

// Calculation of the base URL to precede the urls in the arrays.
// BaseFolder is the highest level folder that is common to all files. It can be a folder or
// URL or snippet i.e. www.ericzander.com would work for web-only but since the base folder
// on my HD which holds the website is called ericzander.com (no 'www.'), I just use 'ericzander.com'
// now, if I burn the site to CD, no modifications are needed.
var BaseFolder = "ericzander.com/"

var DocURL = document.URL  // URL of current document
// BaseURL is the URL of the current document with anything that follows BaseFolder sliced off.
// Later in the script (below the arrays) individual links are formulated by adding paths to BaseURL.
var BaseURL=DocURL.slice(0, DocURL.indexOf(BaseFolder) + BaseFolder.length)

// These next couple of lines are for an alternate URL. For example, I have two domain names
// pointing to the sane IP address. So if someone enters the site by way of the alternate domain name,
// we need to calculate accordingly. Could change this to replace the alternate domain name which might be better.
var BaseFolder2 = "zebraz.org/"
if  (DocURL.lastIndexOf(BaseFolder2) > 0) {
	BaseURL=DocURL.slice(0, DocURL.indexOf(BaseFolder2) + BaseFolder2.length)
	}
//

// SectionArray Definition:
// SectionArray[x][0] = Text user sees (name of section)
// SectionArray[x][1] = URL of link relative to base URL
// SectionArray[x][2] = Order in menu (zero = first)
// SectionArray[x][3] = SectionCode
// SectionArray[x][4] = SubSection Flag. If does not exist, no SubSections.

var SectionArray=new Array(SectionNumbers)
for (i=0; i <SectionNumbers; i++) {
	SectionArray[i]=new Array(5)
	}

SectionArray[0][0] = ('Home');
SectionArray[0][1] = ('index.htm');
SectionArray[0][2] = ('0');
SectionArray[0][3] = ('0');

SectionArray[1][0] = ('Bike Trip &rsquo;98');
SectionArray[1][1] = ('BikeTrip98/index.htm');
SectionArray[1][2] = ('1');
SectionArray[1][3] = ('1');
SectionArray[1][4] = ('1');

SectionArray[2][0] = ('Recipes');
SectionArray[2][1] = ('Recipes/index.htm');
SectionArray[2][2] = ('2');
SectionArray[2][3] = ('2');

SectionArray[3][0] = ('Publications');
SectionArray[3][1] = ('Publications/index.htm');
SectionArray[3][2] = ('3');
SectionArray[3][3] = ('3');

SectionArray[4][0] = ('Running');
SectionArray[4][1] = ('Running/index.htm');
SectionArray[4][2] = ('4');
SectionArray[4][3] = ('4');
SectionArray[4][4] = ('1');

SectionArray[5][0] = ('Lindsey');
SectionArray[5][1] = ('Lindsey/index.htm');
SectionArray[5][2] = ('5');
SectionArray[5][3] = ('5');

SectionArray[6][0] = ('Links');
SectionArray[6][1] = ('index2.htm');
SectionArray[6][2] = ('9');
SectionArray[6][3] = ('6');

SectionArray[7][0] = ('Technology Used');
SectionArray[7][1] = ('Technology/index.htm');
SectionArray[7][2] = ('8');
SectionArray[7][3] = ('7');
SectionArray[7][4] = ('1');

SectionArray[8][0] = ('ZebraZ');
SectionArray[8][1] = ('ZebraZ/index.htm');
SectionArray[8][2] = ('7');
SectionArray[8][3] = ('8');
SectionArray[8][4] = ('1');

SectionArray[9][0] = ('Homework');
SectionArray[9][1] = ('Homework/index.htm');
SectionArray[9][2] = ('6');
SectionArray[9][3] = ('9');
SectionArray[9][4] = ('1');


// SubSectionArray Definition: (same as SectionArray but used slightly differently)
// SubSectionArray[x][0] = Text user sees (name of section)
// SubSectionArray[x][1] = URL of link relative to base URL
// SubSectionArray[x][2] = Order in menu (zero = first)
// SubSectionArray[x][3] = SectionCode

var SubSectionArray=new Array(SubSectionNumbers)
for (i=0; i <SubSectionNumbers; i++) {
	SubSectionArray[i]=new Array(4)
	}

// Bike Trip
SubSectionArray[0][0] = ('Raw Logs');
SubSectionArray[0][1] = ('BikeTrip98/RawLogs/index.htm');
SubSectionArray[0][2] = ('0');
SubSectionArray[0][3] = ('1');

SubSectionArray[1][0] = ('RoadKill Reports');
SubSectionArray[1][1] = ('BikeTrip98/RoadKillReports/index.htm');
SubSectionArray[1][2] = ('1');
SubSectionArray[1][3] = ('1');

SubSectionArray[2][0] = ('Statistics');
SubSectionArray[2][1] = ('BikeTrip98/Stats.htm');
SubSectionArray[2][2] = ('2');
SubSectionArray[2][3] = ('1');

SubSectionArray[3][0] = ('Packing List');
SubSectionArray[3][1] = ('BikeTrip98/PackingList.htm');
SubSectionArray[3][2] = ('3');
SubSectionArray[3][3] = ('1');

SubSectionArray[4][0] = ('Advice');
SubSectionArray[4][1] = ('BikeTrip98/Advice.htm');
SubSectionArray[4][2] = ('4');
SubSectionArray[4][3] = ('1');

SubSectionArray[5][0] = ('Map of Route');
SubSectionArray[5][1] = ('BikeTrip98/RouteMap.htm');
SubSectionArray[5][2] = ('5');
SubSectionArray[5][3] = ('1');

SubSectionArray[6][0] = ('Pictures');
SubSectionArray[6][1] = ('BikeTrip98/Pictures/index.htm');
SubSectionArray[6][2] = ('6');
SubSectionArray[6][3] = ('1');

// Running
SubSectionArray[7][0] = ('Books');
SubSectionArray[7][1] = ('Running/books.htm');
SubSectionArray[7][2] = ('0');
SubSectionArray[7][3] = ('4');

SubSectionArray[8][0] = ('Clubs/Links');
SubSectionArray[8][1] = ('Running/links.htm');
SubSectionArray[8][2] = ('1');
SubSectionArray[8][3] = ('4');

SubSectionArray[9][0] = ('Tom&rsquo;s Run');
SubSectionArray[9][1] = ('Running/TomsRun/index.htm');
SubSectionArray[9][2] = ('2');
SubSectionArray[9][3] = ('4');

SubSectionArray[10][0] = ('Rizzeri&rsquo;s Bitches');
SubSectionArray[10][1] = ('Running/MCM.htm');
SubSectionArray[10][2] = ('3');
SubSectionArray[10][3] = ('4');

SubSectionArray[11][0] = ('MCM 2002');
SubSectionArray[11][1] = ('Running/MCM02.htm');
SubSectionArray[11][2] = ('4');
SubSectionArray[11][3] = ('4');

// Technology
SubSectionArray[12][0] = ('Javascripts');
SubSectionArray[12][1] = ('Technology/Javascripts.htm');
SubSectionArray[12][2] = ('0');
SubSectionArray[12][3] = ('7');

SubSectionArray[13][0] = ('PHP Scripts');
SubSectionArray[13][1] = ('Technology/PHPScripts.htm');
SubSectionArray[13][2] = ('1');
SubSectionArray[13][3] = ('7');

SubSectionArray[14][0] = ('Other Scripts');
SubSectionArray[14][1] = ('Technology/OtherScripts.htm');
SubSectionArray[14][2] = ('2');
SubSectionArray[14][3] = ('7');

SubSectionArray[15][0] = ('Screenshots');
SubSectionArray[15][1] = ('ZebraZ/Screenshots/index.htm');
SubSectionArray[15][2] = ('0');
SubSectionArray[15][3] = ('8');

SubSectionArray[16][0] = ('Demo');
SubSectionArray[16][1] = ('ZebraZ/Browse.php" target="_blank');
SubSectionArray[16][2] = ('1');
SubSectionArray[16][3] = ('8');

SubSectionArray[17][0] = ('Roadmap');
SubSectionArray[17][1] = ('ZebraZ/Roadmap.htm');
SubSectionArray[17][2] = ('2');
SubSectionArray[17][3] = ('8');

SubSectionArray[18][0] = ('Download ZebraZ');
SubSectionArray[18][1] = ('Publications/ZebraZ.zip');
SubSectionArray[18][2] = ('3');
SubSectionArray[18][3] = ('8');

// Homework
SubSectionArray[19][0] = ('Rain Barrels');
SubSectionArray[19][1] = ('Homework/Rainbarrel/index.htm');
SubSectionArray[19][2] = ('0');
SubSectionArray[19][3] = ('9');

SubSectionArray[20][0] = ('Waterproofing');
SubSectionArray[20][1] = ('Homework/Waterproofing/index.htm');
SubSectionArray[20][2] = ('1');
SubSectionArray[20][3] = ('9');

SubSectionArray[21][0] = ('Resources');
SubSectionArray[21][1] = ('Homework/Resources.htm');
SubSectionArray[21][2] = ('2');
SubSectionArray[21][3] = ('9');



// Following are the HTML pieces
// When finally assembled the order of these pieces goes something like this:
//   HTMLHead
//   [repeat as needed]
//   HTMLPreLink, HTMLLinkOpen, [insert URL], HTMLLinkPreClose,
//   [optional: insert HTMLBoldOpen], [insert link name/text], [optional: insert HTMLBoldClose],
//   HTMLLinkTagClose
//   [if followed by subsections, repeat as needed]
//   HTMLSubSectionBetween, HTMLLinkOpen, [insert URL], HTMLLinkPreClose,
//   [optional: insert HTMLBoldOpen], [insert link name/text], [optional: insert HTMLBoldClose],
//   HTMLLinkTagClose
//   [finally finish off]
//   HTMLFooter

var HTMLHead = '<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#333333" align="center"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#CC3300"><tr><td width="50%"><font class="ColumnHeader">Sections</font></td></tr></table></td></tr>';
var HTMLPreLink = '<tr><td bgcolor="#CCCCCC" class="ColumnText">';
var HTMLPostLink = '</td></tr>';
var HTMLFooter = '</table>';
var HTMLParaTagOpen = '<p>';
var HTMLParaTagClose = '</p>';
var HTMLBoldOpen = '<b>';
var HTMLBoldClose = '</b>';
var HTMLSubSectionBetween = '<br>&nbsp;&nbsp;&nbsp;&nbsp;';
var HTMLLinkOpen = '<a href="';
var HTMLLinkPreClose = '">'
var HTMLLinkTagClose = '</a>';

// Following are vars used for putting the HTML pieces together.
var HTMLSection = '';
var HTMLSubSection = '';

// OK, now that we've got the arrays and vars defined, lets get going on the processing.
// Because we are using absolute links (relative to the home page), we don't need to do
// any fancy URL processing.

//Begin a loop to process the sections.
for (var i=0; i<SectionNumbers; i++) {
	// need a loop within a loop to determine section order
	for (ii=0; ii<SectionNumbers; ii++) {
		if (SectionArray[ii][2] == i) {
			HTMLSection += (HTMLPreLink + HTMLLinkOpen + BaseURL + SectionArray[ii][1] + HTMLLinkPreClose);
			// Check if should be bold
			if (SectionArray[ii][3] == SectionCode) {
				HTMLSection += (HTMLBoldOpen + SectionArray[ii][0] + HTMLBoldClose + HTMLLinkTagClose)
				//check for and do subsection
				if (SectionArray[ii][4]) {
					HTMLSection += ProcessSubSection(ii, SubSectionNumbers, SubSectionArray)
					}
				}
			// if should not be bold
			else {
				HTMLSection += (SectionArray[ii][0] + HTMLLinkTagClose)
				}
			// now close the link
			HTMLSection += HTMLPostLink
			}
		}
	}
// Add header & final HTML
HTMLSection = HTMLHead + HTMLSection + HTMLFooter;


// Begin SubSection Loop
function ProcessSubSection(SelectedSection) {
	// reset HTMLSubSection to nothing
	HTMLSubSection = ''
	// begin processing loop
	for (var i=0; i < SubSectionNumbers; i++) {
		for (var ii=0; ii < SubSectionNumbers; ii++) {
			// check if current sub-section array value is (1) for the right section and,
			// (2) right order (they might be out of order)
			if (SubSectionArray[ii][3]==SelectedSection&&SubSectionArray[ii][2]==i) {
				HTMLSubSection += (HTMLSubSectionBetween + HTMLLinkOpen + BaseURL + SubSectionArray[ii][1] + HTMLLinkPreClose)
				// check if the current sub-section array value should be bold
				if (SubSectionArray[ii][2]==SubSectionCode) {
					HTMLSubSection += (HTMLBoldOpen + SubSectionArray[ii][0] + HTMLBoldClose)
					}
				// if not bold...
				else {
					HTMLSubSection += SubSectionArray[ii][0]
					}
				// close the block of code out
				HTMLSubSection += HTMLLinkTagClose
				}
			}
		}
	// Pass HTML string back.
	return HTMLSubSection;
	}
//-->
