function mceSimple(selector)
{
	$(selector).each(function(){
		$(this).tinymce({
			mode : "textareas",
			theme : "advanced",
			language : "es",
			width: "100%",
			height: "200px",
			theme_advanced_toolbar_location : "top",
			theme_advanced_buttons1 : "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			disk_cache : false,
			debug : true,
			onchange_callback : function(ed){
				tinyMCE.triggerSave(false, true); 
			},
			setup : function(ed) {
				ed.onKeyPress.add(function(ed, evt) {
					tinyMCE.triggerSave(false, true); 
				});
				
				ed.onChange.add(function(ed, evt) {
					tinyMCE.triggerSave(false, true); 
				});
			}
		});
	});
}

function mceAdvanced(selector)
{
	$(selector).each(function(){
		$(this).tinymce({
			mode : "textareas",
			theme : "advanced",
			language : "es",
			plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,|,undo,redo,|,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,outdent,indent,blockquote,undo,redo,link,unlink,anchor,image,cleanup,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,removeformat,visualaid,sub,sup,charmap,emotions,iespell,media,fullscreen",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,cite,abbr,acronym,del,ins,attribs,nonbreaking,template,pagebreak,advhr",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : false,
			width: "100%",
			disk_cache : false,
			debug : true,
			onchange_callback : function(ed){
				tinyMCE.triggerSave(false, true);
			},
			setup : function(ed) {
				ed.onKeyPress.add(function(ed, evt) {
					tinyMCE.triggerSave(false, true); 
				});
				
				ed.onChange.add(function(ed, evt) {
					tinyMCE.triggerSave(false, true); 
				});
			}
		});
	});
}

$(document).ready(function()
{
	$(document).ajaxStart(function(){
		$(".mceSimple, .mceAdvanced").each(function(){
			$(this).tinymce('remove');
		});
	}).ajaxStop(function(){
		mceSimple(".mceSimple");
		mceAdvanced(".mceAdvanced");
	});
});

