$(function() {

	$('.message').hide();
	$('.unapproved .message').show();
	$('.unapproved .view-message').html('Hide Message');
	$('.comment-body a').fancybox();
	$('.message a').fancybox();
	
	// Ajax Operations for posts
	$('.delete').click(function() {
		
		if (confirm("Are you sure you want to delete this entry?"))
		{
			var targetUrl = $(this).attr('href');
			
			$.ajax({
				url: targetUrl,
				success: function(data) {
					 $('.comm-' + data).slideUp();
				}
			});
		}
		
		return false;
	});


	$('.toggle-approval').click(function() {
		
		var targetUrl = $(this).attr('href');
		var targetLink = $(this);
		
		$.ajax({
			url: targetUrl,
			success: function(data) {
				 
				$('.comm-' + data).toggleClass('unapproved');
				 
				if ($(targetLink).html() === "Approve This Entry")
				{
			 		$(targetLink).html("Unapprove This Entry");
				 	targetLink.attr('href', targetUrl.substr(0, targetUrl.length-1) + '1');
			 	}
			 	else
			 	{
			 		$(targetLink).html("Approve This Entry");
				 	targetLink.attr('href', targetUrl.substr(0, targetUrl.length-1) + '0');
				}
			}
		});
		
		return false;
	});
	
	$('.view-message').click(function() {
		var link = $(this);
		var div = link.parent().parent();
		
		if (link.html() === 'View Message')
			link.html('Hide Message');
		else
			link.html('View Message');
		
			
		div.children('span.message').slideToggle();

		return false;
	});


});