retrievePage = function(href, data) {
	data = (data ? data : "");
	_method = (data.length > 0 ? "POST" : "GET");
	
	$.ajax({
		dataType: "html",
		url: href,
		data: data,
		type: _method,
		beforeSend: function(xhr) {
			$("#div_layover").show(250);
		},
		success: function(data, status) {
			data = data.slice(data.indexOf("<!--CONTENT_START-->"), data.indexOf("<!--CONTENT_END-->"));
			$("#div_body").html(data);
			convertElements($("#div_body"));
		},
		error : function(xhr, status, error) {
			alert("An error occured: " + status + " / " + error);
		},
		complete : function(xhr, status) {
			$("#div_layover").hide(250);
		}
	});
}

convertElements = function(elem) {
	$("a", elem).click(function() {
		_href = $(this).attr("href");
		
		if (_href.indexOf(domain) < 0 ||
			_href.indexOf("feed") > 0 ||
			_href.indexOf("jpg") > 0) return true;
		
		retrievePage(_href);
		
		return false;
	});
	
	$("form", elem).submit(function() {
		_action = $(this).attr("action");
		_data = $(this).serialize();
		
		retrievePage(_action, _data);
		
		return false;
	});
}

$(function() {
	convertElements($(document));
});

/*retrievePage2 = function(href) {
	$("#iframe_ajax").attr("src", href).contents().ready(function() {
		_html = $(this).contents().contents().contents().html();
		
		alert(_html);
		
		_html = extractContent(_html);
		
		alert(_html);
		
		//$("#div_body").html(_html);
		hideLayover();
	});
}*/

processComments = function(elem) {
	$("#form_commentform").hide();
	
	$("a.a_show_comments", elem).unbind("click").click(function() {
		$("#form_commentform").show(500);
		return false;
	});
}