/*
	BreadCrumbs.js
	Errol Sayre
	esayre@olemiss.edu
	
	Provided by the Office of Research and Sponsored Programs
	The University of Mississippi
	
	This script is free to be used but provides no warranty of function or quality.
*/

// BreadCrumb configuration
// set up the site prefix
var sitePrefix = "/";
	// Please note that we don't use the whole prefix, just the important
	//	part that we need for the server so as to make this script easy for
	//	us to migrate between testing and live server. You can use whatever you
	//	like here.

// set up the bread crumb separator text
var breadCrumbSeparator = ">";

// set up our list of crumb items
	// The bread crumb items refer to items on your site that require special
	//	labels. You can specify a label specifically using the URI of the
	//	file/folder or generically for all occurences of a file/folder.
var breadCrumbLabels = new Array();
// generic labels



//informatii generale
breadCrumbLabels["info.php"] = "Prezentare generala";
breadCrumbLabels["istoric.php"] = "Istoricul facultatii";
breadCrumbLabels["baza-mat.php"] = "Baza materiala";
breadCrumbLabels["album.php"] = "Album foto";
breadCrumbLabels["sali-curs.php"] = "Sali de curs";
breadCrumbLabels["biblioteci.php"] = "Bibliotecile facultatii";


//structura
breadCrumbLabels["structura.php"] = "Prezentare";
breadCrumbLabels["pers-did-aux.php"] = "Personal didactic auxiliar";
breadCrumbLabels["/structura/pers/"] = "Personal FSE";
breadCrumbLabels["/structura/consiliul-profesoral.php"] = "Consiliul profesoral";
breadCrumbLabels["biroul-cp.php"] = "Biroul consiliului profesoral";
breadCrumbLabels["catedre.php"] = "Catedre";
breadCrumbLabels["catedre-se.php"] = "Catedra de Studii Europene";
breadCrumbLabels["catedre-mie.php"] = "Catedra de Managementul Institutiilor  Europene";
breadCrumbLabels["catedre-ri.php"] = "Catedra de Relatii Internationale";
breadCrumbLabels["catedre-sa.php"] = "Catedra de Studii Americane";


breadCrumbLabels["Bogdan_Muresan.php"] = "Muresan Bogdan";
breadCrumbLabels["Ieronim_Procopet.php"] = "Ieronim Procopet";


//oferta de studii
breadCrumbLabels["doctorat.php"] = "Doctorat";
breadCrumbLabels["/linii/licenta/rise.php"] = "Licenta RISE";
breadCrumbLabels["/linii/licenta/riseg.php"] = "Licenta RISE linia germana";
breadCrumbLabels["/linii/licenta/mie.php"] = "Licenta MIE";
breadCrumbLabels["/linii/licenta/sa.php"] = "Licenta Studii Americane";
breadCrumbLabels["/linii/licenta/ae.php"] = "Licenta AE";
breadCrumbLabels["/linii/licenta/dubla-diploma.php"] = "Dubla Diploma";
breadCrumbLabels["/linii/masterat/studii-europene-comparate.php"] = "Studii Europene Comparate";
breadCrumbLabels["/linii/masterat/studii-germane.php"] = "Studii Germane";
breadCrumbLabels["/linii/masterat/studii-americane.php"] = "Studii Americane";
breadCrumbLabels["/linii/masterat/management.php"] = "Management Performant";
breadCrumbLabels["/linii/masterat/management-educational.php"] = "Management Educational";
breadCrumbLabels["/linii/masterat/afaceri-europene.php"] = "Afaceri Europene si Management de Programe";
breadCrumbLabels["/linii/masterat/studii-multiculturale.php"] = "Studii Multiculturale";
breadCrumbLabels["/linii/masterat/dezvoltare-durabila.php"] = "Strategia europeana a dezvoltarii durabile";
breadCrumbLabels["/linii/masterat/stiinta-religie.php"] = "Stiinta si Religie";
breadCrumbLabels["/linii/masterat/societatea-mediatica.php"] = "Societatea Mediatica";
breadCrumbLabels["/linii/masterat/studii-americane.php"] = "Studii Americane";
breadCrumbLabels["/linii/masterat/dezvoltare-regionala.php"] = "Regionalism si dezvoltare regionala";


