/*
	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 = "quantumgroup.com.au";
	// 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
breadCrumbLabels["formmail_withdetails_newsletter.php"] = "Processing";
breadCrumbLabels["thankyou_newsletter.php"] = "Thank You";
breadCrumbLabels["thankyou_seminar.php"] = "Thank You";
breadCrumbLabels["thankyou_risk.php"] = "Thank You";
breadCrumbLabels["pof.php"] = "Property & Opportunity Fund";
breadCrumbLabels["foundry.php"] = "The Foundry";
breadCrumbLabels["media-archive2007.php"] = "Media Archive for 2007";
breadCrumbLabels["anti-money_laundering.php"] = "Anti-money Laundering & Counter Terrorism Financing ACT 2006";
breadCrumbLabels["fees_commisions.php"] = "Fees & Commissions";
// Labels for the download pages
breadCrumbLabels["download.php?title=Gateway%20On%20Palmer%20Property%20Syndicate%20No.%2016%20summary&image=cover_gateway_16&inc=warrants&file=quantum_16_6p&banner=gateway"] = "Gateway Summary";
breadCrumbLabels["download.php?title=Casuarina%20Property%20Syndicate%20No.%2015%20summary&image=cover_casuarina_15&inc=warrants&file=quantum_15_6p&banner=casuarina"] = "Casuarina Summary";
breadCrumbLabels["download.php?title=Property%20and%20Opportunity%20Fund%20Summary&image=cover_pofund&inc=warrants&file=quantum_pofund_6p&banner=qpof"] = "Property and Opportunity Fund Summary";
breadCrumbLabels["download.php?title=Property%20and%20Opportunity%20Fund%20PDS&image=cover_pofund&inc=warrants&file=quantum_pofund_pds&banner=qpof"] = "Download Property and Opportunity Fund PDS";
breadCrumbLabels["download.php?title=Quantum%20Warrants%206%20page%20summary&image=warrants&file=quantum_warrants_4p_02-08"] = "Quantum Warrants 6 page summary";
breadCrumbLabels["download.php?title=Quantum%20Warrants%20Tax%20Ruling&image=warrants_ruling&file=quantum_warrants_ruling"] = "Quantum Warrants Tax Ruling";
breadCrumbLabels["download.php?title=QSmart%20Security%20Issues&image=qs&file=qs_Securityissues"] = "QSmart Security Issues";
breadCrumbLabels["download.php?title=QSmart%20Client%20Manual&image=qs&file=qs_QsmartClientMannual"] = "QSmart Client Manual";
breadCrumbLabels["download.php?title=Quantum%20Warrants%20Security%20Issues%20PDF&image=qs&file=qs_Securityissues"] = "Quantum Warrants Security Issues PDF";
breadCrumbLabels["download.php?title=Quantum%20Warrants%20Client%20Manual%20PDF&image=qs&file=qs_QsmartClientMannual"] = "Quantum Warrants Client Manual PDF";
breadCrumbLabels["download.php?title=Quantum%20QSmart%206%20page%20summary&image=qsmart_6p&inc=&file=quantum_qsmart"] = "Quantum QSmart 6 page summary";

// specific labels
breadCrumbLabels["about"] = "About Us";
breadCrumbLabels["products"] = "Investment Products";
breadCrumbLabels["investors"] = "Investor Relations";
breadCrumbLabels["news"] = "Announcements";
breadCrumbLabels["qsmart"] = "QSmart";
breadCrumbLabels["downloads"] = " ";
//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.php") &&
			(crumbs[0] != "index.php"))
		{
			// 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.php") == -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(/_/g, " ").replace(".php", "").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.php") &&
					(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 < 10)
	{
		// try again in a few seconds
		attempts++;
		setTimeout("displayBreadCrumbs(" + attempts + ");", 25);
	}
}

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