// 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='<span class="bullet">&nbsp;&raquo;&nbsp;</span>'; // 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 (

"/old.html","Home",

"/Articles/Features/index.html","Past Features",
"/Articles/index.html","Articles",
"/Articles/Accessible/index.html","Accessible",
"/Articles/Activities/index.html","Activities",
"/Articles/ArtsandEntertainment/index.html","A&amp;E",
"/Articles/AskUs/index.html","Phyllis Eileen Banks",
"/Articles/Attractions/index.html","Attractions",
"/Articles/BookReviews/index.html","Book Reviews",
"/Articles/Communities/index.html","Communities",
"/Articles/Counties/index.html","Counties",
"/Articles/Destinations/index.html","Destinations",
"/Articles/Dining/Dining.html","Dining",
"/Articles/Driving/index.html","Scenic Drives",
"/Articles/Elderly/index.html","Elderly-Friendly",
"/Articles/Events/index.html","Events",
"/Articles/Fall/index.html","Fall",
"/Articles/FederalLand/index.html","Federal Land",
"/Articles/Food/index.html","Food ",
"/Articles/GeneralInterest/index.html","General Interest",
"/Articles/History/index.html","History &amp; Nostalgia",
"/Articles/Kids/index.html","Kids",
"/Articles/Lodging/index.html","Lodging",
"/Articles/Museums/index.html","Museums",
"/Articles/Outdoors/index.html","Outdoors",
"/Articles/People/index.html","People",
"/Articles/Pets/index.html","Pets",
"/Articles/Plants/index.html","Plants",
"/Articles/RealEstate/index.html","David Burch",
"/Articles/RecentArticles/index.html","Recent Articles",
"/Articles/RequestsforInformation/index.html","Information Requests",
"/Articles/Romantic/index.html","Romantic",
"/Articles/Shopping/index.html","Shopping",
"/Articles/SiteMap/index.html","Site Map",
"/Articles/Southeast/index.html","Southeast",
"/Articles/Southeast/Chaves/index.html","Chaves County",
"/Articles/Southeast/Chaves/Roswell/index.html","Roswell",
"/Articles/Southeast/Curry/index.html","Curry County",
"/Articles/Southeast/Curry/Clovis/index.html","Clovis",
"/Articles/Southeast/De_Baca/FortSumner/index.html","Fort Sumner",
"/Articles/Southeast/Eddy/index.html","Eddy County",
"/Articles/Southeast/Eddy/Jal/index.html","Jal",
"/Articles/Southeast/Eddy/Carlsbad/index.html","Carlsbad",
"/Articles/Southeast/Eddy/Artesia/index.html","Artesia",
"/Articles/Southeast/Lea/index.html","Lea County",
"/Articles/Southeast/Lea/Hobbs/index.html","Hobbs",
"/Articles/Southeast/Lincoln/index.html","Lincoln County",
"/Articles/Southeast/Lincoln/Lincoln/index.html","Lincoln",
"/Articles/Southeast/Lincoln/Capitan/index.html","Capitan",
"/Articles/Southeast/Lincoln/Carrizozo/index.html","Carrizozo",
"/Articles/Southeast/Lincoln/Ruidoso/index.html","Ruidoso",
"/Articles/Southeast/Otero/index.html","Otero County",
"/Articles/Southeast/Otero/Cloudcroft/index.html","Cloudcroft ",
"/Articles/Southeast/Otero/Tularosa/index.html","Tularosa",
"/Articles/Southeast/Otero/Alamogordo/index.html","Alamogordo",
"/Articles/Southeast/Roosevelt/index.html","Roosevelt County",
"/Articles/Southeast/Roosevelt/Portales/index.html","Portales",
"/Articles/Southwest/index.html","Southwest New Mexico",
"/Articles/Southwest/Catron/Mogollon/MogollonNews/index.html","Uncle River",
"/Articles/Southwest/Catron/Mogollon/index.html","Mogollon",
"/Articles/Southwest/Catron/index.html","Catron County",
"/Articles/Southwest/Dona_Ana/index.html","Doña Ana County ",
"/Articles/Southwest/Dona_Ana/Anthony/index.html","Anthony",
"/Articles/Southwest/Dona_Ana/Hatch/index.html","Hatch",
"/Articles/Southwest/Dona_Ana/LaMesilla/index.html","La Mesilla",
"/Articles/Southwest/Dona_Ana/LasCruces/index.html","Las Cruces",
"/Articles/Southwest/GilaWilderness/index.html","Gila Wilderness",
"/Articles/Southwest/Grant/TravelPlanner.html","Grant County",
"/Articles/Southwest/Grant/index.html","Grant County",
"/Articles/Southwest/Grant/Glenwood/index.html","Glenwood",
"/Articles/Southwest/Grant/Silver_City/index.html","Silver City",
"/Articles/Southwest/Hildago/index.html","Hildago County",
"/Articles/Southwest/Hildago/Lordsburg/index.html","Lordsburg",
"/Articles/Southwest/Luna/index.html","Luna County",
"/Articles/Southwest/Luna/Columbus/index.html","Columbus",
"/Articles/Southwest/Luna/Deming/index.html","Deming",
"/Articles/Southwest/Sierra/index.html","Sierra County",
"/Articles/Southwest/Sierra/ElephantButte/index.html","Elephant Butte",
"/Articles/Southwest/Sierra/TorC/index.html","Truth or Consequences",
"/Articles/Southwest/Socorro/index.html","Socorro County",
"/Articles/Southwest/Socorro/Socorro/index.html","Socorro",
"/Articles/Southwest/Socorro/Magdalena/index.html","Magdalena",
"/Articles/Spring/index.html","Spring",
"/Articles/StateLand/index.html","State Land",
"/Articles/Summer/index.html","Summer",
"/Articles/Travelogues/index.html","Travelogues",
"/Articles/Water/index.html","Water",
"/Articles/Wildlife/index.html","Wildlife",
"/Articles/Wine/index.html","Wine",
"/Articles/Winter/index.html","Winter",
"/AuthorBios/index.html","Writers Showcase",
"/Books/Roaming_Southern_New_Mexico/book.html","David Burch",
"/BusinessDirectory/index.html","Business Directory",
"/BusinessDirectory/HealthCare/index.html","Health Care",
"/BusinessDirectory/Attractions/index.html","Attractions",
"/BusinessDirectory/Dining/index.html","Dining",
"/BusinessDirectory/Expired/index.html","Activities",
"/BusinessDirectory/Lodging/index.html","Lodging",
"/BusinessDirectory/Museums/index.html","Museums",
"/BusinessDirectory/Publications/index.html","Magdalena",
"/BusinessDirectory/RealEstate/index.html","Real Estate",
"/BusinessDirectory/Shopping/index.html","Shopping",
"/BusinessDirectory/SpasandResorts/index.html","Spas and Resorts",
"/BusinessDirectory/Transportation/index.html","Magdalena",
"/BusinessDirectory/Universities/index.html","Universities",
"/Common/Guidelines.html","David Burch",
"/Common/navigation.html","",
"/Common/Keywords.html","Southeast",
"/Maps/index.html","Maps",
"","");


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="nav" 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 author of the page will be appended, hyperlinked to the index.html in that directory
function createNavMenu(path,author)
{
  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]=author; 
  }

  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);
} 


