(function($){
	$.aload = function(href){
		var target = $('#aload-target-container');
		var loading = $('<img src="/assets/img/loading.gif" style="width:32px;height:32px;margin:auto;" />');
		window.location.hash = href.replace('#', '~');
		target.empty().append(loading);
		$.get(href.split('#')[0] + '?a', {}, function(r){
			target.html(r);
			$.scrollTo($('a[name="' + window.location.hash.split('~')[1] + '"]'), 800);
			$('input').bind('blur', function(){
				$(this).validate();
			});
			$('form').bind('submit', function(e){
				if(!$(this).find('input').validate())
					e.preventDefault();
			});
		});
	};
})(jQuery);
jQuery(function($){
	$.aload(window.location.hash.replace('#', '').replace('~', '#'));
	$('a[href^="/"]:not([ignore])').live('click', function(e){
		e.preventDefault();
		$.aload($(this).attr('href'));
	});
	$('a[href$="#top"]:not([ignore])').live('click', function(e){
		e.preventDefault();
		$.scrollTo($('a[name="top"]'), 800);
	});
});
