function ajaxRequest(href, noLoader)
{
	if(!href) return;

	// Loader
	if(!noLoader){
		$('#content').html('Loading...');
	}
	
	$.ajax({
 		url: href,
 		dataType: "xml",
 		success: function(){
 			if(!noLoader) init('#content');
			urchinTracker(href);
 		}
	});
}

function init(container)
{
	var selector = '';
	
	selector = 'a.ajx';
	if(container) selector = container + ' ' + selector;
	$(selector).click(function(){
		//ajaxRequest($(this).attr('href'));
		$.history.load(this.href.replace(/^.*#/, ''));
		return false;
	});
	
	selector = 'a.nlajx';
	if(container) selector = container + ' ' + selector;
	$(selector).click(function(){
		ajaxRequest($(this).attr('href'), true);
		//$.history.load(this.href.replace(/^.*#/, ''));
		return false;
	});

	selector = 'a.new';
	if(container) selector = container + ' ' + selector;
	$(selector).click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	
	selector = '#lang a';
	$(selector).attr('href', function(){
		var newLink = $(this).attr('href');
		var presentHash = location.hash;
		presentHash = presentHash.replace(/^.*#/, '');
		
		newLink = newLink.replace(/#.*$/, '');
		newLink = newLink + '#' + presentHash;
		return newLink;
	});

	var afopt = { target: '#messages' };
	$('#ajxfrm').ajaxForm();
}
	


$(function(){
		if(window.location.pathname.length > 1){
			var tmpHref = window.location.protocol + '//' + window.location.host + '/#' + window.location.pathname.replace(/^\//, '');
			window.location = tmpHref;
		}
	
	$.history.init(ajaxRequest);
	init();
	
});

