// javascript menu builder
// tkennedy@lycos-inc.com
// versions:
// 0.5: regexp tomfoolery
// 1.0: replication of perl script to javascript
// 1.1: regexp tomfoolery removed -- logic too clunky and cumbersome
// 1.2: angelfire specific menu seperation code added
// 1.3: af specific code generalized for use on other sites without modification to menu builde code, only configuration file
// 1.4: added code for creation of sub menu
// notes:
// this script must be used in conjunction with a site specific datafile in javascript format

function findCategory() {
    rawestCategory = document.location;
    expression = /.*\/(.*)$/;
    rawCategory = expression.exec(rawestCategory);
    strippedCategory = rawCategory[1];
    dotSep = strippedCategory.indexOf(".");
    category = strippedCategory.substr(0,dotSep);
    return category;
}


//print out menu header, beginning of table
document.write(menuHead+"\n");

for(i=0; i < arrayLength; i++) {
    //reset switches
    var currentURL = urls[i];
    var name = longNames[i];
    var currentClass = normalClass;
    var currentLinkClass = normalLinkClass;
    var arrowSwitch = nonArrow;
    var currentCategory = shortNames[i];
    
    //check catagory and set variables appropriately, also check for seperator row.  print out appropriate table row
    if (currentCategory == category) {
	   	if (subMenu != ""){
   		    arrowSwitch = downArrow;
   		    document.write(menuRow1+currentClass+menuRow2+arrowSwitch+menuRow3+currentClass+menuRow4+currentURL+menuRow5+currentLinkClass+menuRow6+name+menuRow7);
	        currentClass = highlightClass;
	        currentLinkClass = highlightLinkClass;
    		arrowSwitch = indentArrow;
    		document.write(menuRow1+currentClass+menuRow2+arrowSwitch+menuRow3+currentClass+menuRow4sub+arrow+subMenu+menuRow7);
   		} else {
	        currentClass = highlightClass;
    	    currentLinkClass = highlightLinkClass;
    	    arrowSwitch = arrow;
			document.write(menuRow1+currentClass+menuRow2+arrowSwitch+menuRow3+currentClass+menuRow4+currentURL+menuRow5+currentLinkClass+menuRow6+name+menuRow7);
		}
    } else if (currentCategory == "sep") {
    	if (sepNames[currentSep] == seperateAt) {
			document.write(sectionSeperator);
			currentSep++;
		}
		//write out seperator with sepName
		document.write(sepStart+sepNames[currentSep]+sepEnd);
		currentSep++;
    } else {
    	document.write(menuRow1+currentClass+menuRow2+arrowSwitch+menuRow3+currentClass+menuRow4+currentURL+menuRow5+currentLinkClass+menuRow6+name+menuRow7);
    }
}

//close tables and menu.  for af, the menu table does not close here, as the top 5 needs to be included, which must be done via SSI
document.write(menuFoot);

