<!--
/*

Script : navigation-trail.js 
Version : 4.1 
Date : 19 September 2002
- Set home to 'intranet' for /intra/ (still 'maf' for all others)

Contacts : 
  Laurence Clear - clearl@nzfsa.govt.nz
  Dylan Hazlehurst - hazlehurstd@nzfsa.govt.nz
Usage : <script type="text/javascript" language="JavaScript" src="/scripts/navigation-trail-v4.js"></script>

*/

/* 
splt()
Only here for IE3 compatibility (IE3 doesn't support href.split ?)
*/

function splt( s, c ) {

var splits = new Array();
var v = 0, prev = 0, n = 0;
while( v < s.length ) {
  if( s.charAt(v) != c )
   v++;
  else {
   if( v != prev ) 
    splits[n] = s.substring( prev, v );
   else 
    splits[n] = "";
   n++;
   v++;
   prev = v;
  }
}

if( v != prev ) 
  splits[n++] = s.substring( prev, v );
if( s.charAt(s.length-1) == c )
  splits[n++] = "";
return splits;
}




//
//  Set up data
//

var delimiter = " &gt; ";  //navigation trail delimeter
var host="maf";            //text for base dir in the trail
var hostdir="/";           //URL for base dir

/*
Array of contexts.
-this array can be added to.
-paths are from the root and *must* begin and end with a /
e.g. 
arrContextData[0] = new contextObject("/animalproducts/",delimiter + "<a href='/food/'>food</a>");
*/

var arrContextData = new Array();


/*
Array of substitute names for directories.
Where a match is made the substitute name will be displayed.
These arrays can be added to.
arrDirectories is for global substitutes.
arrLocalDirs is for local overrides of global substitutes.
*/

var arrDirectories = new Array();
var arrLocalDirs = new Array();

arrLocalDirs["/MAFnet/"] = "/skip!";
arrLocalDirs["/mafnet/"] = "/skip!";

arrLocalDirs["/biosecurity/about/enforcement/"] = "special investigations group";
arrLocalDirs["/biosecurity/pests-diseases/animals/foot-n-mouth/"] = "foot &amp; mouth";
arrLocalDirs["/biosecurity/pests-diseases/plants/standards/"] = "/skip!";
arrLocalDirs["/biosecurity/exports/animals/standards/"] = "/skip!";
arrLocalDirs["/biosecurity/exports/forests/standards/"] = "/skip!";
arrLocalDirs["/biosecurity/exports/plants/standards/"] = "/skip!";
arrLocalDirs["/biosecurity/imports/forests/standards/"] = "/skip!";
arrLocalDirs["/biosecurity/imports/non-organic/standards/"] = "/skip!";
arrLocalDirs["/biosecurity/pests-diseases/animals/varroa/maps/"] = "/skip!";
arrLocalDirs["/biosecurity/exports/plants/certification/papers/phyto-cert/"] = "phytosanitary certification";
arrLocalDirs["/biosecurity/bio-strategy/"] = "biosecurity&nbsp;strategy";
arrLocalDirs["/biosecurity/pests-diseases/forests/gypsy-moth/residents/"] = "information&nbsp;for&nbsp;Hamilton&nbsp;residents";
arrLocalDirs["/biosecurity/pests-diseases/forests/gypsy-moth/about/"] = "about&nbsp;the&nbsp;gypsy&nbsp;moth";
arrLocalDirs["/biosecurity/pests-diseases/animals/tse/papers/ruminant-feeding-regulations/"] = "/skip!";
arrLocalDirs["/biosecurity/exports/animals/guides/"] = "/skip!";


arrDirectories["antimicrobial"] = "antimicrobial resistance";
arrDirectories["certs"] = "certificates";
arrDirectories["drafts"] = "/skip!";
arrDirectories["hort"] = "horticulture";
arrDirectories["papers"] = "/skip!";
arrDirectories["pests-diseases"] = "pests &amp; diseases";
arrDirectories["press"] = "media centre";
arrDirectories["procedures"] = "/skip!";
arrDirectories["registers-lists"] = "registers &amp; lists";
arrDirectories["risk"] = "risk analyses";
arrDirectories["ruralbulletin"] = "rural bulletin";
arrDirectories["primaryindustries"] = "primary industries";

