javascript syntax with jQuery
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/440739/what-do-parentheses-surrounding-a-javascript-object-function-class-declaration-m">What do parentheses surrounding a JavaScript object/function/class declaration mean?</a><br>
  <a href="http://stackoverflow.com/questions/2309614/what-does-this-javascript-jquery-syntax-mean">What does this JavaScript/jQuery syntax mean?</a>  </p>
</blockquote>



<p>This is an open source jQuery popup library.</p>

<p>Somebody explain the code?  </p>

<pre><code>(function($){...})(jQuery);
</code></pre>

<p>for short <code>()();</code>?</p>

<p>What's this syntax?</p>

<p>How do I call <code>close_model</code> outside the code?</p>

<p>Here is my usage:</p>

<pre><code>$(function() {
    $("#leanModal").leanModal({top:200});
});

$(function(){...});//again what's this syntax?
</code></pre>

<p>Codes:</p>

<pre><code>(function($) {

    $.fn.extend({

        leanModal: function(options) {

            var defaults = {
                top: 100,
                overlay: 0.5
            }

            options = $.extend(defaults, options);

            return this.each(function() {

                var o = options;

                $(this).click(function(e) {

                    var overlay = $("&lt;div id='lean_overlay'&gt;&lt;/div&gt;");

                    var modal_id = $(this).attr("href");

                    $("body").append(overlay);

                    $("#lean_overlay").click(function() {
                        close_modal(modal_id);
                    });

                    var modal_height = $(modal_id).outerHeight();
                    var modal_width = $(modal_id).outerWidth();

                    $('#lean_overlay').css({
                        'display': 'block',
                        opacity: 0
                    });

                    $('#lean_overlay').fadeTo(200, o.overlay);

                    $(modal_id).css({

                        'display': 'block',
                        'position': 'fixed',
                        'opacity': 0,
                        'z-index': 11000,
                        'left': 50 + '%',
                        'margin-left': -(modal_width / 2) + "px",
                        'top': o.top + "px"

                    });

                    $(modal_id).fadeTo(200, 1);

                    e.preventDefault();

                });

            });

            function close_modal(modal_id) {

                $("#lean_overlay").fadeOut(200);

                $(modal_id).css({
                    'display': 'none'
                });

            }

        }
    });

})(jQuery);
</code></pre>
