jQuery.fn.dialogShadow = function() {
	return this.shadow({offset: 2, opacity: 0.3});
}

jQuery.fn.bounceUpEffector = function() {
	return this.effect('bounce', {distance: 20, times: 1});
}

jQuery.fn.initialDialog = function() {
	return this.dialog({modal: true});
}

jQuery.fn.checkFormData = function() {
	if ($('#id_body', this).val() == "") {
		alert('にゅうりょくしてください');
		return false;
	}
	return this;
}

jQuery.fn.previousPagingEffector = function(response) {
	this.hide('slide', {direction: 'right'});
	this.html(response).show('slide', {direction: 'left'});
	return this;
}

jQuery.fn.nextPagingEffector = function(response) {
	this.hide('slide', {direction: 'left'});
	this.html(response).show('slide', {direction: 'right'});
	return this;
}

jQuery.fn.postingEffector = function(response) {
	this.hide('slide', {direction: 'down'});
	this.html(response).show('slide', {direction: 'up'});
	return this;
}

function alertAjaxError() {
	alert('つうしんえらーがはっせいしました');
	return false;
}

$(function() {
	$('#parentFormInitialOpenButton').click(function() {
		$('#parentForm').initialDialog().show().dialogShadow().parent().parent().bounceUpEffector();
		$(this).hide().next().show();
		//$('#id_body', $('#parentForm')).focus();
		return false;
	});

	$('#parentFormOpenButton').click(function() {
		$('#parentForm').dialog('open').parent().parent().bounceUpEffector();
		return false;
	});

	$('#parentForm form').submit(function() {
		var form = $(this).checkFormData();
		if (!form) {
			return false;
		}
		$.post(form.attr('action'),
					 form.serialize(),
					 function(response, status) {
						 if (status != "success") {
							 return alertAjaxError();
						 }
						 $('#parentForm').dialog('close');
						 $('#id_body', form).val('');
						 $('#baseBox').postingEffector(response);
						 //$('#baseBox').html(response).show('slide', {direction: 'up'});
					 });
		return false;
		});
});