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]:'';
		this.port = (results[6])?results[6]:'';
		this.pathname = (results[8])?results[8]:'';
		this.search = (results[9])?results[9]:'';
		this.parameters = new Object();
		var tempArray = this.search.replace(/\?/, '').split('&');
		var i;
		for (i = 0; i < tempArray.length; i++)
		{
			if (tempArray[i])
			{
				var tempValue = tempArray[i].split('=');
				this.parameters[tempValue[0]] = tempValue[1];
			}
		}
		this.hash = (results[10])?results[10]:'';
		return true;
	}
	this.protocol = '';
	this.host = '';
	this.hostname = '';
	this.port = '';
	this.pathname = '';
	this.search = '';
	this.hash = '';
	return false
}

FSite2.Location.prototype.appendParams = function(params)
{
	if (typeof(params) != 'object')
	{
		this.search += (this.search?'&':'?') + params;
		return true;
	}
	for (var key in params)
	{
		this.parameters[key] = params[key];
		this.search += (this.search?'&':'?') + encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
	}
	return true;
}

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;
	}
}

FSite2.processHashParams = FSite2.proccessHashParams;