//
// Do not modify below this point 
//


/*
contextObject creator 
   this.matchpath = the path that will be matched
   this.addpath = the extra bit of the path that you want added to the front of the path to create the desired navigation trail
*/

function contextObject(matchpath,addpath) { 
//   this.matchpath = matchpath.split("/");
   this.matchpathbits = splt( matchpath, "/");
   this.matchpath = matchpath;
   this.addpath = addpath;
} 

var path;

if(!uri){
 var uri = document.location.pathname;
}


if(uri.substring(0,7).toLowerCase() == '/intra/') {
 path = '<a href="/intra/">ST<span style="font-size:11px;vertical-align:middle">&#64;</span>FFnet</a>'; 
} else { 
 path  = "<a href=\"/mafnet/\">" + host + "</a>";   // base dir
}

var direc = hostdir;  // path to nav trail component on the server

//var arrPathBits = uri.split("/"); 
var arrPathBits = splt(uri, "/"); 
var startat = 1;
var newstartat;
var idirectories, jdirectories;

/*
Loop throught the array of context objects until a directory or
group of directories is matched
If a match is found then 
-add the addpath value of the object to the path string
-fill in any missing directories for direc, since we start at an arbitrary place in the path.
-set the startat value to the startat value of the object. 
-stop the loop.
*/

for( var icontext = 0; icontext < arrContextData.length; icontext++ ) {
 if( uri.substring(0,arrContextData[icontext].matchpath.length) == arrContextData[icontext].matchpath ) {
 // Fill any skipped parts of the path
  newstartat = arrContextData[icontext].matchpathbits.length - 2;
  for( jdirectories = startat; jdirectories < newstartat; jdirectories++ )
   direc += arrPathBits[jdirectories] + "/"; 
  path += arrContextData[icontext].addpath;
  startat = newstartat;
  break;
  }
}

/*
Loop through location string
*/

var lastdirectory=false;
var isindex = arrPathBits[arrPathBits.length-1] == "index.htm" || arrPathBits[arrPathBits.length-1] == "index.html" || arrPathBits[arrPathBits.length-1] == "";

for( idirectories = startat; idirectories < arrPathBits.length-1; idirectories++ ) {
 // Check if this is the last directory in the path
 if (idirectories==arrPathBits.length-2)
  lastdirectory=true;

 /*
 If last directory then there is no link
 Test if index file index.htm, index.html
 */
 var strName = arrPathBits[idirectories];

 direc += strName + "/";

 /*
 Where a directory has a substitute name in the arrDirectories array use this 
 to display instead of the real name
 Super-Dehyphenation:
  -If there is no "friendly" name for directory then automatically convert hyphens "-" to spaces, 
   as they nearly always substitute for spaces anyway.
 */

 // Look for local first
 var finalstrName;
 if( arrLocalDirs[direc] ) {
  finalstrName = arrLocalDirs[direc];
  }
 else // look for global
  if( arrDirectories[strName] ) {
   finalstrName = arrDirectories[strName];
   }
  else {
   if ( document.layers || document.all ) {
    re = new RegExp( "-", "g" );
    finalstrName = strName.replace( re, " " );
    }
   else { 
    //browser is too old for .replace() so the hyphens are safe...for now
    finalstrName = strName;
    }
   }

if( finalstrName!="/skip!" ) {
 path += delimiter;
 if( !(lastdirectory && isindex) ) 
  path += "<a href=\"" + direc + "\">";
  
 path += finalstrName;

 //If last directory then there is no link
 if( !(lastdirectory && isindex) ) 
  path += "</a>";
 }

}


document.write (path);

//End -->
