        var kernelDomain = '';
        var imageManagerUrl = '';
        var fileManagerUrl = '';
        var audioManagerUrl = '';
        var editorId = '';

        $(document).ready(function() {
            initEditorValues();
            tinyMCE.execCommand('mceAddControl', false, 'commentTextArea');
            if (kernelDomain) {
                createAudioPlugin();
            }
        });
        
        function initEditorValues ()
        {
            kernelDomain = $("#kernelDomain").val();
            imageManagerUrl = $("#imageManagerUrl").val() + "&_t=" + Math.random();
            fileManagerUrl = $("#fileManagerUrl").val() + "&_t=" + Math.random();
            audioManagerUrl = $("#audioManagerUrl").val() + "&_t=" + Math.random();
            editorId = $("#editorId").val();
        }
    
        function createAudioPlugin ()
        {
            // Creates a new plugin class and a custom listbox
            tinymce.create('tinymce.plugins.AudioPlugin', {
                createControl: function(n, cm) {
                    switch (n) {
                        case 'audiobutton':
                            var c = cm.createButton('audiobutton', {
                                title : 'Вставить / редактировать mp3-файл',
                                image : '/i/tiny_mce/audio.png',
                                onclick : function() {

                                    /*
                                    var url = kernelDomain + 'editor/plugins/addaudio';
                                    var ed = tinyMCE.get('Content');
                                    */
                                    var newUrl = '/editor/plugins/addaudio/audio.htm';
                                    winobj=window.open(newUrl,"popup","width=460,height=310,left=230,top=250,scrollbars=1,location=0,menubar=0,resizable=1");
                                    winobj.focus();                                
                                }
                            });

                            // Return the new splitbutton instance
                            return c;
                    }
                    return null;
                }
            });
            // Register plugin with a short name
            tinymce.PluginManager.add('audio', tinymce.plugins.AudioPlugin);            
        }
    
        //биндим клик по кнопке открыть форму
        var _width = $("textarea.comment-editor").eq(0).width();
        var _height = $("textarea.comment-editor").eq(0).height() + 20;
        var _elementId = $("textarea.comment-editor").eq(0).attr("id");
        
    
        tinyMCE.init({
            // General options
            //mode : "textareas",
            mode : "none",
            language: "ru",
            width: _width,
            height: _height,

            theme : "advanced",
            plugins : "-audio,youtube,advimage,advlink,media",
            elements : _elementId,
            // Theme options
            theme_advanced_buttons1 : "link,unlink,image,audiobutton,youtube",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            theme_advanced_buttons4 : "",

            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "none",
            theme_advanced_resizing : true,
            relative_urls : false,
            remove_script_host : false,

            // If you set this option to true, TinyMCE will force BR elements on newlines instead of inserting paragraphs. This option is set to false by default since paragraphs is a much better concept. BR elements should only be used when you really have to (mostly never). Also as of 3.x the forced_root_block option is enabled by default so if you really want to disable paragraphs disable that one as well.        
            force_br_newlines : true,
            // This option enables you to make sure that any non block elements or text nodes are wrapped in block elements. For example <strong>something</strong> will result in output like: <p><strong>something</strong></p>. This option is enabled by default as of 3.0a1.
            forced_root_block : "",
            
            valid_elements : "a[href|title|target],img[class|src|alt=|title=],object[classid|width|height|codebase|*]"
                            + "param[name|value|_value],embed[type|width|height|src|*],br",

            content_css : "/css/content.css"
        });
