/** 

Breadcrumb javascript from http://www.mickweb.com/javascript/tutorials/breadcrumbs/explanation.html
Edited by Tom Pollard on November 9th, 2005 to include style and image specs, and to remove the root breadcrumb to flightline.highline.edu


Future development needs:
     Convert to title case - done 11-14-2005
     Convert web names to meaningful text - done 11-14-2005
     ie: 
     	libauto to System Administration
     	media to Media Services
     	tpollard to Tom Pollard
     	etc.

Note:  the main html file in each folder must be that same as what is speced in the default_page variable.
     

*/

var realList = new Array();
var fakeList = new Array();

realList[0] = "libauto";
fakeList[0] = "Library Systems";
realList[1] = "media";
fakeList[1] = "Media Services Home";
realList[2] = "tpollard";
fakeList[2] = "Tom Pollard's Home";


var listLen = realList.length

// alert("Test flag - Array lenth is: " + listLen)

function spawn(expr,qty,reversed){
var spawnee=[expr];
for(s=1;s<qty;s++){
spawnee[s]=expr+spawnee[s-1];
}
return reversed? spawnee.reverse() : spawnee();
}

function changeCase(teststring) {
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = teststring.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
teststring = tmpStr;

return tmpStr;
}


function mw_crumbs(divider,default_page,root,rootname,rooturl){
if(!divider) {divider=" : "}
if(!default_page){default_page="index.html"}

var m=location.toString(),h="";
m=m.substring(m.indexOf("/")+1);
m=m.split("/");
var howmany=spawn("../",m.length,true);
howmany[m.length]=default_page;

h += ('<img src="http://flightline.highline.edu/libauto/menu/tri.gif" border="0"  alt="Arrow image" width="6" height="6">&nbsp; &nbsp;');
// h += ('>&nbsp; &nbsp;');
h += ("<a class='breadcrumb' href="+rooturl+">"+rootname+"</a>"+divider);
var realdir;
for(i=2;i<m.length-1;i++){
realDir = m[i];

if (i==2) {
  for (x=0;x<=realList.length-1;x++) {
  	// alert("Pass through array is " + x + " of " + realList.length + " " + realDir); 
  	 if (realDir == realList[x]) {realDir = fakeList[x];} 	 
  	 }	
     }	
breadtext = changeCase(realDir);
h+=("<a class='breadcrumb' href="+howmany[i+2]+">"+unescape(breadtext+"</a>"+divider))
}
h +=("<span class='breadcrumb-text'>");
h += document.title;
h +=("</span>");
//h = changeCase(h);

/**
if(root) {
h=h.replace(eval("/"+location.host+"/"),root)
}
*/

return h
}


/**
snippet of code to illustrate the use of an array to swap out the directory name for something more meaningful!


var dList = new Array();
var nList = new Array();

// dir staging to This is a test
dList[0] = 'staging';
nList[0] = 'This is a test';

function breadcrumbs(sClass, sDelimiter)
{
    if(!sDelimiter) sDelimiter = '|';
    var sURL = (location.pathname.indexOf('?') != -1) ? location.pathname.substring(0, location.pathname.indexOf('?')) : location.pathname;
        sURL = (location.pathname.charAt(0) == '/') ? location.pathname.substring(1) : location.pathname;
    var aURL = sURL.split('/');
    if(aURL)
    {
      var sOutput = 'Home ' + sDelimiter + ' ';
      var sPath = '/';
      for(var i = 0; i < aURL.length; i++)
      {
        if(aURL[i].indexOf('.html')!=-1)continue;
        sPath += aURL[i] + '/';
        for(var s = 0; s < dList.length; s++)if(aURL[i]==dList[s])aURL[i]=nList[s];        
        sOutput += '';
        sOutput += ' ' + sDelimiter + ' ';
      }
      sOutput += document.title;
      document.write(sOutput);
    }
}

*/