DialogPopupClass = function (options)
{
  this.init(options);
};


$.extend(DialogPopupClass.prototype, {
  // object variables
  overlay_div: null,
  popup_div: null,
  inner_div: null,
  spinner: null,
  close_icon: null,

  options: {
    onopen: null,
    onclose: null,
    append_to: 'body',
    close_on_background_click: true
  },

  init: function(options) {
    // do initialization here
    this.options =  $.extend(this.options, options);

    this.overlay_div = $('<div>')
      .attr('class', 'popup_close')
      .css({
        'background': '#000000 none repeat scroll 0 0',
        'display': 'none',
        'height': '100%',
        'left': '0',
        'position': 'fixed',
        'top': '0',
        'width': '100%',
        'z-index': '100000'
      });

    this.popup_div = $('<div>')
      .attr('class', 'popup')
      .css({ 'z-index': '100001' });
    this.inner_div = $('<div>');

    this.close_icon = $('<a>')
      .attr({
        'class': 'button popup_close',
        'href': '#'
      })
      .html('Fenster schließen');

  },

  change_popup_div_pos: function() {

    this.popup_div.css("position","absolute");
    this.popup_div.css("top", ( $(window).height() - this.popup_div.outerHeight() ) / 2+$(window).scrollTop() + "px");
    this.popup_div.css("left", ( $(window).width() - this.popup_div.outerWidth() ) / 2+$(window).scrollLeft() + "px");

  },

  open: function() {
    this.inner_div.appendTo(this.popup_div);
    this.close_icon.appendTo(this.popup_div);

    this.close_icon.bind('click', {that: this}, function(ev) {
      ev.preventDefault();
      ev.data.that.close();
    });

    this.overlay_div.appendTo(this.options.append_to);
    this.popup_div.appendTo(this.options.append_to);

    this.change_popup_div_pos();

    this.overlay_div.css('opacity','0.7')
    this.overlay_div.fadeIn(0);

    this.popup_div.fadeIn(500);

    if(typeof(this.options.onopen) == 'function')
      this.options.onopen();

  },

  close: function() {
    var ov_div = this.overlay_div;
    var pop_div = this.popup_div;

    this.popup_div.fadeOut(500, function() {
      ov_div.fadeOut(0, function() {
        ov_div.remove();
        pop_div.remove();
      });
    });


    //this.fireEvent('onClose');
    if(typeof(this.options.onclose) == 'function')
      this.options.onclose();

  }

});
