function setupPostAjax(){
	$ ('a.display').unbind('click');
	$ ('a.display').bind('click', function() {
		var post = $(this).parent().parent().parent();
		var postId = post.attr("id").replace(/^post-(.*)$/,'$1') ; //Get entry ID

		//closePost($('.displaying'));
		//post.addClass('displaying');

		var postContent = $("div.content_post_content", post);
		var postPlus =$("div.post_plus", post);

		var destination = $(post).offset().top-100;

		$.ajax ({
			url:"?action=ajax_post&id="+postId,
			success:function(data) {
				$content=postContent.html(data).hide().slideToggle("slow", function(){
					setupCommentAjax(postId);
				});
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination + 560}, 500 );
				postPlus.slideToggle('slow');
				$('p.more_info', post).toggleClass('hide');
				$('a.close_post', post).toggleClass('hide');
			}
		} ) ;
		$('a.display', post).unbind('click');
		
		$('a.display', post).addClass('displayed');
		$('a.display', post).removeClass('display');
		
		$ ('a.close_post', post).bind('click', function() {
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination }, 500 );
			postPlus.slideToggle('slow');
			postContent.slideToggle("slow", function() {
				$('p.more_info', post).toggleClass('hide');
				$('a.close_post', post).toggleClass('hide');
				$ ('a.displayed', post).bind('click', function() {
					$('a.displayed', post).unbind('click');
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination + 560}, 500 );
					postPlus.slideToggle('slow');
					postContent.slideToggle("slow", function() {
						$('p.more_info', post).toggleClass('hide');
						$('a.close_post', post).toggleClass('hide');
					});
				})
			});
		});
		return false ;
	} ) ;
}

/*function closePost(post){
	post.removeClass('displaying');
	var postContent = $("div.content_post_content", post);
	var postPlus =$("div.post_plus", post);
	postPlus.slideToggle('fast');
	postContent.slideToggle("fast", function() {
		$('p.more_info', post).toggleClass('hide');
		$('a.close_post', post).toggleClass('hide');
		$ ('a.displayed', post).bind('click', function() {
			$('a.displayed', post).unbind('click');
			postPlus.slideToggle('fast');
			postContent.slideToggle("fast", function() {
				$('p.more_info', post).toggleClass('hide');
				$('a.close_post', post).toggleClass('hide');
			});
		})
	});
}*/

function setupCommentAjax(id){
	var comments=$("#comments-"+ id);
	var $commentlist=$('.comments_list', comments);
	var $respond=$('#respond', comments);
	var $textarea=$('#comment', comments);
	var $message=$('<span class="comment-message"></span>').appendTo($respond);
	$('#commentform', comments).submit(function(){
		$.ajax({
			beforeSend:function(xhr){
				xhr.setRequestHeader("If-Modified-Since","0");
				$message.empty().append('ENVIANDO...');
			},
			type:'post',
			url:$(this).attr('action'),
			data:$(this).serialize(),
			dataType:'html',
			error:function(xhr){
				if(xhr.status==500){
					$message.empty().append(xhr.responseText.split('<p>')[1].split('</p>')[0]);
				}
				else if(xhr.status=='timeout'){
					$message.empty().append('Error:Server time out,try again!');
				}
				else{
					$message.empty().append('Please slow down,you are posting to fast!');
				}
			},
			success:function(data){
				$message.empty().append('Thank you for your comment!');
				$newComList=$(data).find('.comments_list');
				$commentlist.remove();
				$newComList.insertAfter($respond);
				$commentlist=$newComList;
				$textarea.val(''); 
			}
		});//end of ajax
		//
		return false;
	});
}
