jQuery.fn.modalWindow = function() {
  // MEMBERS SETZEN
  var elem   = $(this[0]);
  var args   = arguments[0];

  var b_closebtn = true;
  var b_closable = true;
  var s_myId     = 'modal';
  var s_customId = false;
  var i_width    = 450;
  var i_height   = 600;
  var i_fade     = 600;
  var f_callback = function() {}

  // ARGUMENTE AUSLESEN
  if(typeof(args) != 'undefined') {
    b_closebtn = args.closebtn;
    i_width    = parseInt(args.w);
    i_height   = parseInt(args.h);
    s_url      = args.url;
    s_title    = args.title;
    if (typeof(args.closable) != 'undefined') b_closable = args.closable;
    if (typeof(args.customId) != 'undefined') s_customId = args.customId;
    if (typeof(args.callback) != 'undefined') f_callback = args.callback;
  }

  // BROWSER-MASSE BESTIMMEN
  var i_stageLeft  = 12;
  var i_stageTop   = 12;

  var i_screenWidth  = screen.width;
  var i_screenHeight = screen.height;
  var i_winOutWidth  = window.outerWidth;
  var i_winInnWidth  = window.innerWidth;
  var i_winOutHeight = window.outerHeight;
  var i_winInnHeight = window.innerHeight;

  // detect screen and browser window dimensions for IE6/7:
  if(typeof(i_winInnWidth) == 'undefined') {
    i_winInnWidth = document.documentElement.clientWidth;
  }
  if(typeof(i_winInnWidth) == 'undefined') {
    i_winInnWidth = document.body.clientWidth;
  }
  if(typeof(i_winInnHeight) == 'undefined') {
    i_winInnHeight = document.documentElement.clientHeight;
  }
  if(typeof(i_winInnHeight) == 'undefined') {
    i_winInnHeight = document.body.clientHeight;
  }

  i_stageLeft  = Math.floor((i_winInnWidth-i_width)/2)-24;
  if(i_height < i_winInnHeight) {
    i_stageTop   = Math.floor((i_winInnHeight-i_height)/2);
  } else {
    i_stageTop   = 2;
    i_height     = i_winInnHeight - 52;
    i_width      = i_width + 32;
  }

  var myBg = s_myId + '_bg', myBox = s_myId + '_box', myCont = s_myId + '_cont';
  if (s_customId) {
      myBg   = s_customId + '_bg';
      myBox  = s_customId + '_box';
      myCont = s_customId + '_cont';
  }

  var boxElem = '<div id="' + myBg + '"></div><div id="' + myBox + '"><div id="' + myCont + '"></div></div>';

  var f_close = function() {
    $(elem).find('#' + myBg + ', #' + myBox + '').fadeOut('1000').remove();
  }

  // ACTION:
  $(elem).prepend(boxElem);
  $(elem).find('#' + myBox).css({'width': i_width+'px', 'height': i_height+'px', 'top': i_stageTop+'px', 'left': i_stageLeft+'px'});
  $(elem).find('#' + myCont).load(s_url, f_callback);
  if(typeof(s_title) != 'undefined') {
    $(elem).find('#' + myBox).prepend('<h1>'+s_title+'</h1>');
  }
  if(typeof(b_closebtn) != 'undefined' && b_closebtn == true) {
    $(elem).find('#' + myBox).append('<a href="javascript:void(0);" class="arr_link" id="close_btn">schließen</a>');
  }
  $(elem).find('#' + myBg + ', #' + myBox).fadeIn(i_fade);

  if(b_closable) {
    $(elem).find('#' + myBg + ', #close_btn').click(f_close);

    $(document).unbind('keyup');
    $(document).keyup(function (e) {
      switch(e.keyCode) {
        case 27:
          $(elem).find('#' + myBg + '').click();
          break;
      }
    });
  }
}
