$(document).ready(function() {
	var url_comment_form = $('a.url_comment_form').attr('href');
	var url_comment_submit = $('a.url_comment_submit').attr('href');
	var url_mail_send = $('a.url_mail_send').attr('href');

	//
	// show the mail form
	//
	$('.email_send').live('click', function () {
		var article = $(this).parent();

		$('.email_form', article).show("slow");
		$('.email_send', article).hide("slow");
	});

	//
	// hide the mail form
	//
	$('.close_mail_form').live('click', function () {
		var article = $(this).parent().parent().parent();

		$('.email_form', article).hide('slow');
		$('.email_send', article).show('slow');
	});

	//
	// send mail
	//
	$('.email_submit').live('click', function () {
		var article = $(this).parent().parent().parent();
		var id = $('a.id', article).attr('href')

		$.post(url_mail_send, {
				mail: $('input.mail', article).val(),
				subject: $('input.subject', article).val(),
				message: $('textarea.message', article).val()
			}, function (html) {
				$('.email_form', article).hide('slow');
				$('.email_form', article).html(html);
				$('.email_form', article).show('slow');
			}
		);
	});

	//
	// show the comments form
	//
	$('.comment_leave').live('click', function () {
		var article = $(this).parent();

		$('.comment_form', article).show("slow");
		$('.comment_leave', article).hide("slow");
	});

	//
	// hide the comments form
	//
	$('.close_comment_form').live('click', function () {
		var article = $(this).parent().parent().parent();

		$('.comment_form', article).hide("slow");
		$('.comment_leave', article).show("slow");
	});

	//
	// submit comments
	//
	$('.comment_submit').live('click', function () {
		var article = $(this).parent().parent().parent();
		var id = $('a.id', article).attr('href')

		$.post(url_comment_submit, {
				article_ptr: id,				
				nick: $('input.nick', article).val(),
				email: $('input.email', article).val(),
				text: $('textarea.text', article).val()
			}, function (html) {
				$('.comment_form', article).hide('slow');
				$('.comment_form', article).html(html);
				$('.comment_form', article).show('slow');
			}
		);
	});
});
