  addEvent(window, 'load', init_me);

  function addEvent(obj, event, funct) {  
    if (obj.attachEvent) { //IE  
      obj['e' + event + funct] = funct;  
      obj['x' + event + funct] = function() {  
        obj['e' + event + funct](window.event);  
      }  
      obj.attachEvent('on' + event, obj['x' + event + funct]);  
    } else // other browser  
      obj.addEventListener(event, funct, false);  
  }   

  function init_me() {
    links = document.getElementsByTagName('a');
    for(linkId = 0; linkId < links.length; linkId++) {
      link = links[linkId];
      if(link.className == 'editlink') {
        if(document.all) {
        //IE si zase dela co chce = nic
          link.onclick=new Function('return openEditor(this.href);');
        } else {
          link.setAttribute('onclick', 'return openEditor(this.href);');
        }
      }
    }
    
    if(switcher = document.getElementById('editorSwitch')) {
      switcher.style.display= 'block';
      switcher.style.textAlign = 'right';
      switcher.innerHTML = 'Zapnout/vypnout editor';
      switcher.style.margin = '0.3em';
      switcher.style.cursor = 'pointer';
      addEvent(switcher, 'click', toggleEditor);
    }
  }

  function openEditor(url) {
    editorWin = window.open(url, '', 'height=500,width=600,menubar=no,location=no,resizable=yes,scrollbars=no,status=yes');
    
    //if(typeof editorWin == 'object')
      return false;
    return true; 
  }

  function showPreview() {
    if(typeof window.opener == 'object')
      window.opener.location.reload();
  }  
  
  function showPreviewAndClose() {
    if(typeof window.opener == 'object')
      window.opener.location.reload();
    window.close();
  }

