title: My first jQuery plugin. Need help formatting and understanding how it works
body: <p>I wrote my first plugin today: a simple tool to make the number in an element count upwards.
  It works great, but I built it following examples and some trial and error so I can't say I understand how it works fully.</p>
  
  <p>I don't understand:</p>
  
  <p>a) How I should include handy functions like the <code>secondsToTime()</code> function (supposing I need it to be in a function - I understand that in this example it does not.) Why does it work here from within this.each block?</p>
  
  <p>b) How are the variables I declared (<code>_this, seconds, interval</code>) scoped? They are all kept simultaneously for each element.</p>
  
  <p>c) Could this plugin be structured better?</p>
  
  <p>Code:</p>
  
  <pre><code>$(document).ready(function(){
    $('.ticker').countup();
  });
  
  (function($) {   
    $.fn.countup = function() {
      return this.each(function(){
        var _this = this,
        seconds = parseInt($(this).text()),
        interval = setInterval(updateTicker, 1000 );
        updateTicker();
        function updateTicker(){
          seconds += 1;
          time = secondsToTime(seconds);
          outputtime = time.h + ":" + ((time.m &lt;= 9) ? '0' + time.m : time.m) + ":" + ((time.s &lt;= 9) ? '0' + time.s : time.s)
          $(_this).text(outputtime);
        }   
        function secondsToTime(secs){
          var hours = Math.floor(secs / (60 * 60));
          var divisor_for_minutes = secs % (60 * 60);
          var minutes = Math.floor(divisor_for_minutes / 60);
          var divisor_for_seconds = divisor_for_minutes % 60; 
          var seconds = Math.ceil(divisor_for_seconds);
          var obj = { 
            "h": hours,
            "m": minutes,
            "s": seconds
          };  
          return obj;
        }   
      }); 
    };  
  })(jQuery); 
  </code></pre>
  
  <p>Thanks for your feedback.</p>