function initLinks()
{

	var links = $$('a');
	
	var host = location.hostname;
	
	for(var i=0; i < links.length; i++)
	{
		if (links[i].href == undefined || links[i].href == "") {		continue;	}
		if (links[i].target == "_blank") { continue; }
		if (links[i].href.substr(links[i].href.lastIndexOf('.') + 1, 3) != "php") { continue; }
		
		if (links[i].href.substr(0,1) != "/" && links[i].href.substr(7, host.length) != host) { continue; }

		links[i].observe('click', handleClick);
	}
}

function handleClick(event)
{
	if (!Event.isLeftClick(event))
	{
		return false;
	}
	
	var repl = "http:\/\/" + location.hostname;
	dhtmlHistory.add(this.href.replace(repl, ""), null);
	
	
	goTo(this.href);
	Event.stop(event);
}

var linkListener = function(newLocation, historyData) 
{
	var url = newLocation;

	if (url == "" && location.href == "http://" + location.hostname + "/")
	{
		return;
	}
	
	
	goTo(url, historyData);
}

function goTo(href)
{
//	if (historyData == null)
//	{
	new Ajax.Request(href, {
		method:'post',
		parameters: {"ajax": 1},
		evalJSON: false,
		sanitizeJSON: false,
		encoding: "utf-8",
		onSuccess: function(response) {

			var data = response.responseText.evalJSON(true);
			
			$('navbox').update(data['nav']);
			$('contentbox').update(data['content']);			

			initLinks();
			$$('body')[0].scrollTo();
		}
	});
/*	}
	else
	{
		$('navbox').update(historyData['nav']);
		$('contentbox').update(historyData['content']);			
		$$('body')[0].scrollTo();
	}*/
}
