function openPDFWin(url) {
  window.open(url, '', 'resizable');
}

function activateContentFolding() {
  if (useJQuery) {
    $(".foldable .text-content, .foldable .tx-ecogal-ply1, .foldable .videoplayer, .foldable .csc-header-n7").hide();
    $(".foldable").each(function () {
      var header = $(this).find(".csc-header")[0];
      if (header) {
        header.style.cursor = "pointer";
        header.title = "Click to show/hide details";
        $(header).bind("click", function(event) {
          $(this).parents(".foldable").find(".text-content, .tx-ecogal-ply1, .videoplayer, .csc-header-n7").toggle("normal");
        });
      }
    });
  } else {
    // FIXME: Unterstützung für tx-ecogal und zugehörigen Header nicht implementiert
    $$(".foldable .text-content").invoke("hide");
    $$(".foldable").each(function (el) {
      var header = el.down(".csc-header");
      header.style.cursor = "pointer";
      header.title = "Click to show/hide details";
      header.observe("click", function(event) {
        Effect.toggle(event.element().up(".foldable").down(".text-content"), "blind", { duration: 0.5 });
      });
    });
  }
}

function initPDFLinks() {
  if (useJQuery ) {
    $("a").each(function() {
      if (this.href && this.href.match(/\.pdf$/) )
        this.onclick = function() { openPDFWin(this.href); return false };
    });
  } else {
    $$("a").each(function(el) {
      if (el.href && el.href.match(/\.pdf$/) )
        el.onclick = function() { openPDFWin(el.href); return false };
    });
  }
}

function activateCalendarTooltips() {
  Tips.options.images = "/fileadmin/templates/js/prototype/images/";
  var prototip_options = { 
    border: 2, radius: 2, stem: 'topLeft', offset: { x: -5, y: -2 }, 
    hideOn: { element: 'closeButton', event: 'click' }, hideAfter: 7.3, hideOthers: true,
    hook: { tip: 'leftTop', target: 'bottomMiddle' } 
  }; 
  document.observe('dom:loaded', function() { 
    $$('.linked_day').each(function(el) { 
      var options = prototip_options;
      var tooltip_el = $(el.getAttribute('context'));
      if (tooltip_el) options["title"] = tooltip_el.down("h4").innerHTML;
      new Tip(el,  tooltip_el || '(leer)', options);
    }); 
  }); 
}


var useJQuery = typeof(jQuery) == "function";
var initCallback = function() {
  initPDFLinks();
  activateContentFolding();
};

if (useJQuery) {
  jQuery(function($) { initCallback() });
} else {
  document.observe("dom:loaded", initCallback);
}


