


/*
Created By: Chris Campbell
Website: http://particletree.com
Date: 2/1/2006

Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/

Extended by: echternacht new media (http://www.echternacht.com)
Extension: load Lightbox content via iframe
Requirement: requires Prototype JavaScript framework >= 1.5.0 (http://prototype.conio.net/)
Requirement: requires QueryParser  >= 0.2 (http://www.echternacht.com)
*/
if((typeof Prototype=='undefined') || parseFloat(Prototype.Version.split(".")[0] + "." + 
         Prototype.Version.split(".")[1]) < 1.5)
 throw("Lightbox requires the Prototype JavaScript framework >= 1.5.0");
if(typeof QueryParser=='undefined' || parseFloat(QueryParser.version) < 0.2)
 throw("Lightbox requires QueryParser >= 0.2");
/*-------------------------------GLOBAL VARIABLES------------------------------------*/
var detect = navigator.userAgent.toLowerCase();
var abox;
var Lightbox = Class.create();
Lightbox.prototype = {
 yPos : 0,
 xPos : 0,
 height : 0,
 width : 0,
 content : '',
 initialize: function(ctrl) {
  
  this.content = ctrl.href;
  Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false);
  ctrl.onclick = function(){return false;};
  qp = new QueryParser(this.content);
  this.height  = (qp.getValue('height') != null) ? qp.getValue('height') : 0;
  this.width  = (qp.getValue('width') != null) ? qp.getValue('width') : 0;
 },
 activate: function(){
  if (detect.indexOf('msie') > -1 && detect.charAt(detect.indexOf('msie') + 1 + 'msie'.length) < 7){
   this.getScroll();
   this.prepareIE('100%', 'hidden');
   this.setScroll(0,0);
   this.hideSelects('hidden');
  }
  this.displayLightbox("block");
  Lightbox.setActiveBox(this);
 },
 prepareIE: function(height, overflow){
  bod = document.getElementsByTagName('body')[0];
  bod.style.height = height;
  bod.style.overflow = overflow;
  htm = document.getElementsByTagName('html')[0];
  htm.style.height = height;
  htm.style.overflow = overflow; 
 },
 hideSelects: function(visibility){
  selects = document.getElementsByTagName('select');
  for(i = 0; i < selects.length; i++) {
   selects[i].style.visibility = visibility;
  }
 },
 getScroll: function(){
  if (self.pageYOffset) {
   this.yPos = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){
   this.yPos = document.documentElement.scrollTop; 
  } else if (document.body) {
   this.yPos = document.body.scrollTop;
  }
 },
 setScroll: function(x, y){ window.scrollTo(x, y);  },
 displayLightbox: function(display){
  this.adjustBox();
  $('overlay').style.display = display;
  $('lightbox').style.display = display;
  if(display != 'none')
   this.loadContent();
 },
 adjustBox: function(){
  if(this.height > 0 && this.width > 0){
   wd = this.getWindowDimensions();
   $('lightbox').style.height = this.height + "px";
   $('lightbox').style.width  = this.width + "px";
   $('lightbox').style.top    =  (wd['height']-this.height)/2 + "px";
   $('lightbox').style.left   =  (wd['width']-this.width)/2 + "px";
   $('lightbox').style.margin = 0;
  }
 },
 loadContent: function(){
  info  = '<div id="lbClose"><a href="#">&nbsp;</a></div>'; //schließen-Text
  info += '<iframe id="lbContent" name="lbContent" src="'+this.content+'" frameborder="0" scrolling="no"></iframe>';
  new Insertion.Before($('lbLoadMessage'), info);
  Event.observe($('lbClose'), 'click', Lightbox.deactivateBox, false);
  $('lightbox').className = "done";
 },
 deactivate: function(){
  Element.remove($('lbClose'));
  Element.remove($('lbContent'));
  if (detect.indexOf('msie') > -1 && detect.charAt(detect.indexOf('msie') + 1 + 'msie'.length) < 7){
   this.setScroll(0,this.yPos);
   this.prepareIE("auto", "auto");
   this.hideSelects("visible");
  }
  this.displayLightbox("none");
 },
 getWindowDimensions: function() {
  var w = 0, h = 0, d = document;
  if( typeof( window.innerWidth ) == 'number' ) {
   w = window.innerWidth;
   h = window.innerHeight;
  } else if( d.documentElement && ( d.documentElement.clientWidth || d.documentElement.clientHeight ) ) {
   w = d.documentElement.clientWidth;
   h = d.documentElement.clientHeight;
  } else if( d.body && ( d.body.clientWidth || d.body.clientHeight ) ) {
   w = d.body.clientWidth;
   h = d.body.clientHeight;
  }
  return {width: w, height: h};
 }
}
/*-----------------------------------------------------------------------------------------------*/
Lightbox.redesign = true;
Lightbox.setActiveBox = function (box) { abox = box; }
Lightbox.deactivateBox = function (){ if(abox != null) abox.deactivate(); }
Lightbox.initialize = function(){
 Lightbox.addMarkup();
 
 var fbox = document.getElementsByClassName('fbOn');
 for(var i = 0; i < fbox.length; i++) {
    if (fbox[i].href.indexOf('?') != -1) {
    fbox[i].href+= "&redesign=true";
     } else {
     fbox[i].href+= "?redesign=true";
     }    
  fbox[i] = new Lightbox(fbox[i]);
 }
}
Lightbox.addMarkup = function() {
 bod    = document.getElementsByTagName('body')[0];
 overlay   = document.createElement('div');
 overlay.id  = 'overlay';
 lb    = document.createElement('div');
 lb.id   = 'lightbox';
 lb.className  = 'loading';
 lb.innerHTML = '<div id="lbLoadMessage"><p>Loading</p></div>';
 bod.appendChild(overlay);
 bod.appendChild(lb);
 Event.observe(overlay, 'click', Lightbox.deactivateBox, false);
}
Event.observe(window, 'load', Lightbox.initialize, false);
Event.observe(window, 'unload', Event.unloadCache, false);

function openBoxForm(frm){
 obj = document.createElement('a');
 obj.href = frm.action+'&'+Form.serialize(frm)+"&redesign=true";
 fboxFrm = new Lightbox(obj);
    fboxFrm.activate();
    return false;
}
function auswahl(url){
 if (document.getElementById('lbContent') == null) {
  obj = document.createElement('a');
      if (url.indexOf('?') != -1) {      
     obj.href = url + "&redesign=true";
     } else {
     obj.href = url + "?redesign=true";
      }
     fboxFrm = new Lightbox(obj);
     fboxFrm.activate();     
 }
}