$(document).ready(function(){
	var to_author = $('#commentform input[name=to_author]').val();
	if(to_author == '')
	{
		$('#commentform .to_author').hide();
	}
	
	var commentform = $('#commentform');
	if(!commentform.hasClass('error'))
	{
		commentform.hide();
	}
	else
	{
		parent.location = '#write_comment';
		$('#write_comment').click(function(e){
			e.preventDefault();
			parent.location='';
			});
		$('a.answer').click(function(e){
			e.preventDefault();
			parent.location='';
			});
		return;
	}
	
	$('#write_comment').toggle(
		function(e){
			e.preventDefault();
			$('#commentform').show();
			parent.location = '#write_comment';
		},
		function(e){
			e.preventDefault();
			var commentform = $('#commentform');
			commentform.find('input[name=to_author]').val('');
			var to_ath = commentform.find('.to_author');
			to_ath.find('span').html('');
			to_ath.hide();
			commentform.hide();
			commentform.find('input[name=author]').val('');
			commentform.find('input[name=code]').val('');
			commentform.find('textarea[name=txt]').val('');
			commentform.hide();
		});

	$('a.answer').click(function(e){
		e.preventDefault();
		var ath = $(this).parent().find('span.ath').html();
		var commentform = $('#commentform');
		commentform.find('input[name=to_author]').val(ath);
		var to_ath = commentform.find('.to_author');
		to_ath.find('span').html(ath);
		to_ath.show();
		parent.location = '#write_comment';
		commentform.show();
		});
});
