// Initialize acronyms to be uppercased
var acronyms = ['it','nyuci','hrwc','nyuccc','tabs','cbh','cec','ent','id','nycpcc','va','pgt','iem'];

// Put them in a simulated hash table for fast lookup
for (var i = 0; i < acronyms.length; i++) {
    acronyms[acronyms[i]] = acronyms[i];
}

function breadCrumbs(separator, cStyle, tStyle, dStyle) {
	// Ignore the filename in the URL
	var path = location.pathname.replace(/(^\/.*\/)(.*$)/, '$1');
	var dtS = document.title.toString();
	var tArr;

	// Remove leading/trailing slashes from the path for proper splitting
	path = path.replace(/^\/(.*?)\/$/, '$1');

	var subdirArray = path.split('/');

	for (i = 0; i < subdirArray.length; i++) {
		var dirname = subdirArray[i];

		if (acronyms[dirname] == dirname ) {
			dirname = dirname.toUpperCase();
		}

		dirname = titleCase(unescape(dirname));
		dirname = dirname.replace("Emergency","Emergency Medicine");
		dirname = dirname.replace("Ortho","> Emergency Orthopedics");
		
		var fullpath = '/';
		for (j = 0; j <= i; j++) {
			fullpath += subdirArray[j] + '/';
		}

		if (i < 1) {
			document.write('<a href="' + fullpath + '" class="' + cStyle + '">' + dirname +
			'</a>  ' + '<span class="' + dStyle + '">' + separator + '</span> ');
		} else {
			document.write('<a href="' + fullpath + '" class="' + cStyle + '">' + dirname +
			'</a>  ' + '<span class="' + dStyle + '"></span> ');
		}
    }
	
	/*if (dtS.indexOf(" | ") > -1) {
	tArr = dtS.split(" | ");
		document.write('<span class="' + tStyle + '">' + tArr[0] + '</span>');
	} else {
		document.write('<span class="' + tStyle + '">' + dtS + '</span>');

	}*/
}

function titleCase(a) {
	g = a.split(' ');
	for (l = 0; l < g.length; l++) {
		g[l] = g[l].toUpperCase().slice(0, 1) + g[l].slice(1);
	}
	return g.join(' ');
}

// Call code to display breadcrumbs
breadCrumbs('>','breadcrumbslink','breadcrumbs','breadcrumbs');
