(function($){
	$.fn.ajaxEdit = function(options){
		
		var contentPart = this;
		var originalHtml = this.html();
		editor = $('<textarea/>').text(originalHtml);
		editor.height(this.height());
		editor.width('100%');
		this.html('').append(editor);
		button = $('<input type="button" value="Save"/>');
		button.data('target', editor);
		button.click(function(){
			var val = $(this).data('target').val();
			if(val == originalHtml){
				contentPart.html(originalHtml);
				if(typeof(options.success)!="undefined"){
					call = options.success;
					call();
				}
				return;
			}
			$(this).val('Saving...');
			options.data[options.newDataKey]=val;
			$.ajax({
				url: options.url,
				data: options.data,
				success: function(){
					contentPart.html(val);
					if(typeof(options.success)!="undefined"){
						call = options.success;
						call();
					}
				}
			});
		});
		this.append(button);
		
		return this;
	}
})(jQuery);

