// Добавление WYSIWYG к формам на фронтэнде.
function insert_wysiwyg(inner_elements, images_list) {

	tinyMCE.init({
		mode: 'exact',
		theme: 'advanced',
		convert_urls: false,

		plugins: '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,wordcount,advlist,embed',

		theme_advanced_buttons1: 'styleselect, formatselect, image, bold, italic, separator, cut, copy, paste, undo, redo, separator, link, unlink, separator, bullist, numlist, code, removeformat, embed',
		theme_advanced_buttons2: 'justifyleft, justifycenter, justifyright, justifyfull, separator, tablecontrols, separator, pasteword, separator, imagemanager',
		theme_advanced_buttons3: '',

		elements: inner_elements,
		extended_valid_elements: '*[*]',
		external_image_list_url: '/_cache/' + images_list,
		content_css: '/styles/wysiwyg.css',

		force_br_newlines: false,
		force_p_newlines: true,

		encoding: 'xml',
		apply_source_formatting: false,
		remove_linebreaks: false,
		entity_encoding: 'named',
		entities: '160,nbsp,38,amp',
		nowrap: false,
		debug: false,
		gecko_spellcheck: true,

		theme_advanced_styles: '',

		template_external_list_url: 'lists/template_list.js',
		external_link_list_url: 'lists/link_list.js',
		media_external_list_url: 'lists/media_list.js',

		table_styles: '',
		table_cell_styles: '',
		table_row_styles: '',

		language: 'ru'
	}) // tinyMCE.init

} // function insert_wysiwyg

// Добавление WYSIWYG к формам постов.
function insert_wysiwyg_blog_post(inner_elements, images_list) {

	tinyMCE.init({
		mode: 'exact',
		theme: 'advanced',
		convert_urls: false,

		plugins: '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,wordcount,advlist,embed',

		theme_advanced_buttons1 : "bold,italic,underline,|,fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,|,numlist,bullist,|,outdent,indent,blockquote,|,justifyleft,justifycenter,justifyright,|,undo,redo,|,readmore",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",

		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",

		plugins : 'inlinepopups',

		setup : function(ed) {
			// Add readmore tag
			ed.addButton('readmore', {
				title : 'readmore cut',
				image : '/_img/readmore.png',
				onclick : function() {
					ed.focus();
					ed.selection.setContent('&lt;readmore&gt;Читать дальше&lt;/readmore&gt;');
				}
			})
		},

		elements: inner_elements,
		extended_valid_elements: '*[*]',
		external_image_list_url: '/_cache/' + images_list,
		content_css: '/styles/wysiwyg.css',

		force_br_newlines: false,
		force_p_newlines: true,

		encoding: 'xml',
		apply_source_formatting: false,
		remove_linebreaks: false,
		entity_encoding: 'named',
		entities: '160,nbsp,38,amp',
		nowrap: false,
		debug: false,
		gecko_spellcheck: true,

		theme_advanced_styles: '',

		template_external_list_url: 'lists/template_list.js',
		external_link_list_url: 'lists/link_list.js',
		media_external_list_url: 'lists/media_list.js',

		table_styles: '',
		table_cell_styles: '',
		table_row_styles: '',

		language: 'ru'
	}) // tinyMCE.init

} // function insert_wysiwyg

// Добавление WYSIWYG к форме добавления/редактирования события.
function insert_wysiwyg_events(inner_elements, images_list) {

	tinyMCE.init({
		mode: 'exact',
		theme: 'advanced',
		convert_urls: false,

		plugins: '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,wordcount,advlist,embed',

		theme_advanced_buttons1: 'styleselect, formatselect, image, bold, italic, separator, cut, copy, paste, undo, redo, separator, link, unlink, separator, bullist, numlist, code, removeformat, embed',
		theme_advanced_buttons2: 'justifyleft, justifycenter, justifyright, justifyfull, separator, tablecontrols, separator, pasteword, separator, imagemanager, readmore',
		theme_advanced_buttons3: '',


		setup : function(ed) {
			// Add readmore tag
			ed.addButton('readmore', {
				title : 'readmore cut',
				image : '/_img/readmore.png',
				onclick : function() {
					ed.focus();
					ed.selection.setContent('&lt;readmore&gt;Читать дальше&lt;/readmore&gt;');
				}
			})
		},
		
		elements: inner_elements,
		extended_valid_elements: '*[*]',
		external_image_list_url: '/_cache/' + images_list,
		content_css: '/styles/wysiwyg.css',

		force_br_newlines: false,
		force_p_newlines: true,

		encoding: 'xml',
		apply_source_formatting: false,
		remove_linebreaks: false,
		entity_encoding: 'named',
		entities: '160,nbsp,38,amp',
		nowrap: false,
		debug: false,
		gecko_spellcheck: true,

		theme_advanced_styles: '',

		template_external_list_url: 'lists/template_list.js',
		external_link_list_url: 'lists/link_list.js',
		media_external_list_url: 'lists/media_list.js',

		table_styles: '',
		table_cell_styles: '',
		table_row_styles: '',

		language: 'ru'
	}) // tinyMCE.init

} // function insert_wysiwyg
