var plugins_tmce = "safari,iespell,inlinepopups,autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager";
var colors_tmce = "#000000,#999999,#CCCCCC,#FF0000,#00FF00,#0000FF,#FFFF00";
jQuery.fn.extend({
	isTinyMCE:function(){
		$(this).each(function(){
			if($(this).is('textarea')){
				if($(this).prev('.preview').length<=0)
					$(this).before('<div style="width:'+$(this).width()+'px" class="preview">'+$(this).val()+'</div>');
				$(this).prev('.preview')
				.click(function(){
					$(this).hide().next('textarea').height($(this).height()).tinymce({
						script_url : "/lib/js/tinymce/tiny_mce_gzip.php",
						language : "fr",
						skin : "o2k7",
						skin_variant : "silver",
						theme : "advanced",
						width : "695",
						disk_cache:true,
						debug:false,
						entity_encoding : "raw",
						plugins : plugins_tmce,
						content_css : "/lib/css/tinymce.css",
				        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,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,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
				        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
				        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "bottom",
						theme_advanced_resizing : true,
						theme_advanced_resize_horizontal : false,
						theme_advanced_text_colors : colors_tmce,
						theme_advanced_background_colors : colors_tmce,
						paste_auto_cleanup_on_paste : true
					});
				});
			}
		});
	}
});

/*
tinyMCE_GZ.init({
	themes : "advanced",
	plugins : plugins_tmce,
	languages : "fr",
	disk_cache : true
 });
*/
$(function(){$('textarea.editor').isTinyMCE();});
