$(document).ready(function(){
	Cufon.replace('h1, label, .blogsplash a');
	prepareLinks();
});

function loadContent(url){
	var _this = $('div.display');
	var _loader = $('<img id="ajax-loader" src="/UI/Images/ajax-loader.gif" alt="Loading..." />');
	_loader.css('top', (($('div.graphic').height() / 2)) + 'px');
	_loader.css('left', ((_this.width() / 2) - 110) + 'px');
	_this.append(_loader);
	var _content = $('<div id="content" />');
	_content.load(url + ' div.content', {rnd: (Math.random() * 100)}, function(){
		_this.fadeOut('slow', function(){
			$('a.previous').attr('href', _content.find('a.previous').attr('href'));
			$('a.next').attr('href', _content.find('a.next').attr('href'));
			_this.attr('title', _content.find('.display').attr('title'));
			document.title = document.title.substring(0, document.title.indexOf('-') + 2) + _this.attr('title');
			_this.empty();
			_this.html(_content.find('.display').html());
			Cufon.replace('h1, label');
			_this.find('a[rel=external]').each(function(){
				$(this).attr('target', '_blank');
			});
			_loader.fadeOut('slow', function(){
				_this.fadeIn('slow', function(){
					_loader.remove();
				});
			});
		});
	});
}

function prepareLinks(){
	$('.previous,.next').click(function(){
		loadContent($(this).attr('href'));
		return false;
	});
	$('a[rel=external]').each(function(){
		$(this).attr('target', '_blank');
	});
}
