<!--

// Three functions to build side nav, cookie crumbs and
// determine directory depth

// the BuildCookieCrumbsProvost and BuildSideNavProvost function are passed
// arrays from second level pages, those arrays are 
// defined normally in a file called sitedata.html which lives
// in second level sites and in turn is included in all of 
// the pages in the second leve site
// these arrays include the pages titles and page urls for 
// the second level sites
// looks like this
// durls[0] = 'index.html'
// durls[1] = 'arts.html'
// dts[0] = 'Around Austin'
// dts[1] = 'Arts &amp; Entertainment'



function BuildCookieCrumbsProvost(fn,titles,root,acroList) {
	
	// The home variable is set to include a link back to the UT home page
	// and the words UT Home, this is static
	
	var home = '&nbsp; <a href="http://www.utexas.edu/">UT Home</a> -&gt; ';
	
	// fn is an array of filenames for the site
	// titles is an array of titles for the site
	// path is the directory path for the site
	// all three of these are passed from second level pages
	// and the arrays are specified in sitedata.html in the second
	// level site	
	var path = window.location.pathname; // the pathname of the current page following the domain, i.e. '/provost/faculty/index.html'
	
	var depth = depthOf(path); // depth of file, i.e. '/provost/faculty/index.html' = depth of 2
	
	var crumbs = home + '<a href="' + root + fn[0] + '">' + titles[0] + '</a> -&gt; '; // initiate root breadcrumb as a link
	
	var sideNavLoc =  sideNavIndex(path,root,fn); // location, if any, of item in sideNav


	
	/////////////////
	// Location: root
	if(depth == 1) {
		
		if( hasIndex(path) == true ) {

			// write root as text
			document.write(home + titles[0]);
			
		} else {
			
			// file other than index.html, write root as link and filename as text
			crumbs += makePretty(path.split("/")[2],acroList);
			
			document.write(crumbs);
		}
		
	}
	//////////////////////
	// Location: 2nd level
	else if(depth == 2) {
		
		
		// build 2nd level based on sideNav		
		if( sideNavLoc != false ) {

			if( hasIndex(path) == true ) {

				// write parentDirectory as text
				crumbs += titles[sideNavLoc];
				
			} else {
				
				// write parentDirectory as link & filename as text
				crumbs += '<a href="' + root + fn[sideNavLoc] + '">' + titles[sideNavLoc] + '</a> -&gt; ' + makePretty(path.split("/")[3],acroList);
				
			}
			
		}
		// build 2nd level based on directory after root and NOT sideNav
		else {
			
			if( hasIndex(path) == true ) {
				
				// write parentDirectory as text
				crumbs += makePretty(path.split("/")[2],acroList);
				
			} else {
				
				// write parentDirectory as link & filename as text
				crumbs += '<a href="' + root + path.split("/")[2] + '/">' + makePretty(path.split("/")[2],acroList) + '</a> -&gt; ' + makePretty(path.split("/")[3],acroList);
				
			}
		}
		
		document.write(crumbs);
	
	}
	/////////////////////////////
	// Location: beyond 2nd level
	else {
				
		// build 2nd level breadcrumb
		if( sideNavLoc != false ) {
			crumbs += '<a href="' + root + fn[sideNavLoc] + '">' + titles[sideNavLoc] + '</a> -&gt; ';
		} else {
			crumbs += '<a href="' + root + path.split("/")[2] + '">' + makePretty(path.split("/")[2],acroList) + '</a> -&gt; ';
		}
		
		// build the rest of the breadcrumbs beyond 2nd level
		var stopIndex = depth;
		
		if(hasIndex(path) == false) { stopIndex += 1; }
		
		for(var j=3; j<=stopIndex; j++)
		{
			if( j != stopIndex ) {
				crumbs += buildLink(path.split("/"),j);
			} else {
				// writes the text
				crumbs += makePretty(path.split("/")[stopIndex],acroList);
			}
		}
		
		document.write(crumbs);
	}
}

function buildLink(path,stop)
{
	// creates a link
	
	var crumb;
	var newPath = '';
	
	for(var i=1; i<stop+1; i++)
	{
		newPath += "/" + path[i];
	}
	
	crumb = '<a href="' + newPath + '">' + makePretty(path[stop],acroList) + '</a> -&gt; ';
	
	return crumb;
}

function sideNavIndex(path,root,fn) {
	
	// checks to see if path is found in sideNav (sitedata.html)
	
	var loc = false;

	for(var i=0; i<fn.length; i++)
	{
		if( path.match(root+fn[i]) != null )
		{
			loc = i;
		}
	}

	return loc;
}

