title: Traffic light jquery plugin
body: <p>I wrote jQuery plugin, that simulates work of traffic light. You can see demo <a href="http://jsfiddle.net/eko24ive/FeqFd/4/" rel="nofollow">here</a>, and the source code:</p>
  
  <pre><code>$.fn.plugin = function (b/*time*/,a/*starting with given color*/) {
      b.push(b[1]);//adding phases time to plugin array 
      return this.each(function (f, d) {
          var
              e = ["#008000", "#FFFF00", "#FF0000", "#FFFF00"],//green,yellow,red,yellow
              c = function () {
                  $(d).html(b[a])// here i want to place time, that left for current phase, it should change dynamicly
                      .css({
                          "background-color": e[a]//changing bg as light
                      });
               window.setTimeout(c, 1000 * b[a]);//hold phase as long as we told to plugin
               a = ++a % 4//result would be 0..1..2..3 and so on
              };
          c()
      })
  };
  
  $(window).load(function(){
  $("#c1").plugin([2,2,2],0);
  $("#c2").plugin([2,2,2],2);
  })
  
  &lt;/head&gt;
  &lt;body&gt;
  Starts with red:&lt;span id="c1" style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;br&gt;
  Starts with green:&lt;span id="c2" style=""&gt;&amp;nbsp;&lt;/span&gt;&lt;br&gt;
  </code></pre>
  
  <p>So, as you can see i'm selecting element, add plugin, writing time of phases for green,yellow,red, and with what color traffic light should begin.</p>
  
  <pre><code>$(d).html(b[a])
  </code></pre>
  
  <p>This part of code just writing time for current phase.
  I want to this number showed the time left for the phase.</p>