tinyMCE.init({
  theme : "advanced",
  mode: "textareas",
  editor_selector : "rich",
  plugins : "bbcode",
  /* for a localized version: install your language file, uncomment next line and adapt it */
  language : "de",
  theme_advanced_buttons1 : "bold,italic,underline,bullist,numlist,image,link,unlink,fontsizeselect,forecolor,justifyleft,justifycenter,justifyright,justifyfull,undo,redo,removeformat",
  theme_advanced_buttons2 : "",
  theme_advanced_buttons3 : "",
  theme_advanced_toolbar_location : "top",
  theme_advanced_toolbar_align : "center",
  /* for a localized version: you should adapt next line by translating texts */
  theme_advanced_font_sizes : "tiny=50%,small=85%,normal=100%,big=150%,huge=200%",
  content_css : "styles/prosilver/theme/bbcode.css",
  convert_fonts_to_spans: true,
  font_size_style_values : "8,10,12,14,18,24,36",
  entity_encoding : "raw",
  add_unload_trigger : false,
  remove_linebreaks : false,
  setupcontent_callback : "inizia",
  force_p_newlines : false,
  forced_root_block : false,
  //convert_fonts_to_spans : false,
  media_types : "flash=swf"
});
function toggla(bb)
{
  var bottone = document.getElementById('bottonecambia');
  if (tinyMCE.getInstanceById('message') != null) {
    tinyMCE.execCommand('mceRemoveControl', false, 'message');
    bb.style.display = '';
    bottone.removeChild(bottone.firstChild);
    bottone.appendChild(document.createTextNode('visual editor'));
  } else {
    tinyMCE.execCommand('mceAddControl', false, 'message');
    bb.style.display = 'none';
    bottone.removeChild(bottone.firstChild);
    bottone.appendChild(document.createTextNode('bb source'));
  }
}
function inizia(editor_id, body, doc)
{
  rte = tinyMCE.getInstanceById(editor_id);
  var bb = document.getElementById('format-buttons');
  if (bb && bb.style.display != 'none') {
    bb.style.display = 'none';
    var sottobb = document.createElement('div');
    bb.parentNode.insertBefore(sottobb, bb.nextSibling);
    var a1 = document.createElement('a');
    a1.setAttribute('id', 'bottonecambia');
    a1.appendChild(document.createTextNode('bb source'));
    tinymce.dom.Event.add(a1, 'click', function(e) {toggla(bb);});
    sottobb.appendChild(a1);
  }
  var boxfaccine = document.getElementById('smiley-box');
  if (!boxfaccine) {
    return;
  }
  var imgs = boxfaccine.getElementsByTagName('img');
  var ia;
  for (var i = 0; i < imgs.length; i ++) {
    ia = imgs[i].parentNode;
    ia.onclick = null;
    if (ia.getAttribute('onclick') == 'javascript:return false;') {
      continue;
    }
    ia.setAttribute('onclick', 'javascript:return false;');
    tinymce.dom.Event.add(ia, 'click', function(e) {
      var bb = document.getElementById('format-buttons');
      if (bb && bb.style.display != 'none') {
        insert_text(e.target.alt, true);
      } else {
        rte.execCommand('mceInsertContent', false, rte.dom.createHTML('img', {src: e.target.src}));
      }
      tinymce.dom.Event.stop(e);
    });
  }
  rte.focus();
}