// specific labels
breadCrumbLabels["/"] = "Home";
breadCrumbLabels["/info/"] = "Informatii";
breadCrumbLabels["/linii/"] = "Programe studii";
breadCrumbLabels["/rel-int/"] = "Relatii internationale";



//admitere
breadCrumbLabels["admitere.php"] = "Admitere";
breadCrumbLabels["chestionar.php"] = "Chestionar";
breadCrumbLabels["admitere-licenta.php"] = "Admitere nivel Licenta";
breadCrumbLabels["admitere-master.php"] = "Admitere nivel Master";
breadCrumbLabels["cariera.php"] = "Cariera";
breadCrumbLabels["criterii.php"] = "Criterii de admitere";
breadCrumbLabels["locuri.php"] = "Locuri";
breadCrumbLabels["/admitere/taxe.php"] = "Taxe admitere";
breadCrumbLabels["desfasurare.php"] = "Desfasurarea admiterii";
breadCrumbLabels["/admitere/rezultate.php"] = "Rezultate";
breadCrumbLabels["/admitere/rezultate2008.php"] = "Rezultate Admitere 2008";
breadCrumbLabels["confirmare.php"] = "Confirmarea";
breadCrumbLabels["redistribuiri.php"] = "Redistribuiri";
breadCrumbLabels["contestatii.php"] = "Contestatii";
breadCrumbLabels["redistribuiri.php"] = "Redistribuiri";


//Studenti
breadCrumbLabels["/studenti/studenti.php"] = "Studenti";
breadCrumbLabels["/studenti/orar.php"] = "Orar";
breadCrumbLabels["/studenti/regulamente.php"] = "Regulamente";
breadCrumbLabels["/studenti/licenta.php"] = "Informatii licenta";
breadCrumbLabels["/studenti/practica.php"] = "Practica";
breadCrumbLabels["/studenti/burse.php"] = "Burse";
breadCrumbLabels["/studenti/contracte.php"] = "Contracte de studii";
breadCrumbLabels["/studenti/fise.php"] = "Fise de inscriere ";
breadCrumbLabels["/studenti/taxe.php"] = "Taxe";
breadCrumbLabels["/studenti/cazare.php"] = "Cazari/camine";


// rel-internationale
breadCrumbLabels["/rel-int/rel-int.php"] = "Relatii internationale";
breadCrumbLabels["/rel-int/tempus.php"] = "Programul Tempus";
breadCrumbLabels["/rel-int/erasmus.php"] = "Programul Erasmus";
breadCrumbLabels["/rel-int/progr-ea.php"] = "Programul European Affairs";
breadCrumbLabels["/rel-int/honoris.php"] = "Doctor Honoris Causa";


//cercetare

breadCrumbLabels["/cercetare/cercetare.php"] = "Cercetare";
breadCrumbLabels["/cercetare/conferinte.php"] = "Conferinte";
breadCrumbLabels["/cercetare/evenimente.php"] = "Evenimente";
breadCrumbLabels["/cercetare/lansare_carte.php"] = "Lansare de carte";
breadCrumbLabels["/cercetare/reuniuni.php"] = "Reuniuni stiintifice";
breadCrumbLabels["/cercetare/publicatii.php"] = "Publicatii";
breadCrumbLabels["/cercetare/fundatia-ie.php"] = "Fundatia 'Ideea Europeana'";
breadCrumbLabels["/cercetare/institute-cercetare.php"] = "Institute de cercetare";


//alumni
breadCrumbLabels["/alumni/alumni.php"] = "Alumni";



//breadCrumbLabels["images/"] = "Images Folder";

