/* depends on: jQuery */

/*!
 @abstract	The singleton responsible for downloading information about essays stored on the server.
 */
var Essays = {
	
	/*!
	 @method	downloadAvailableEssays
	 @abstract	Download the available essay-manifest.
	 @param		self			The object to be used as 'this' for the success and failure handlers.
	 @param		successHandler	A function expecting a single JSON object.
	 @param		failureHandler	A function expecting an XMLHttpRequest object, String object, and Error object.
	 @result	void
	 */
	downloadAvailableEssays: function(/*Object*/self, /*(JSON) -> void*/successHandler, /*(XMLHttpRequest, String, Error) -> void*/failureHandler) {
		$.ajax({
			   url: 'Data/Manifest.json', 
			   dataType: 'json', 
			   context: self, 
			   error: failureHandler, 
			   success: successHandler
		});
	},
	
	/*!
	 @method	downloadEssay
	 @abstract	Download an essay with a specified name. This should have been retrieved through Essays.downloadAvailableEssays.
	 @param		essayName		The name of the essay to download.
	 @param		self			The object to be used as 'this' for the success and failure handlers.
	 @param		successHandler	A function expecting a single JSON object.
	 @param		failureHandler	A function expecting an XMLHttpRequest object, String object, and Error object.
	 @result	void
	 */
	downloadEssay: function(/*String*/essayName, /*Object*/self, /*(JSON) -> void*/successHandler, /*(XMLHttpRequest, String, Error) -> void*/failureHandler) {
		$.ajax({
			   url: escape('Data/' + essayName), 
			   dataType: 'json', 
			   context: self, 
			   error: failureHandler, 
			   success: successHandler
		});
	},
	
};

