(function() {

	var EledaPluginAutosave = {
		/**
		 * Init
		 * 
		 * Inicializuje plugin.
		 *
		 * @param {tinymce.Editor} editor
		 * @param {string} url
		 */
		init: function(editor, url) {
			editor.onChange.add(function () {
				if (EledaPluginAutosave.activeSaving != null) {
					EledaPluginAutosave.activeSaving.abort();
				}
				EledaPluginAutosave.activeSaving = Modules.ajaxSendRequest({
					type: 'autosaveText',
					text: editor.getContent(),
					modul_id: Modules.id,
					method: 'POST'
				}, null, function() {
					Modules.Gap.list();
					Modules.Bubble.list();
				});
			});
		},

		activeSaving: null,

		/**
		 * GetInfo
		 *
		 * Vrátí informace o pluginu.
		 */
		getInfo: function() {
		  return {
			longname: 'Eleda Plugin for Autosave',
			author: 'Clevis s.r.o.',
			authorurl: 'http://www.clevis.cz/',
			version: '1.0.0'
		  };
		}
	};

	// Vytvoříme nový plugin do editoru
	tinymce.create('tinymce.plugins.EledaPluginAutosave', EledaPluginAutosave);

	// Zaregistrujeme plugin
	tinymce.PluginManager.add('eledaautosave', tinymce.plugins.EledaPluginAutosave);

})();

