title: Understanding this javascript jquery function in function snippet
body: <p>This is partly a jquery question, but most javascript.  I just don't know javascript well enough to understand this code:</p>
  
  <pre><code>1 (function () {
  2            $(function () {
  3                //Global ajax progress dialog box
  4                //Simply run $("#ajax-progress-dialog").dialog("open"); script before the ajax post and
  5                //$("#ajax-progress-dialog").dialog("close"); on the ajax post complate
  6                $("#ajax-progress-dialog").dialog({
  7                    autoOpen: false,
  8                    draggable: false,
  9                    modal: true,
  10                    height: 80,
  11                    resizable: false,
  12                    title: "Processing, please wait...",
  13                    closeOnEscape: false,
  14                    open: function () { $(".ui-dialog-titlebar-close").hide(); } // Hide close button
  15                });
  16            });
  17        })(); 
  </code></pre>
  
  <p>I understand lines 3-15. In fact, I think I understand lines 2 through 16:  this is creating an anonymous function and wrapping it as a jquery object, right?  Not sure why it needs to be wrapped, but more importantly, I especially don't understand lines 1: opens with "(function" and 17: closes with ")()". What's that about?</p>
  
  <p>BTW, for completeness, note that this is invoked as follows:</p>
  
  <p>$("#ajax-progress-dialog").dialog("open");</p>
  
  <p>Credit: this example comes from  <a href="http://www.tugberkugurlu.com/archive/working-with-jquery-ajax-api-on-asp-net-mvc-3-0-power-of-json-jquery-and-asp-net-mvc-partial-views" rel="nofollow">tugberkugurlu</a></p>