toggleLoginFields = function(ele)
{
	if(ele.attr('checked'))
	{
		ele.siblings('span').text('Yes');
		ele.parent().siblings('.login-fields').slideDown('fast');
	}
	else
	{
		ele.siblings('span').text('No');
		ele.parent().siblings('.login-fields').slideUp('fast');
	}
};

$(document).ready(function()
{
	$('#eula-agree').click(function()
	{
		window.location = '/home.php?accepteula=true'; return false;
	});
	
	$('.add-author>a').click(function()
	{
		$.ajax(
		{
			url: '/manage-author.php',
			dataType: 'html',
			success: function(data)
				{
					var wrapper = $("#add-wrapper");
					wrapper.add().html(data);
					new widgEditor("author_profile");
					wrapper.toggle('fast');
					$('#author_canlogin, #author_isadmin').click(function(){toggleLoginFields($(this));});
				}
		});
		$('.edit-select, #edit-wrapper').hide('fast');
		return false;
	});
	
	$('.edit-author>a:first-child').click(function()
	{
		$(".edit-select").toggle('fast');
		$('#add-wrapper, #edit-wrapper').hide('fast', function() { $("#add-wrapper form, #edit-wrapper form").remove(); });
		return false;
	});
	
	$('.delete-post').click(function()
	{
		return confirm('The post will be deleted permanently.');
	});
});

editAuthor = function(authid)
{
	$.ajax(
	{
		url: '/manage-author.php',
		data: { id: authid },
		dataType: 'html',
		success: function(data)
			{
				$(".edit-select").hide('fast');
				var wrapper = $("#edit-wrapper");
				wrapper.add().html(data);
				new widgEditor("author_profile");
				wrapper.show('fast');
				$('#author_canlogin, #author_isadmin').click(function(){toggleLoginFields($(this));});
				$('#delete-author').click(function()
				{
					if(confirm('This author and all their posts will be deleted permanently.'))
					{
						$("#author_delete").attr('value', 'true');
						return true;
					}
					else
					{
						return false;
					}
				});
			}
	});
	
	return false;
}

