// Poor mans Javascript navigation bar for Citydesk sites
// (c)2002 Adriaan van den Brand
// http://www.zonnet.nl/adriaan_brand
// adriaan_brand@zonnet.nl

var arrow=' > '; // replace with image if you like, e.g. ' <IMG src="/mnu/arrow.gif"> ';

// menu in title bar
// generate an array of all index files
// root index separately because we want to name it Home (and not use the pretty title)
// last item is now empty, but will be filled dynamically in createNavMenu
// arMenu[][2] contains all paths\index.html with known header names 
var arMenu=new Array (

"/index.html","Home",

"/amelie/index.html","index",
"/software/index.html","Software-Tools",
"/foto/index.html","Fotografie",
"/malt/index.html","Malt Whisky",
"/books/index.html","Meine Bücher",
"/entries/index.html","Weblog oder Krimskrams?",
"/armin/index.html","Arminius",
"/dea/index.html","Andrea's Seiten",
"","");


var topMenu=""; // this global is filled with the menu; use document.write to get it in your pages
var publishPath=""; 


// internal function
// find path in arMenu and append item to menu if found
// if linkit==true then it will become a hyperlink (not for the page itselves)
function FindMenu(path,linkit)
{ 
  path=unescape(path);
  path=path.replace(/\\/gi,"/");   // just in case we're previewing on Windows machines : backslash --> slash
  for (var index=0;index<arMenu.length;index+=2)
  { 
    // check if path matches with item in arMenu (without index.html)
    cmp= arMenu[index].substring(0,arMenu[index].lastIndexOf("/"));
    if (path == cmp) 
	{
      if (linkit) // should we create a link ?
      {
        if(index<(arMenu.length-2)) {
           if (topMenu != "") topMenu=topMenu+arrow;
             topMenu=topMenu + '<a class="mainjump" href="'+publishPath+arMenu[index]+'">'+arMenu[index+1]+"</a>";
        }		  
      }
      else
      {  // linkit == false so only append title (not hyperlinked)
        if (topMenu != "") 	   
          topMenu=topMenu+arrow; 
        topMenu=topMenu + arMenu[index+1];
      }
     return 1; // found
    } 
  }
  if ((path==arMenu[arMenu.length-2]) && (path.indexOf("index.")<0) ) // last item = current page
  {
    topMenu=topMenu + arrow + arMenu[arMenu.length-1];
    return 1; // found
  }
  return 0; // not found
}

// create a navigation menu for path
// all elements of path are searched for in arMenu
// if found, then the headline of the page will be appended, hyperlinked to the index.html in that directory
function createNavMenu(path,headline)
{
  topMenu="";
  var menu="";
  var currentPath=unescape(location.pathname);
  currentPath=currentPath.replace(/\\/gi,"/"); // replace backslashes to fwd slashes
  var ppLen= currentPath.indexOf(path);           // find abslink in 'real' url
  if (ppLen >0)
  {
    publishPath = currentPath.substring(0,ppLen);
  }
  if (path.indexOf("index")<0)
  {
    arMenu[arMenu.length-2]=path;
    arMenu[arMenu.length-1]=headline; 
  }

  var lastindex=0;
  var index = 0;
  var einde=0;
  var startindex=lastindex+1;
  var lastSlashPos=(currentPath.indexOf("index")>=0)?currentPath.lastIndexOf("/"):-1;
  // iterate trough path; check every directory from root till filename
  do {
    index = currentPath.indexOf("/", lastindex); 
    if (index<0) 
    { 
      FindMenu(currentPath.substring(startindex-1,1000));
    }
    else
    { 
      if (!FindMenu(currentPath.substring(startindex-1, index),(index!=lastSlashPos)))
      {
        startindex=index+1;
      }
    }
    lastindex=index+1;
  } while (index != -1);
} 

