$(document).ready(function() {
	jQuery.extend(k2CommentOptions, {
		clearForm:		true,
		resetForm:		true,
		beforeSubmit:	k2Comment.beforeSubmit,
		error:			k2Comment.submitError,
		success:		k2Comment.submitSuccess
	});

    // bind form using 'ajaxForm'
	jQuery('form#commentform').ajaxForm(k2CommentOptions);
});

var k2Comment = {
	beforeSubmit: function() {
		jQuery('#commenterror').hide();
		jQuery('#commentload').show();
	},

	submitError: function(request) {
		jQuery('#commentload').hide();

		jQuery('#commenterror').show().html(request.responseText);
	},

	submitSuccess: function(data) {
		jQuery('#commenterror').hide().html();

		if ( jQuery('#leavecomment').length ) {
			jQuery('#leavecomment').remove();
		}

		jQuery('#comments').html(parseInt(jQuery('#comments').html()) + 1);

		if ( !jQuery('#commentlist').length ) {
			jQuery('#pinglist').before('<ol id="commentlist"></ol>');
		}

		jQuery('#commentlist').append(data);
		jQuery('#commentform :input').attr('disabled', true);
		jQuery('#commentload').hide();

		setTimeout(k2Comment.enableForm, 15000);
	},

	enableForm: function() {
		jQuery('#commentform :input').removeAttr('disabled');
	}
};