function gup( name ) {
    // function to parse the href line by key/vall pair
    // e.g. 
    // http://www.abc.com/index.html?frank=123?paul=456
    // gup(frank) returns 123
    // gup(paul) returns 456
    // gup = get url parameter
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var tmpURL = window.location.href;
    var results = regex.exec( tmpURL );
    if( results == null )
	return "";
    else
	return results[1];
}

function currentPage() {
    // return the current page after stripping
    // off the rest of the path
    // e.g. http://www.abc.com/aaa/bbb/ccc/page.html
    // returns "page.html"
    
    // get current URL in plain text
    var url = unescape(window.location.href);
    var xend   = url.length;
    var xstart = url.lastIndexOf("/")+1;
    var currPage = url.substring(xstart,xend);
    return currPage;
}

function currentTopic(htmlPage) {
   filenames = getPageFilenames();
   pagenames = getPageNames();
   for (ii=0; ii<filenames.length; ii++)  {
      if (filenames[ii] == htmlPage) {
         return pagenames[ii]
      }
   }
}


function getPageNames() {
    // define the page names in a function
    // so that other .js files in this directory
    // can access these arrays
    var pageNames = new Array("Home",
			      "Research",
			      "Teaching",
			      "CV",
			      "Contact");
    return pageNames;
}

function getPageFilenames() {
    // define the page names in a function
    // so that other .js files in this directory
    // can access these arrays
    var pageFilenames = new Array("index.html",
				  "research.html",
				  "teaching.html", 
				  "cv.html", 
				  "contact.html");
    return pageFilenames;
}

function getHeaderImages() {
    var headerImages = new Array("battat.jpg",
                                 //"boardwalk.jpg",
                                 "whirlpool_crop_bw.jpg",
                                 //"whirlpool_crop.jpg",
                                 //"sombrero.jpg",
				 //"blackboard1_crop.jpg",
				 "einsteinshow_crop.jpg",
				 //"orchid.jpg",
				 //"dogwood.jpg",
				 "dogwood_bw.jpg",
				 "adam_small-1.jpg");
				 //"autumnRoad.jpg");
    return headerImages;
}


var pageNames     = getPageNames();
var pageFilenames = getPageFilenames();

// keep track of the link status 
var status = new Array();
var allInactive = 1;

// loop over all links to find the active one
for (ii=0; ii<pageNames.length; ii++)  {
    // get the current webpage to
    // determine which link is active
    // set inactive by default
    status[ii] = "inactive";
    if (currentPage() == pageFilenames[ii]) {
	status[ii] = "active";
	//stat = "active";
	allInactive = 0;
    }
}
// if all are inactive, make the first link the active one
if (allInactive) {
    status[0] = "active";
}

// then write the links
for (ii=0; ii<pageNames.length; ii++) {
    document.write('<a class='+status[ii]+' href="'+pageFilenames[ii]+'">'+pageNames[ii]+'</a>');
}

