var backgroundBox = null;
var foregroundBox = null;

window.addEvent('domready', function(){
  backgroundBox = new Element('div', {
    'styles': {
      'background-color': '#000',
      'position': 'absolute',
      'top': '0px',
      'left': '0px',
      'width': window.getWidth() + 'px',
      'height': window.getScrollHeight() + 'px',
      'opacity': '0.5',
      'z-layer': '100'      
    }
  });   

  foregroundBox = new Element('div', {
    'styles': {
      'background-color': 'white',
      'border': '1px solid #636363',
      'position': 'absolute',
      'top': '100px',
      'left': ((window.getWidth()/2) - 250) + 'px',
      'width': '500px',
      'height': 'auto',
      'z-layer': '200'      
    }
  });

  if($('moreInfoLink')) {
    $('moreInfoLink').addEvent('click', function(){
      document.body.appendChild(backgroundBox);
      document.body.appendChild(foregroundBox);
      
      var URL = '';
      URL = this.getFirst().value;
      
      if(URL != '') {
       new Ajax(URL, {
            method: 'get',
            onComplete: function(){ addFrmHandle(); },
            update: foregroundBox }).request();
      }
    })
  }
});


function addFrmHandle() {
  if($('ajaxFormClose')) {
    $('ajaxFormClose').addEvent('click', function(){
      foregroundBox.remove();
      backgroundBox.remove();             
    });
  }

  if($('ajaxKontaktForm')) {
    $('ajaxKontaktForm').addEvent('submit', function(e) {        
      new Event(e).stop();
      $('ajaxKontaktForm').send({update: foregroundBox, onComplete: function(){ addFrmHandle(); }});
    });
  }
}
