var currentURL = location.href;
var folders = currentURL.split("/");
var page = folders[folders.length-1];

function breadcrumb() {
	var projectsSections = new Array(
		"current",
		"commercial",
		"interiors",
		"residential",
		"retail",
		"agedcare",
		"tourism",
		"heritage",
		"urbandevelopment",
		"designadvisory",
		"infrastructure",
		"community",
		"education",
		"institutional",
		"transport"
	);
	
	var projectSectionsTitle = new Array(
		"Current",
		"Commercial Architecture",
		"Workplace Interiors",
		"Residential, Housing &amp; Mixed Use", 
		"Retail",
		"Health &amp; Aged Care",
		"Tourism, Leisure &amp; Hospitality",
		"Heritage, Conservation &amp; Refurbishment",
		"Urban Design &amp; Masterplanning",
		"Design Advisory",
		"Infrastructure",
		"Community &amp; Cultural",
		"Education &amp; Training",
		"Institutional &amp; Justice",
		"Transport &amp; Infrastructure"
	);
	
	var newsMatch = /news/.test(page);
	
	if ($("#navigation ul li:eq(2)").hasClass("selectedPageRoot") == true) {
		// If you are in the Projects section, loop through sections to check which landing page you are at.
		for (var i=0; i<projectsSections.length; i++) {
			// When there is a match, add breadcrumb with appropriate heading
			if (page == projectsSections[i]) {
				$("#breadcrumb").html("<h2><a href='/projects'>Projects</a><span class='arrow'>&gt;</span><a href='/" + projectsSections[i] + "'>" + projectSectionsTitle[i] + "</a></h2>");
			}
		}
	}
	else {
		for (var i=0; i<projectsSections.length; i++) {
			if ($("#navigation ul li.hasChildren").hasClass("selectedPageRoot") == true && page != projectsSections[i]) {
				$("#breadcrumb").html("<h2><a href='" + $(".mainNav li.selectedPageRoot a").attr("href") + "'>" + $(".mainNav li.selectedPageRoot a").text() + "</a></h2>");
			}
			else {
				/*if (page != "contact" && newsMatch == false && page != "subscribe" && page != "privacy" && page != "staff") {*/
				if ($("body").hasClass("noSubMenu") == false && newsMatch == false) {
					$("#breadcrumb").html("<h2><a href='" + $(".mainNav li.selectedPage a").attr("href") + "'>" + $(".mainNav li.selectedPage a").text() + "</a></h2>");	
				}
			}
		}
	}
}
