// script for alex-fu.com

// init comments reply button
$(
	function () { 
		// this area will not be in the DOM if commenting is disabled.
		if ($('#commentForm').length > 0) {
			// find ever comment
			$('div.comment small')
				// and add a button to call the "reply" function
				.each(
					function (i) {
						id = $(this).parents('.comment').attr('id').match(/comment_(\d+)/);
						$(this).append('<a href="/comments/reply/comment' + id[1] + '" onclick="return commentReplyTo(' + id[1] + ');">Reply</a>');
					}
				);
			$('#commentForm').hide().after('&nbsp;<a id="commentShow" href="#" onclick="return commentShowForm();">New Comment</a>');
		}
	}
);
function commentReplyTo (id) {
	$('form#commentForm input#replyTo').remove();
	$('#commentForm').append('<input id="replyTo" type="hidden" name="replyto" value="' + id + '" />');
	commentShowForm();
	return false;
}
function commentShowForm () {
	$('#commentForm').show();
	$('#commentShow').remove();
	
	return false;
}

// init blog admin form
$(
	function () {
		if ($('#blogNew').length == 0)
			return;
		
		$('p#submit').prepend('<button onclick="return !adminBlogAdd();">Add More</button>');
	}
);
function adminBlogAdd ()
{
	var n = $('.bodyText textarea').length;
	
	$('p#submit').before('<p class="bodyText"><textarea name="text' + (n + 1) + '" rows="15" style="width : 100%;"></textarea>');
	
	return true;
}