﻿var _fieldToPost = '';
var _editorBookmark = null;

function CreateWYSYWYGEditor(classId, onInitCallBack) {

    tinyMCE.init({
        // General options
        mode: "textareas",
        theme: "advanced",
        editor_selector: classId,
        content_css: "/bAdmin/DefaultContent/Admin/Styles/XhtmlEditor.css",

        plugins: "safari,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",

        // Theme options
        theme_advanced_buttons1: "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,forecolor,backcolor",
        theme_advanced_buttons2: "bullist,numlist,|,outdent,indent,blockquote,,link,unlink,cleanup,code,|,fullscreen",
        theme_advanced_buttons3: "",
        theme_advanced_buttons4: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",

        theme_advanced_resizing: true,
        theme_advanced_resize_horizontal: false,

        accessibility_focus: true,
        media_strict: true,
        width: "100%",

        // Eventi
        setup: function(ed) {
            ed.onClick.add(function(ed, e) {
                _editorBookmark = (ed.selection.getBookmark());
            });
            ed.onKeyUp.add(function(ed, e) {
                _editorBookmark = (ed.selection.getBookmark());
            });
        }

    });
    
}

function onXhtmlInitialized() {

}

// Funzioni esterne per la gestione delle opzioni che possiamo aggiungere all'editor
function InsertVideo(editorId, videoid) {
    var editor = tinyMCE;
    if (editor) {
        editor.activeEditor.focus();
        if (_editorBookmark)
            editor.activeEditor.selection.moveToBookmark(_editorBookmark);
        editor.activeEditor.selection.setContent('[@video:' + videoid + ']');
        //editor.activeEditor.execCommand('mceInsertContent', false, '[@video:' + videoid + ']');
        
        jQuery.fn.fancybox.close();
    }
}

