/*
Copyright Justin Whitford 2001.
  http://www.whitford.id.au/
Perpetual, non-exclusive license to use this code is granted
on the condition that this notice is left intact.

may 2008:
http://www.whitford.id.au/webmonkey/code/breadcrumbs/
*/
  function breadcrumbs(){
    sURL = new String;
    bits = new Object;
    var x = 0;
    var stop = 0;
    var output = "";	 // originally:  "<A HREF=\"/\">Home</A>"; but this takes us out of chemung folder

    // get url to strip folder names out of
	sURL = location.href;
	
	// removes "http://" from url
    sURL = sURL.slice(7, sURL.length);
//	alert("sURL: " + sURL)
	
	// get where next "/" is
	chunkStart = sURL.indexOf("/");
//	alert("chunkStart: " + chunkStart)
	
	// store what is to the right of that "/"
    sURL = sURL.slice(chunkStart+1, sURL.length)

    // slice up url into bits
	while(!stop){
	  chunkStart = sURL.indexOf("/");
      if (chunkStart != -1){
		bits[x] = sURL.slice(0, chunkStart)
        sURL = sURL.slice(chunkStart+1, sURL.length);
      }else{
        stop = 1;
      }
      x++;
    }

    // collect in output all the bits
	for(var i in bits){
	  // if first part of breadcrumb, add no " > " at start; but want them between each item only
	  if(i==0){
	  	prefix = ""
	  } else {
	  	prefix = " > "	
	  }
	  output += prefix + "<A HREF=\"";
      
	  // adding "up a level" for each folder
	  for(y = 1; y < x-i; y++){
        output += "../";
      }
	  // add bits to breadcrumb links, with corrections
	  output += bits[i] + "/\">" + correct(bits[i]) + "</A>";	 	 
    }
	
	// write out entire series of links
    document.write(output);
 }


// various corrections for breadcrumb elements
function correct(obj){
	// check if "chemung": change to "home" for display in the breadcrumb trail
	if(obj == "chemung"){
		obj = "home"
	}
	// to capitalize first letter of each word in trail
	var testwd = obj; 
	var firstLetter = testwd.substr(0,1); 
	var rest = testwd.substr(1, testwd.length -1) 
	obj = firstLetter.toUpperCase() + rest 
	return obj
}

