
// Function for initialisation WYSIWYG
function initWYSIWYG(id) {
	tinyMCE.init({
		// General options
		mode : "exact",
		elements : (id ? id:"tinymce_textarea"),
		theme : "advanced",
		// plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
		plugins : "fullscreen,media,paste,preview,table",
		language : "en",
		content_css : "/css/tinymce.css",

        // Default width and height
		width : "90%",
		height : "300",

        // Small new lines
		force_p_newlines : false,
		force_br_newlines : true,
		forced_root_block : "",

		// Theme options
		// theme_advanced_buttons1 : "fontselect,fontsizeselect,|,forecolor,backcolor,|,bold,italic,underline,strikethrough,|,sub,sup,|,link,image,media,blockquote,removeformat",
		// theme_advanced_buttons2 : "undo,redo,|,cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,|,ltr,rtl,|,print,preview,fullscreen",
		// theme_advanced_buttons3 : "unlink,anchor,|,visualaid,insertlayer,code,hr,|,charmap,iespell,|,tablecontrols",
		theme_advanced_buttons1 : "fontselect,fontsizeselect,|,forecolor,backcolor,|,bold,italic,underline,strikethrough,|,sub,sup,|,link,image,media,blockquote,removeformat",
		theme_advanced_buttons2 : "undo,redo,|,pastetext,pasteword,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,outdent,indent,|,preview,fullscreen,|,unlink,anchor,|,code,hr,|,charmap",
		theme_advanced_buttons3 : "tablecontrols",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true
	});

	createEditorPanel();
}

var editor_panel = false;
var editor_content = "";

function createEditorPanel() {	if (!editor_panel) {		editor_panel = true;		// tinymce.EditorManager.activeEditor.getContent();		$("body").append("<div id='editor-panel' class='drop-menu' style='height: 50px; position: absolute; top: 10px; left: 10px;'>" +
						 "<div class='inner' style='height: 38px;'>" +
						 "<a href='#' onclick='openPreviewWindow(); return false;'>Предпросмотр</a><br>" +
						 "<a href='#' onclick='openHelpWindow(); return false;'>Правила</a>" +
						 "</div>" +
						 "</div>");
		$(window).scroll(function() {			$("#editor-panel").css("top", ($(window).scrollTop() + 10) + "px");
		});
	}}

function getEditorContent() {	return editor_content;}

// Open window with help by content box
function openHelpWindow() {	var preview = window.open("/includes/ajax/editor.php?help", "help", 'left=50,top=50,width=680,height=600,toolbar=0,resizable=0,scrollbars=1');
}

// Open window with preview of content box
function openPreviewWindow() {
	editor_content = tinymce.EditorManager.activeEditor.getContent();
	$.ajax({async: false, type: "POST", url: "/includes/ajax/editor.php", data: {"parse" : editor_content}, success: function(data) {
		editor_content = data;
		var preview = window.open("/includes/ajax/editor.php?preview", "preview", 'left=50,top=50,width=680,height=600,toolbar=0,resizable=0,scrollbars=1');
	}});
}