$(function(){
	$('a.commentGoodies').click(function(){
		openTag = $(this).attr('openTag');
		closeTag = $(this).attr('closeTag');

		if (this.id == 'add-link'){
			fillText = 'http://something.com';
			closeTag = closeTag + '\n';
		}
		else if (this.id == 'add-image') {
			closeTag = '\n';
			fillText = '';
		}
		else{
			fillText = 'enter text here';
		}

		//$('#commentText').append(openTag+fillText+closeTag);
		$('#commentText').val($('#commentText').val() + openTag+fillText+closeTag);

		return false;
	});

	$('#attach').click(function(){
		$('#upload-div').toggle();
	});
	
	$('#addCommentId').click(function(){
		$('#detailForm').toggle();
	});
	
	$('a.comment_edit_link').click(function(){
		var comment_id = $(this).attr('comment_id');
		$('form#comment_edit_form_'+comment_id).toggle();
		$('p#comment_text_'+comment_id).toggle();
		return false;
	});
	
	$('form.comment_edit_form').submit(function(){
		var comment_id = $(this).attr('comment_id');
		var comment_text = $('textarea#comment_'+comment_id).val();
		var comment_type = $(this).attr('comment_type');

		var data = { comment_id: comment_id, comment: comment_text, comment_type: comment_type, Submit: 'true' };

		$.post("/comment/ajaxUpdateComment", data, function(returndata){
			$('p#comment_text_'+comment_id).html(returndata.commentText).show();
			$('textarea#comment_'+comment_id).val(returndata.textareaText);
			$('form#comment_edit_form_'+comment_id).hide();
		}, "json");
		return false;	
	});
	
	$('a.post_edit_link').click(function(){
		$('form#post_edit_form').toggle();
		$('p#post_actual').toggle();
		return false;
	});
	
	$('#post_edit_form').submit(function(){
		var post_id = $('#post_uid').val();
		var text = $('textarea#post_text').val();

		var data = { post_id: post_id, text: text, Submit: 'true' };

		$.post("/forum/ajaxUpdatePost", data, function(returndata){
			$('p#post_actual').html(returndata.commentText).show();
			$('textarea#post_text').val(returndata.textareaText);
			$('form#post_edit_form').hide();
		}, "json");
		return false;	
	});
	
	$('a.comment_delete_link').click(function(){
		var comment_id = $(this).attr('comment_id');
		var post_id = $('.forumList').attr('id');

		var data = { comment_id: comment_id, post_id: post_id, Submit: 'true' };

		$.post("/forum/ajaxDeleteForumComment", data, function(returndata){
			$('div#comment_container_'+comment_id).hide("slow");
		}, "json");

		
		return false;
	});
});
