var Doxsey = {
	Blog: {
		login: function(evt, el) {			
			Doxsey.call("login",{"password": el.find("input").val()},function() {
				location.reload();
			});
		},
		logout: function(evt, el) {			
			Doxsey.call("logout",{},function() {
				location.reload();
			});
		},
		publishPostEvent: function(evt, el) {
			var entry = el.parents("div.entry");
			
			Doxsey.call("publishPost",{"post_id": entry.attr("post_id")},function() {
				location.reload();
			});
		},
		unpublishPostEvent: function(evt, el) {
			var entry = el.parents("div.entry");
			
			Doxsey.call("unpublishPost",{"post_id": entry.attr("post_id")},function() {
				location.reload();
			});
		},
		deleteCommentEvent: function(evt, el) {			
			Doxsey.call("deleteComment",{"comment_id": el.attr("comment_id")},function() {
				location.reload();
			});
		},
		/**
		 * Submit the Comment
		 */
		submitCommentEvent: function(evt, el) {
			var form = el;
			
			var author = form.find("input[name='comment_author']").val();
			var link = form.find("input[name='comment_link']").val();
			var content = form.find("textarea").val();
			
			Doxsey.call(
				"submitComment",
				{
					post_id: $("div.post").attr("post_id"),
					author: author,
					link: link,
					content: content
				},
				function() {
					location.reload();				
				}
			);
			
			return false;
		},
		submitPostEvent: function(evt, el) {			
			var form = el;
						
			var postId = Number(form.attr("post_id"))
			var title = form.find("input[name='post_title']").val();
			var status = form.find("select").val();
			var content = form.find("textarea").val();
			
			Doxsey.call(
				"editPost",
				{
					post_id: postId,
					title: title,
					status: status,
					content: content					
				},
				function(result) {
					console.log(result);
					location.href = "post.php?id=" + result.id;
				}
			);
			
			return false;
		}
	},
	call: function(method, data, success) {		
		$.ajax({
			url: "api.php",
			data: {
				method: method,
				data: $.toJSON(data)
			},
			dataType: "json",
			success: success
		});
	}
};