var TextElement;

if ($type(window['ModuleElement']) == 'class'){
	TextElement = new Class({
		Extends: ModuleElement,
		options:{
		}
	});
	$extend(TextElement,{
		attach:function(){
		
		},
		load:function(textarea,options){
			textarea.toRichTextarea($merge(TextElement.tinyMCEConfig, options));
			(function(){if (tinyMCE.activeEditor) tinyMCE.activeEditor.execCommand('mceCleanup');}).delay(1000);
		},
		unload:function(textarea){
			var id = textarea.get('id');
			tinyMCE.execCommand('mceRemoveControl', false, id);
		},

		askToSaveIfDirty : function(textarea) {
			return tinyMCE.getInstanceById(textarea.get('id')).isDirty() ? confirm('You have unsaved changes. Are you sure you want to continue?') : true;
		},
		
		saveText : function (textarea){
			var editor = tinyMCE.get(textarea.get('id'));
			if (editor){
				editor.save();
				editor.setProgressState(1);
			}
		},

		unlockText : function(textarea){
			var editor = tinyMCE.get(textarea.get('id'));
			if (editor)
				editor.setProgressState(0);
		}
	});

	TextElement.tinyMCEConfig = {
		plugins : "safari,paste,searchreplace,inlinepopups,filemanager,imagemanager,media,spellchecker,table",
		theme_advanced_buttons1 : "undo,redo,|,pasteword,|,search,replace,|,justifyleft,justifycenter,justifyright,justifyfull,|,insertfile,insertimage,|,table,row_before,row_after,delete_row,row_props,col_before,col_after,delete_col,cell_props",
		moduleinstid : null
	};
}