$(function () {
	
	//Showing the big comment box when "add comment" is clicked
	$('.add_comment_link a ').livequery('click', function(e) {
		show_big_comment_box($(this).attr("id"));
		return false;
	});
	
	
	//expanding into bigger text area when small text box is clicked
	$('.small_comment_text').livequery('click', function(e) {
		feed_id = $(this).attr("feed_id");
		
		show_big_comment_box(feed_id);
		return false;
	});
	

	//send ajax request to server when comment form is submitted
	$('.comment_form').livequery('submit', function(e) {
		$("#add_comment_loader_"+ $(this).attr("feed_item_id")).show();
		$("#add_comment_submit_"+ $(this).attr("feed_item_id")).hide();
		var request_string = $(this).attr("action");
		$.post(request_string+ "?" + $(this).serialize(), null, null, "script");
		return false;
	});
	
	//show more comments button
	$('.show_more_comments').livequery('click', function(e) {

		feed_id = $(this).attr("feed_id");
		$(this).hide();
		$(".associated_feed_"+ feed_id).show();
	
		return false;
	});
	
	//delete comment 
	$('.delete_comment').livequery('click', function(e) {

		
		//$.get($(this).attr("href")+ "?" + $(this).serialize(), null, null, "script");
		var answer = confirm("Are you sure you want to delete the comment?")
		if (answer){
			feed_id = $(this).attr("feed_id");
			$.ajax({
			  type: 'DELETE',
			  url: $(this).attr("href"),
			  data: null,
			  success: null,
			  dataType: "script"
			});
		}
	
		return false;
	});
});

function show_big_comment_box(feed_id)
{
	$("#add_comment_small_area_"+feed_id).hide();
	$("#add_comment_area_"+feed_id).show();
	$("#add_comment_text_"+feed_id).focus();
}
