/*
	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 = "/en/";
	// 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


//despre 
breadCrumbLabels["/en/despre/misiune/misiune.html"] = "Mission";
breadCrumbLabels["/en/despre/misiune/multicultural.html"] = "Multicultural character";
breadCrumbLabels["/en/despre/misiune/mesaj-presedinte.html"] = "President's message";
breadCrumbLabels["/en/despre/misiune/mesaj-rector.html"] = "Rector's message ";
breadCrumbLabels["/en/despre/misiune/istoric.html"] = "History";
breadCrumbLabels["/en/despre/organizare/rectorat.html"] = "Rector's Office";
breadCrumbLabels["/en/despre/organizare/cons-acad.html"] = "Academic Council";
breadCrumbLabels["/en/despre/organizare/senat.html"] = "Senate";
breadCrumbLabels["/en/despre/organizare/secretariat.html"] = "General Secretariate";
breadCrumbLabels["/en/despre/organizare/infrastructura.html"] = "Infrastructure";
breadCrumbLabels["/en/despre/organizare/structura.html"] = "Organisational structure";

breadCrumbLabels["/en/despre/publice/carta.html"] = "UBB Charter";
breadCrumbLabels["/en/despre/strategii/qa.html"] = "Quality Assurance";
breadCrumbLabels["/en/despre/publice/cod-etic.html"] = "Ethical Code";
breadCrumbLabels["/en/despre/publice/acte_normative.html"] = "Legislation";
breadCrumbLabels["/en/despre/publice/surse_financiare.html"] = "Financial Resources";
breadCrumbLabels["/en/despre/organizare/administratie.php"] = "Administration";
breadCrumbLabels["/en/despre/strategii/po.html"] = "Operational plan";
breadCrumbLabels["/en/despre/strategii/plan-strategic.html"] = "Strategic plan";
breadCrumbLabels["/en/despre/strategii/pl.html"] = "Linguistic policy";
breadCrumbLabels["/en/despre/info/posturi_didactice.html"] = "Vacanct Positions";





// specific labels
breadCrumbLabels["/"] = "Home";
breadCrumbLabels["/en/"] = "Home";
breadCrumbLabels["/en/despre/"] = "About UBB";
breadCrumbLabels["/en/despre/misiune/"] = "Mission";
breadCrumbLabels["/en/despre/organizare/"] = "Organization";
breadCrumbLabels["/en/despre/strategii/"] = "Programmes and Strategies";
breadCrumbLabels["/en/despre/info/"] = "Information-INFOUBB";
breadCrumbLabels["/en/despre/publice/"] = "Public documents";

//structura
breadCrumbLabels["/en/structura/"] = "Structure";
breadCrumbLabels["/en/structura/facultati/"] = "Faculties";
breadCrumbLabels["/en/structura/extensii_academice/"] = "Academic extensions";
breadCrumbLabels["/en/structura/unitati_cercetare/"] = "Research Units";

breadCrumbLabels["/en/structura/unitati_cercetare/cercetare_fundamentala.html"] = "Units for Fundamental Research";
breadCrumbLabels["/en/structura/unitati_cercetare/consiliere.html"] = "Units for Counselling and Labour Force Development";
breadCrumbLabels["/en/structura/unitati_cercetare/consultanta-politic.html"] = "Consultancy Providers in the Political, Social and Juridical Field ";
breadCrumbLabels["/en/structura/unitati_cercetare/consultanta-economic.html"] = "Consultancy Providers in the Economic-Administrative Field";
breadCrumbLabels["/en/structura/unitati_cercetare/cercetare-valorificare.html"] = "Units for Capitalization of Scientific Research with Technological Impact";
breadCrumbLabels["/en/structura/unitati_cercetare/cultura.html"] = "Culture Promoting";

breadCrumbLabels["/en/structura/centre_culturale/"] = "Foreign Cultural Centres";
breadCrumbLabels["/en/structura/centre_limbi_moderne/"] = "Centres for Modern Languages";
breadCrumbLabels["/en/structura/centre_limbi_moderne/centrul_alpha.html"] = "ALPHA Centre";
breadCrumbLabels["/en/structura/centre_limbi_moderne/centrul_lingua.html"] = "LINGUA Centre";
breadCrumbLabels["/en/structura/facilitati/"] = "Facilities";

breadCrumbLabels["/en/structura/biblioteci/"] = "Libraries";
breadCrumbLabels["/en/structura/biblioteci/biblioteci.html"] = "Libraries";
breadCrumbLabels["/en/structura/biblioteci/be.html"] = "Electronic libraries";

breadCrumbLabels["/en/structura/sport/"] = "Sports and Leisure Time";
breadCrumbLabels["/en/structura/sport/botanica.html"] = "The Alexandru Borza Botanical Garden";
breadCrumbLabels["/en/structura/sport/parc.html"] = "Prof. PhD Iuliu Hatieganu University Sports Park";
breadCrumbLabels["/en/structura/sport/observator.html"] = "Astronomical Observatory";
breadCrumbLabels["/en/structura/sport/arcalia.html"] = "Arcalia Centre";
breadCrumbLabels["/en/structura/sport/belis.html"] = "Belis Resort";
breadCrumbLabels["/en/structura/sport/bazin.html"] = "Complexul de Natatie";
breadCrumbLabels["/en/structura/sport/baru_mare.html"] = "Baru-Mare Resort";


breadCrumbLabels["/en/structura/muzee/"] = "Museums";
breadCrumbLabels["/en/structura/muzee/muzeul_univ.html"] = "University Museum";
breadCrumbLabels["/en/structura/muzee/muzeul_mineralogic.html"] = "Museum of Mineralogy";
breadCrumbLabels["/en/structura/muzee/muzeul_botanic.html"] = "Botanical Museum";
breadCrumbLabels["/en/structura/muzee/muzeul_paleo.html"] = "Paleontology-Stratigraphy Museum";
breadCrumbLabels["/en/structura/muzee/muzeul_vivariu.html"] = "Vivarium";
breadCrumbLabels["/en/structura/muzee/muzeul_zoologic.html"] = "Zoological Museum";

breadCrumbLabels["/en/structura/publicatii/"] = "Publishing and Distribution";
breadCrumbLabels["/en/structura/publicatii/edituri.html"] = "Publishing and distribution";
breadCrumbLabels["/en/structura/publicatii/reviste.html"] = "Scientific Journals";
breadCrumbLabels["/en/structura/publicatii/libraria_ubb.html"] = "University Book Store";

//programe academice
breadCrumbLabels["/en/programe_academice/"] = "Academic programmes";

breadCrumbLabels["/en/programe_academice/licenta/licenta_specializari.html"] = "Bachelor";
breadCrumbLabels["/en/programe_academice/licenta/licenta_specializari.html"] = "Bachelor's Degree Programmes";
breadCrumbLabels["/en/programe_academice/licenta/licenta_documente.html"] = "Documents";

breadCrumbLabels["/en/programe_academice/masterat/masterat_specializari.html"] = "Masters";
breadCrumbLabels["/en/programe_academice/masterat/masterat_specializari.html"] = "Master's Degree Programmes";
breadCrumbLabels["/en/programe_academice/masterat/masterat_documente.html"] = "Documents";

breadCrumbLabels["/en/programe_academice/scoli_vara/"] = "Summer Schools";
breadCrumbLabels["/en/programe_academice/pregatirea_cadrelor/"] = "Teaching Staff Professional Training";


breadCrumbLabels["/en/studenti/"] = "Students";

breadCrumbLabels["/en/studenti/invatamant/"] = "Education";
breadCrumbLabels["/en/studenti/invatamant/sistem_inv.html"] = "Romanian educational system";
breadCrumbLabels["/en/studenti/invatamant/ects.html"] = "ECTS regulation";
breadCrumbLabels["/en/studenti/invatamant/formulare.html"] = "Contracts";
breadCrumbLabels["/en/studenti/invatamant/bologna.html"] = "Procesul Bologna";

breadCrumbLabels["/en/studenti/burse/index.html"] = "Scholarships";
breadCrumbLabels["/en/studenti/burse/regulament_burse.html"] = "Scholarship Regulation";
breadCrumbLabels["/en/studenti/burse/oferta_burse.html"] = "Scholarships";

breadCrumbLabels["/en/studenti/taxe/"] = "Fees";
breadCrumbLabels["/en/studenti/taxe/taxe_licenta.html"] = "Bachelor Tuition Fees";
breadCrumbLabels["/en/studenti/taxe/taxe_master.html"] = "Master Tuition Fees";
breadCrumbLabels["/en/studenti/taxe/taxe_doctorat.html"] = "Doctoral Tuition Fees";
breadCrumbLabels["/en/studenti/taxe/taxe_universitare.html"] = "University Fees";
breadCrumbLabels["/en/studenti/taxe/regulamente.html"] = "Tuition Fees Regulation";

breadCrumbLabels["/en/studenti/campus/"] = "Campus";
breadCrumbLabels["/en/studenti/campus/camine.html"] = "Student Housing";
breadCrumbLabels["/en/studenti/campus/tarife.html"] = "Accommodation fees";
breadCrumbLabels["/en/studenti/campus/reg_cazare.html"] = "Accomodation Regulations";


breadCrumbLabels["/en/studenti/tutoriat/"] = "Tutoring in UBB";
breadCrumbLabels["/en/studenti/tutoriat/conceptul/"] = "The concept";
breadCrumbLabels["/en/studenti/tutoriat/beneficiarii/"] = "Students - tutoring beneficiaries";
breadCrumbLabels["/en/studenti/tutoriat/sistemul/"] = "Tutoring System";
breadCrumbLabels["/en/studenti/tutoriat/programul/"] = "Tutoring Programme";
breadCrumbLabels["/en/studenti/tutoriat/calitatea/"] = "Being a tutor";
breadCrumbLabels["/en/studenti/tutoriat/remuneratia/"] = "Rates of pay for tutors";

breadCrumbLabels["/en/studenti/facilitati_it/"] = "IT Facilities";

breadCrumbLabels["/en/studenti/viata_cultural_sportiva/"] = "Sports, Arts and Entertainment";
breadCrumbLabels["/en/studenti/viata_cultural_sportiva/culturala.html"] = "Culture";
breadCrumbLabels["/en/studenti/viata_cultural_sportiva/sportiva.html"] = "Sports";

breadCrumbLabels["/en/studenti/organizatii/"] = "Student Associations";


//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
