FSite2.Location = function (url)
{
	this.href = url;
	this.parse();
}

FSite2.Location.prototype.replace = function (url)
{
	this.href = url;
	this.parse();
}

FSite2.Location.prototype.parse = function ()
{
	var results;
	
	if (this.href)
	{
		var reg = new RegExp    ('^((http[s]?|ftp):\/\/)?(([^:\/]+)|(([^:\/]+):([0-9]+)))?((\/[^?#]*)(\\?[^#]*)?(#.*)?)?$', 'g');
		results=reg.exec(this.href);
		this.protocol = (results[2])?results[2]:'';
		this.host = (results[3])?results[3]:'';
		this.hostname = (results[4])?results[4]:((results[6])?results[6]:'');
		this.port = (results[7])?results[7]:'';
		this.pathname = (results[9])?results[9]:'';
		this.search = (results[10])?results[10]:'';
		this.hash = (results[11])?results[11]:'';
		return true;
	}
	this.protocol = '';
	this.host = '';
	this.hostname = '';
	this.port = '';
	this.pathname = '';
	this.search = '';
	this.hash = '';
	return false
}

FSite2.Location.prototype.toString = function()
{
	var url='';
	if (this.protocol && this.host)
		url+=this.protocol+'://'+this.host;
	if (this.pathname)
		url+=this.pathname;
	if (this.search)
		url+=this.search;
	if (this.hash)
		url+=this.hash;
	return url;
}

FSite2.proccessHrefParams = function (anchorElement)
{
	var locationHref = new FSite2.Location(anchorElement.href);
	var hashHref = locationHref.hash
	locationHref.hash=null;
	var locationWindow = new FSite2.Location(window.location.toString());
	locationWindow.hash=null;
	if (locationHref.toString() == locationWindow.toString())
	{
		document._FSite2Hash=hashHref.substr(1);
		FSite2.proccessHashParams();
		return false;
	}
	return true;
}

FSite2.proccessHashParams = function ()
{
	if (document._FSite2Hash==null)
		document._FSite2Hash = window.location.hash.toString().substr(1);
	var hash = document._FSite2Hash;
	var newHash;
	if (hash.length>=2)
	{
		var steepHash = hash.split(',');
		var hrefHash;
		if (!(hrefHash = document.getElementById(steepHash[0])))
			return true;
		if (steepHash.length>1)
		{
			var newSteep=new Array();
			for (var i=1; i<steepHash.length; i++)
				newSteep[i-1]=steepHash[i];
			newHash=newSteep.join(',');
		}
		else
		{
			newHash='';
		}
		document._FSite2Hash = newHash;
		if (hrefHash.rel)
		{
			var container = document.getElementById(hrefHash.rel);
			if (container && (container.style.display!='none') && (container.style.visibility!='hidden'))
			{
				FSite2.proccessHashParams();
				return false;
			}
		}
		hrefHash.onclick();
		return false;
	}
}