function makePretty(word,acroList)
{
	// makes uppercase
	// converts underscores to spaces
	// removes '.html'
	
	word = word.replace(/_/g," "); // converts underscores to spaces
	word = word.replace(/%20/g," "); // converts %20 to spaces
	word = word.replace(/.html/,""); // removes '.html'
	
	/* special cases */
	word = word.replace(/academicservicelearning/,"Academic Service-Learning");
	word = word.replace(/provosthistory/,"Provost History");
	word = word.replace(/ftgp/,"Faculty Travel Grant Program");
	word = word.replace(/orgcharts/,"ORG Charts");
	word = word.replace(/vsa/,"Voluntary System of Accountability");
	word = word.replace(/plus-minus/,"Plus/Minus");
	word = word.replace(/racecode/,"Race Code");
	word = word.replace(/qa/,"Q & A");
	
	
	var wordArray = word.split(" ");
	var newWord = '';
	
	// makes words in String, uppercase
	for(var i=0; i<wordArray.length; i++)
	{

		// checks if word is found in Acronym list
		// if true, make word all uppercase
		if(isAcronym(wordArray[i],acroList) == true) { wordArray[i] = wordArray[i].toUpperCase(); }
		
		// make first letter uppercase
		newWord += wordArray[i].substr(0,1).toUpperCase() + wordArray[i].substr(1);

		
		// add spaces in between words
		if(i+1 != wordArray.length)
		{
			newWord += " ";
		}
	}

	return newWord;
}

function isAcronym(word,acronyms) {
	
	// checks incoming word against list of known Acronyms
	// incoming word, from the URL, is most likely lowercase
	
	var isAcro = false;
	
	for(var i=0; i<acronyms.length; i++) {
		
		//looks for disinct acronyms, i.e. looking for CASE returns true for CASE, false for CAS, false for CASES
		if(word.match(acronyms[i]) != null && acronyms[i].match(word) != null) { isAcro = true; }
	
	}
	
	return isAcro;
}

function hasIndex(path) {
	
	var isIndex = true;
	
	// checks for negative case (if .html file exists, but is not named index)
	if( path.match(".html") != null && path.match("index.html") == null ) { isIndex = false; }
	else if( path.match(".php") != null && path.match("index.php") == null ) { isIndex = false; }
	
	return isIndex;
}

function depthOf(path) {
	
	var depth; // depth of file, i.e. '/provost/faculty/index.html' = depth of 2
	
	depth = path.split("/").length-2; // -2 accounts for folder before root and file after path
	
	return depth;
}

function BuildSideNavProvost(fn,titles,root) {

	// this function basically builds the sidenav bar in
	// multiple pages within a second level site
	
	// Within the sidenav the current page will be bold, gray and not linked
	// All other pages in side nav will be linked
	
	// fn is an array of URLs for the site
	// titles is an array of titles for the site
	// path is the directory path for the site
	// all three of these are passed from second level pages
	// and the arrays are specified in sitedata.html in the second
	// level site
	
	// need line feed on side nav to create some space
	// this should probably be in second level html doc
	// rather than in Javascript function
	
	document.write('<br />'); 
	
	var path = window.location.pathname;
	var sideNav; // sideNav directory
	var title; // sideNav title
	
	
	for (var j=0; j<fn.length; j++) {
		
		sideNav = fn[j];
		title = titles[j];

		// found match in sideNav
		// first condition checks if path is in root
		// second condition checks if path is a child of a sideNav element
		// Note: root is in sideNav, but there are no conditions to check the path against,
		// 		 therefore this conditional is broken up into two pieces
		if ( (depthOf(path) == 1 && j == 0) || (path.match(sideNav) != null && j != 0) ) {

			// currentDir matches current directory in array
			// so just write document title with no link
			document.write('<p class="currentmenu"><a href="'+dp+fn[j]+'">' + title + '</a></p>');		
		}
		// No match so write document title and link to document
		else {
			
			// outgoing link in sideNav
			if(fn[j].match("http://")) {
				document.write('<p><a href="' + sideNav + '">' + title + '</a></p>');
			}
			// regular link
			else {
				document.write('<p><a href="' + root+sideNav + '">' + title + '</a></p>');
			}
			
		}
	}   // end for loop

   document.write("<img height='10' src='/graphics/transparent.gif' alt='' width='1' />");
   document.write("<img height='1' src='/graphics/small_black_line_horz.gif' alt='' width='100' />");

}  // end BuildSideNavProvost function

// -->