var w = false;

function openPDFWin(url) {
  window.open(url, '', 'resizable');
}

document.observe("dom:loaded", function() {
  
  $$('.event').each(function(event) {
    event.observe("mouseover", function() {
      event.addClassName("hover");
    });
    event.observe("mouseout", function() {
      event.removeClassName("hover");
    });
  });
  
  $$("a").each(function(a) {
    if (a.readAttribute("href").match(/^popup/)) {
      a.setAttribute("_href", a.readAttribute("href"));
      a.setAttribute("href", "#");
      a.up().observe("click", function() {
        popup(a.readAttribute("_href"));
      });
    }
  });

  $$("a[href$=.pdf]").each(function(elem) {
    elem.observe("click", function() {
      openPDFWin(this.href);
      this.href = "";
      return false;
    });
  });

  $$("div.image a").each(function(elem) {
    elem.observe("click", function() {
      openPDFWin(this.href);
      this.href = "";
      return false;
    });
  });
});

function popup(url) {
  if (w) { w.close(); }
  if (url.endsWith("Galerie")){
     w = window.open(url, "popup", "width=780,height=650,scrollbars=yes");
  } else {
    w = window.open(url, "popup", "width=680,height=650,scrollbars=yes");
  }
  w.focus();
}