(function($) {
	
	$.extend({ 
		/**
	 	 * @param toCall	-	Script to call
	 	 */
	 	ksAjaxSend: function(toCall) {
	 		$.ksAjaxSend(toCall, null, null, null);
	 	},
	 	
	 	/**
	 	 * @param toCall	-	Script to call
	 	 * @param action	-	Action to call
	 	 */
	 	ksAjaxSend: function(toCall, action) {
	 		$.ksAjaxSend(toCall, action, null, null);
	 	},
	 	
	 	/**
	 	 * @param toCall	-	Script to call
	 	 * @param PostData	- 	The data that should be send via POST
	 	 */
	 	ksAjaxSend: function(toCall, postData) {
	 		$.ksAjaxSend(toCall, null, postData, null);
	 	}, 
	 	
	 	/**
	 	 * @param toCall	-	Script to call
	 	 * @param action	-	Action to call
	 	 * @param PostData	- 	The data that should be send via POST
	 	 */
	 	ksAjaxSend: function(toCall, action, postData) {
	 		$.ksAjaxSend(toCall, action, postData, null);
	 	}, 
	 	
	 	
	 	/**
	 	 * @param toCall	-	Script to call
	 	 * @param action	-	Action to call
	 	 * @param postData	- 	The data that should be send via POST
	 	 * @param af		- 	Function to call after get the result
	 	 */
	 	ksAjaxSend: function(toCall, action, postData, af) {
	 		$.ajax({
	 		    url: '/ajax/'+toCall+'.php',
	 		    type: 'POST', 
	 		    data: {
	 		    	action: action,
	 		    	postData: postData,
	 		    	callBack: af
	 		    },
	 		    async: false,
	 		    dataType: 'json',
	 		    success: $.ksAjaxResult,
	 		    error: function(XMLHttpRequest, textStatus, errorThrown) {   /* Error handling */   }
	 		});
	 	}, 
	 	ksAjaxResult: function(result){
	 		// TODO: prepare for multiple callBacks, default HTML renderings (e.g. div replace) & html updates
	 		if(result.callBack != null)
	 			//var callBackData = ;
	 			eval(result.callBack+'(result.callBackData, result.action)');
	 	}
	 });
	
	// Ajax Helpers
	
	// Serialize a set of data (e.g. formdata) into a json array
	$.fn.serializeJSON=function() {
		var json = {};
		jQuery.map($(this).serializeArray(), function(n, i){
			json[n['name']] = n['value'];
		});
		return json;
	};
	
	
})(jQuery);

