var sospcidf_modal  =
{
  initialized:  {},
  registered: {},
  add:
    function (name, url, options)
    {
      this.registered[name]  = {
        'url':      url,
        'options':  options};

      return this;
    },
  exists:
    function (name)
    {
      return (typeof(this.registered[name]) !== 'undefined');
    },
  remove:
    function (name)
    {
      if (this.exists(name) === true)
        delete this.registered[name];

      return this;
    },
  init:
    function ()
    {
      var ptr = this;
      for (var x in this.registered)
      {
        this.initialized[x] = {
          message: null,
          init:
            function ()
            {
              var name = x;
              $('#' + name).click(
              function (e)
              {
                e.preventDefault();

                $.get(ptr.registered[name]['url'],
                  function(data)
                  {
                    // create a modal dialog with the data
                    $(data).modal(jQuery.extend({
                      closeHTML:    '<a href="#" class="modal-close">&nbsp;</a>',
                      position:     ['20%',],
                      overlayId:    'modal-overlay',
                      containerId:  'modal-container',
                      onOpen:       ptr.registered[name].open,
                      onClose:      ptr.registered[name].close
                    }, ptr.registered[name]['options']));
                  });
              });
            },
          open:
            function (dialog)
            {
              var name = x;
              ptr.initialized[name].resize(dialog);
              $(window).resize(
                function ()
                {
                  ptr.initialized[name].resize(dialog);
                });

              dialog.overlay.fadeIn(200,
                function ()
                {
                  dialog.container.fadeIn(200,
                  function ()
                  {
                    dialog.data.fadeIn(200);
                  });
                });
            },
          close:
            function (dialog)
            {
              dialog.data.fadeOut(200,
                function ()
                {
                  dialog.container.fadeOut(200,
                    function ()
                    {
                      dialog.overlay.fadeOut(200,
                      function ()
                      {
                        $.modal.close();
                      });
                    });
                });
            },
          resize:
            function (dialog)
            {
              dialog.container.height($(window).height() - 75);
            }
        };

        this.initialized[x].init();
      }

      return this;
    }
};