function displayBreadCrumbs(attempts)
{
	// locate the breadcrumb container
	var theBreadCrumbBar = null;
	if (document.all)
	{
		theBreadCrumbBar = document.all.BreadCrumbBar;
	}
	else
	{
		theBreadCrumbBar = document.getElementById("BreadCrumbBar");
	}
	
	// check to make sure that we have our breadcrumb bar
	if (theBreadCrumbBar != null)
	{
		// get the current url
		// we'll want to ensure that we get the start of our site so, we'll
		//	ignore everything up to and including our site prefix
		var thePath = location.href;
		var theProtocol = "";
		var theSite = "";
		
		// strip out the protocol from the path
		theProtocol = thePath.substring(0, thePath.indexOf("://") + 3);
		thePath = thePath.substring(thePath.indexOf("://") + 3);
		
		// strip out the site name
		theSite = thePath.substring(0, thePath.indexOf(sitePrefix));
		thePath = thePath.substring(thePath.indexOf(sitePrefix));
		
		// strip out the site prefix
		thePath = thePath.substring(thePath.indexOf(sitePrefix) + sitePrefix.length);
		
		// remove hash links
		var theHash = "";
		if (thePath.indexOf("#") > -1)
		{
			theHash = thePath.substring(thePath.indexOf("#"));
			thePath = thePath.substring(0, thePath.indexOf("#"));
		}
		
		// break out the individual pieces of the location
		var crumbs = thePath.split("/");
		var currentPath = sitePrefix;
		var crumbCount = 0;
		
		// add a "home" link
		// create a bread crumb container
		var breadCrumb = document.createElement("span");
		breadCrumb.setAttribute("class", "breadCrumb");
		
		// determine the crumb label
		// first use the default
		var crumbLabel = "Home";
		
		// second look for a generic label
		if ((breadCrumbLabels[sitePrefix] != null))
		{
			crumbLabel = breadCrumbLabels[sitePrefix];
		}
		
		// third look for a specific label
		if ((breadCrumbLabels[currentPath] != null))
		{
			crumbLabel = breadCrumbLabels[currentPath];
		}
		
		// add the text
		// check to see if there are any crumbs after this one
		if ((0 < crumbs.length) &&
			(crumbs[0] != "index.html") &&
			(crumbs[0] != ""))
		{
			// create a new link
			var linkTag = document.createElement("a");
			linkTag.href = theProtocol + theSite + currentPath;
			linkTag.appendChild(document.createTextNode(crumbLabel));
			breadCrumb.appendChild(linkTag);
		}
		else
		{
			// add the text together
			breadCrumb.appendChild(document.createTextNode(crumbLabel));
		}
		theBreadCrumbBar.appendChild(breadCrumb);
		
		// increment our count of crumbs
		crumbCount++;
		
		// loop through the crumbs
		for (var crumbIndex = 0; crumbIndex < crumbs.length; crumbIndex++)
		{
			// setup the current path
			currentPath += crumbs[crumbIndex];
			if (crumbIndex + 1 < crumbs.length)
			{
				currentPath += "/";
			}
			
			if ((crumbs[crumbIndex] != "") &&
				(crumbs[crumbIndex].indexOf("index.html") == -1))
			{
				// add this crumb to the list
				// create a bread crumb container
				var breadCrumb = document.createElement("span");
				breadCrumb.setAttribute("class", "breadCrumb");
				
				// add a greater than to the left hand side
				if (crumbCount > 0)
				{
					breadCrumb.appendChild(document.createTextNode(breadCrumbSeparator));
				}
				
				// determine the crumb label
				// first use the crumb itself
				var crumbLabel = crumbs[crumbIndex].replace(/_/g, " ").replace(".html", "").capitalize();
				
				// second look for a generic label
				if ((breadCrumbLabels[crumbs[crumbIndex]] != null))
				{
					crumbLabel = breadCrumbLabels[crumbs[crumbIndex]];
				}
				
				// third look for a specific label
				if ((breadCrumbLabels[currentPath] != null))
				{
					crumbLabel = breadCrumbLabels[currentPath];
				}
				
				// add the text
				// check to see if there are any crumbs after this one
				if ((crumbIndex + 1 < crumbs.length) &&
					(crumbs[crumbIndex + 1] != "index.html") &&
					(crumbs[crumbIndex + 1] != ""))
				{
					// create a new link
					var linkTag = document.createElement("a");
					linkTag.href = theProtocol + theSite + currentPath;
					linkTag.appendChild(document.createTextNode(crumbLabel));
					breadCrumb.appendChild(linkTag);
				}
				else
				{
					// add the text together
					breadCrumb.appendChild(document.createTextNode(crumbLabel));
				}
				theBreadCrumbBar.appendChild(breadCrumb);
				
				// increment our count of crumbs
				crumbCount++;
			}
		}
	}
	else if (attempts < 5)
	{
		// try again in a few seconds
		attempts++;
		setTimeout("displayBreadCrumbs(" + attempts + ");", 100);
	}
}

// add a handy function to the string class
String.prototype.capitalize = function()
{
	return this.replace(/\w+/g, function(a)
	{
		return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
	});
};

// set us up to display bread crumbs
displayBreadCrumbs(1); // JavaScript Document
