document.locus = locus;
document.locus.set = setLocus;
document.locus.dictionary = dictionary;
document.locus.iniziale = new Array();
document.locus.finale = new Array();

function locus() //ver 2.1 by marco
{
	var homePage = document.locus.homePage ? document.locus.homePage : "home";
	var homeIndex = document.locus.homeIndex ? document.locus.homeIndex : "index.php";
	var dirIndex = document.locus.dirIndex ? document.locus.dirIndex : "index.php";
	var separator = document.locus.separator ? document.locus.separator : " / ";
	var linkAttrib = document.locus.linkAttrib ? document.locus.linkAttrib : "";
	var textAttrib = document.locus.textAttrib ? document.locus.textAttrib : "";
	var begin = document.locus.begin ? document.locus.begin : "";
	var end = document.locus.end ? document.locus.end : "";
	var levels = new Array();
	var dirUp = "../";
	var backTmp = "";
	var navBar = "";
	var isIndex = 0;
	var url = document.httpUtl.getPagePath().replace(/\\/g,"/");
	
	if ( ( url == "/" + dirIndex ) || ( url == "/" ) || (!url) ) return //esce se la pagina attuale č l'indice del sito
	
	//rimuove l'url della pagina dalla stringa
		url = url.substr(1, url.lastIndexOf("/") - 1);
		
	//elimina gli underscore
	url = url.replace(/_/g," ");
	
	//effettua le sostituzioni del dizionario, se presenti
	if (document.locus.iniziale.length > 0)
		for (q = 0; q <= document.locus.iniziale.length; q ++ )
			url = url.replace(document.locus.iniziale[q], document.locus.finale[q])
	
	
	//se la pagina visualizzata č un directory index il flag viene impostato a true
	isIndex = document.location.pathname.replace(url, "").indexOf(dirIndex) != -1 ? 1 : 0
		
	//aggiunge il livello zero: la root
	url = url.length > 0 ? homePage + "/" + url : homePage;
	
	//scompone l'url nelle singole directory
	levels = url.split("/")
	
	for (q = 0; q < levels.length - isIndex; q ++)
		{
		backTmp = "";
		for (i = levels.length - 1; i > q; i --)
			backTmp += dirUp;
			levels[q] = levels[q].link(backTmp + ( q == 0 ? homeIndex : dirIndex))
		}
	
	navBar = levels.join(separator);
	
	if (linkAttrib.length > 0) 
		navBar = navBar.replace(/<A/g, "<A " + linkAttrib + " ");
		
	if (textAttrib.length > 0) 
		navBar = "<span " + textAttrib +" >" + navBar + "</span>";
	
	document.writeln ( begin + navBar + end )
}

function setLocus(param, value) //ver 1.0 by marco
{
	var allowedParam = /homeIndex|homePage|dirIndex|separator|linkAttrib|textAttrib|begin|end/;
	if (!allowedParam.test(param)) return;
	eval("document.locus." + param + "=\"" + value +"\"");
}

function dictionary(iniziale, finale)
{
	if (!iniziale && !finale) return;
	
	document.locus.iniziale[document.locus.iniziale.length] = iniziale;
	document.locus.finale[document.locus.finale.length] = finale;
}

//****************************************************************************************************************
//oggetto di gestione dell'url
function httpUtl(rootDir)
{
	//(private)
	var url = document.location;
	var host = document.location.host;
	var path = document.location.pathname;
	var query = document.location.search;
	var root = rootDir;
	
	//metodi pubblici
	this.getUrl = function (absoluteServerPath) //restituisce un url relativo alla root del server o il percorso completo di una cartella
	{
		var folder;
		
		if (!host)
		{
			folder = path.substring(0, path.indexOf(root) + root.length);
			return folder + absoluteServerPath
		}
		else return absoluteServerPath;
	}
	
	this.getPagePath = function() //restituisce il path della pagina dalla root del server in gių, o dalla cartella di lavoro in gių
	{
		if (!host)
			return path.substring(path.indexOf(root) + root.length);
		else 
			return document.location.pathname;
	}
		 
}

document.httpUtl = new httpUtl("www.smparquet.com"); //nome della cartella locale

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