jQuery Plugin development Events Handlers
<p>I'm trying to learn to develop jQuery plugins. I readed the base tutorial on jQuery site, and try to understand how it works and how structure the plugin.</p>

<p>I did some fast test, but i'm stuck now and i don't know how to get past.</p>

<p>Here is the code:</p>

<pre><code>var myElement = $("#Foo");
var myButton = $("#Bar");
(function($) {
var showAlert;
var mathWorks;
var methods = {
    init : function(options) {

    // Declaring Default Options
    var defaults = 
    {
        option1 : 'Default',
        option2 : false
    }

    // Merge Options
        var opt =  $.extend(defaults, options);

    showAlert = function(txt)
    {
        alert(txt);
    }

    mathWorks = function(a,b)
    {
        alert('Result of '+a+'*'+b+' = '+ a*b);
    }


    methods.doSomething(opt.option1);
},

doSomething: function(text)
{
    alert(text);
},

doMathWorks: function(a,b)
{

    mathWorks(a,b)
}

};

$.fn.testPlugin = function() {
    var method = arguments[0];

    if(methods[method]) {
        method = methods[method];
        arguments = Array.prototype.slice.call(arguments, 1);
    } else if( typeof(method) == 'object' || !method ) {
        method = methods.init;
    } else {
        $.error( 'Method ' +  method + ' does not exist on jQuery.pluginName' );
        return this;
    }
    return method.apply(this, arguments);   

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

<p><strong>Where do i declare Events Handlers?</strong></p>

<p>Like:</p>

<pre><code>myButton.bind('click', function()
        {
            alert('test');
            //methods.doSomething("Testing");
});
</code></pre>

<p>And also, It is correct to declare elements variables before the plugin, as i did?</p>
