/*******************************

 breadcrumbs.js, Version 1.1.1, 29-Sep-2004
 Copyright Northgate Information Solutions UK Limited, 2002-2004

 *******************************/

/*********************
 Breadcrumbs class

 Constructor:
	Breadcrumbs(helpSystem, topicFrame, targetFrame, elementId)
 Properties:
	helpSystem		A reference to the HelpSystem object.
	topicFrame		A reference to the topic frame.
	targetFrame		A reference to the frame where the breadcrumbs
						will be displayed.
	elementId		The id of the element to contain the
						breadcrumbs. Optional - default: "breadcrumbs". 
 Methods:
	insert()
 *********************/

// *** Constructor for Breadcrumbs class ***
function Breadcrumbs(helpSystem, topicFrame, targetFrame, elementId) {
	this.helpSystem = helpSystem;
	this.topicFrame = topicFrame;
	this.targetFrame = targetFrame;
	this.elementId = (!elementId ? "breadcrumbs" : elementId);
}

// *** Breadcrumbs instance methods ***
Breadcrumbs.prototype.insert = function bcrInsert() {
	var brcr;
	var brcrContent = "";
	var brcrTag = null;
	
	// Get a reference to the breadcrumbs element.
	var brcrElement = this.targetFrame.document.getElementById(this.elementId);
	
	// If there is a breadcrumbs <meta> tag...
	var metaTags = this.topicFrame.document.getElementsByTagName("meta");
	for (var i = 0; i < metaTags.length; i++) {
		if (metaTags[i].name == this.elementId) {
			brcrTag = metaTags[i];
			break;
		}
	}
	if (brcrTag) {
		// Get its content attribute.
		brcrContent = brcrTag.content;
	}

	// If there are any breadcrumbs...
	if (brcrContent) {
		// Initialise the breadcrumbs HTML and text.
		var brcrHtml = ""
		var brcrText = "";
		// Separate out the different breadcrumb levels.
		var brcrLevels = brcrContent.split(",");
		// For each breadcrumb level...
		for (var i = 0; i < brcrLevels.length; i++) {
			// Separate the name and the value.
			brcr = brcrLevels[i].split("=");
			/* The text of the breadcrumb might include a comma,
			   so if there is no equals sign, save the text and
			   try the next element. */
			brcrText += (brcrText != "" ? "," : "") + brcr[0];
			if (brcr.length > 1) {
				// Remove any trailing colon.
				brcr[1] = brcr[1].split(":")[0];
				/* If local site maps are in use, make the URL relative
				   to the location of the banner. */
				var nf = this.helpSystem.configuration.navigationFiles;
				if (nf.siteMap) {
					var url = nf.controlPath;
					url = url.pathConcat(brcr[1]);
					url = "../" + this.helpSystem.absoluteUrl(url);
					brcr[1] = url;
				}
				/* Convert the breadcrumb to a link and 
				   append it to the breadcrumbs HTML. */
				brcrHtml += (i > 0 ? " &gt; " : "") + brcrText.link(brcr[1]);
				brcrText = "";
			}
		}	// Loop.
		// Insert the breadcrumbs HTML into the banner table.
		brcrElement.innerHTML = brcrHtml;
	}	
	else {
		// Clear the breadcrumbs table cell.
		brcrElement.innerHTML = "&nbsp;";
	}	// End if
}

