$(document).ready(function() {
	var presentation_id = $('#presentation_id').val();
	var minisite_id = $('#minisite_id').val();
	$('.f-post').ajaxForm({
		target: null,
		beforeSubmit: comment_progress,  
		success: comment_render, 
		url: '/ajax/comments/add/index.php?presentation_id=' + presentation_id + '&minisite_id=' + minisite_id, 
		type: 'post', 
		dataType: 'json', 
		clearForm: false, 
		resetForm: false
	});
});

var comment_progress = function () {
	$('.btn-post').css('display', 'none');
}

var comment_render = function (comment) {
	//render comment
	var comment_date_format = $('#comment_date_format').val();
	var date = $.PHPDate(comment_date_format, new Date());
	$('#l-comm').prepend('\
	<li>\
		<p>' + comment['body'] + '</p>\
		<div class="c-sig">\
			<span class="c-date">' + date + '</span>\
			<span class="c-name">' + comment['author']  + '</span>\
		</div>\
	</li>\
	');
	
	//show fields
	$('textarea[name=comment]').val('');
	$('.blank-s').remove();
	$('.btn-post').css('display', 'block');
};
