/*

	functions to handle the collection and output of breadcrumbs

*/

var bcDelim = "|";


function doBreadcrumbs(title, count, path) {
	// get (or initialise) the breadcrumbs Array
  var name = "breadcrumbs";
  if (path != '' && path != ' ') {
    name = name + "-" + path.substring(path.indexOf('/') + 1);
  }  
	var bc = new cookieObject(name, null, path);
	// do not try to display more breadcrumbs than there are
	if (count > bc.fields.length) count = bc.fields.length;
	// output 'count' breadcrumbs
	for (var i = count; i > 0; i--) {
		var bctext = bc.fields[bc.fields.length - i];
		// separate the URL from the Title
		var idx = bctext.indexOf(bcDelim);
    var link = bctext.substring(0, idx);
    var desc = bctext.substring(idx + 1);
    // output a link
    document.write("<a href='" + link + "' class='breadcrumb'>" + desc + "</a>");
	}
	// add the current page to the breadcrumbs
	var last = bc.fields[bc.fields.length - 1];
	var next = document.location.href + bcDelim + title;
	// do not add a breadcrumb if the page has been reloaded
	if (next != last) {
		bc.fields[bc.fields.length] = next;
		bc.write();
	}
}
