/* Copyright Claude Needham gxxaxx@gmail.com All rights reserved
	Please refrain from using this script without permission.
	This is how I make my living. 
	If you would like to use the script contact me. We can work something out. 
	You can get a javascript without stealing it (I'll keep the price low).
	And I can live in a house instead of a station wagon.
*/
/*
BCRUMB:
	on inclusion in the webpage will automatically 
	1) init itself.
	2) locate an html wrapper (div, p, li, etc) in which to insert a trail of breadcrumbs
	3) if such exists it will calculate the trail of breadcrumbs and insert

Requires

1)	an object of the type
	<p id="bcrumbobj"></p>

2)	A line to load the javascript
	<script type="text/javascript" src="/ssi/xxaxxlib.js"></script>
	<script type="text/javascript" src="/ssi/bcrumbx.js"></script>

*/

// Little trick to keep variable spaces from banging together.
var oxxaxxlib = oxxaxxlib || new xxaxxlibo();

var BCrumbVars = {};

BCrumbVars.bcrumbhome = "Home"; // string used to indicate home
BCrumbVars.bcrumbsep = " / "; // string used to separate bits of the breadcrumb

BCrumbVars.crumbholderID = "bcrumbobj";	// id used to indicate the object to accept breadcrumb

// Below here is program. You should not need to alter this
BCrumbVars.objcrumbholder = null;
BCrumbVars.dochref = "";
BCrumbVars.bcrumb = "";

BCrumbVars.hrefbits = new Array();
BCrumbVars.doccrumbs = new Array();

BCrumbVars.init = function () {

	BCrumbVars.objcrumbholder = document.getElementById(BCrumbVars.crumbholderID);
	if (!(BCrumbVars.objcrumbholder)) {
		return;
	}

	BCrumbVars.dochref = document.location.href;

// for testing local	BCrumbVars.dochref = BCrumbVars.dochref.replace("file:///C:/","http://www.");

	BCrumbVars.dochref = oxxaxxlib.GrabFront("&",BCrumbVars.dochref + "&");
	BCrumbVars.dochref = oxxaxxlib.GrabFront("?",BCrumbVars.dochref + "?");

	BCrumbVars.dochref = oxxaxxlib.GrabAfter("//",BCrumbVars.dochref);
	BCrumbVars.dochref = oxxaxxlib.GrabAfter("/",BCrumbVars.dochref);
//	alert(BCrumbVars.dochref);
	while(BCrumbVars.dochref) {
		if (BCrumbVars.dochref.substring(BCrumbVars.dochref.length - 1) == "/") {
			BCrumbVars.dochref = BCrumbVars.dochref.substring(0, BCrumbVars.dochref.length - 1);
			BCrumbVars.str = oxxaxxlib.GrabFile(BCrumbVars.dochref) + "/";
		} else {
			BCrumbVars.str = oxxaxxlib.GrabFile(BCrumbVars.dochref);
		}

		BCrumbVars.doccrumbs.push( BCrumbVars.str );
		BCrumbVars.hrefbits.push("/");

		BCrumbVars.dochref = oxxaxxlib.GrabDir(BCrumbVars.dochref);
	}

	if (BCrumbVars.doccrumbs.length <= 0) {
		return;
	}

	for (i = BCrumbVars.doccrumbs.length -1; i>=0; i--) {
		for (j = 0; j <= i; j++) {
			BCrumbVars.hrefbits[j] += BCrumbVars.doccrumbs[i];
		}
	}


	BCrumbVars.bcrumb = '<a href="/">' + BCrumbVars.bcrumbhome + '</a>';
	for (i = BCrumbVars.hrefbits.length -1; i>=0; i--) {
		BCrumbVars.bcrumb  += BCrumbVars.bcrumbsep;
		tmpstr = BCrumbVars.doccrumbs[i];
		if (tmpstr.substring(tmpstr.length - 1) == "/") {
			tmpstr = tmpstr.substring(0, tmpstr.length - 1);
		}
		BCrumbVars.bcrumb  += '<a href="' + BCrumbVars.hrefbits[i]+'">' +  tmpstr + '</a>';
	}
//	alert(BCrumbVars.bcrumb);
	BCrumbVars.objcrumbholder.innerHTML = BCrumbVars.bcrumb;

}


// this is same as putting <body onload="init()"> in doc
// window.onload = init;
oxxaxxlib.addLoadEvent( BCrumbVars.init );


