/* Tiny MCE Editor */
/*******************/

var myEditors1 = new Array();
var myEditors2 = new Array();

function initEditors() {
	myEditors1 = $('textarea.editor_text');
	myEditors2 = $('textarea.editor');
	openEditors();
}

function openEditors() {
	// Text
	tinyMCE.settings['editor_selector'] = 'editor_text';
	tinyMCE.settings['theme_advanced_buttons1'] = 'pastetext,separator,bold,italic,separator,bullist,numlist,separator,link,unlink,separator,removeformat,code';
	tinyMCE.settings['theme_advanced_buttons2'] = '';
	tinyMCE.settings['theme_advanced_buttons3'] = '';
	for (i=0;i<myEditors1.length;i++) {
		tinyMCE.idCounter = 0;
		tinyMCE.execCommand('mceAddControl', false, myEditors1[i].id);
	}
	// HTML
	tinyMCE.settings['editor_selector'] = 'editor';
	tinyMCE.settings['theme_advanced_buttons1'] = 'formatselect,separator,bold,italic,separator,bullist,numlist,indent,outdent,separator,sub,sup,separator,charmap';
	tinyMCE.settings['theme_advanced_buttons2'] = 'link,unlink,anchor,separator,image,separator,tablecontrols';
	tinyMCE.settings['theme_advanced_buttons3'] = 'pastetext,pasteword,selectall,separator,undo,redo,separator,search,replace,separator,removeformat,code';
	tinyMCE.settings['theme_advanced_blockformats'] = 'p,h2,h3,h4,h5,h6';
	for (i=0;i<myEditors2.length;i++) {
		tinyMCE.idCounter = 0;
		tinyMCE.execCommand('mceAddControl', false, myEditors2[i].id);
	}
}

function removeEditors() {
	for (i=0;i<myEditors1.length;i++) {
		tinyMCE.execCommand('mceRemoveControl', false, myEditors1[i].id);
	}
	for (i=0;i<myEditors2.length;i++) {
		tinyMCE.execCommand('mceRemoveControl', false, myEditors2[i].id);
	}
}

function myFileBrowser(field_name, url, type, win) {
	if (type=='image')
		tinyMCE.activeEditor.windowManager.open({
				file : "/admin/popup/images/cd/?tinyMCE=1",
				title : "Image Browser",
				width : 600, height : 600,
				close_previous : "no",
				resizable : "yes", scrollbars: "yes",
				inline : "yes"
			}, {
				window : win,
				input : field_name
			});
	if (type=='file')
	tinyMCE.activeEditor.windowManager.open({
				file : "/admin/popup/files/cd/?tinyMCE=1",
				title : "File Browser",
				width : 600, height : 600,
				close_previous : "no",
				resizable : "yes", scrollbars: "yes",
				inline : "yes"
			}, {
				window : win,
				input : field_name
			});
	return false;
}

tinyMCE.init({
	theme : "advanced",	mode : "textareas",	language: "de", editor_selector : 'editor',
	entity_encoding : "raw", forced_root_block : "p", remove_trailing_nbsp : true,
	doctype : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">',
	fix_list_elements : true, fix_table_elements : true, relative_urls : false,	button_tile_map : true,
	plugins : "paste,table,searchreplace,inlinepopups", content_css: '/admin/styles/content.php',
	paste_auto_cleanup_on_paste : true,	paste_convert_middot_lists : true, paste_unindented_list_class : "",
	paste_replace_list : '\u2122,<sup>TM</sup>',
	theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location: 'bottom', theme_advanced_resizing: true, theme_advanced_resize_horizontal : false,
	file_browser_callback : "myFileBrowser"
});
