title: jquery animate div left/right if conditions
body: <p>I managed to put together a block of code that animates a div inside a container div based on certain conditions - however my math must be slightly off because it is animating slightly too far to the left. see example @ <a href="http://dev.whiteb0x.com/gallery" rel="nofollow">http://dev.whiteb0x.com/gallery</a></p>
  
  <pre><code>var width = $('#nav').width();
  $('#nav').width(width * 2 + 20);
  
  $(".nav-next").click(function () {
      var pos = $('#nav').position();
      var width = $('#nav-viewport').width();
      var width = width * (-1);
      alert(width);
      if (pos.left &lt;= 0 &amp;&amp; pos.left &gt; width &amp;&amp; !$('#nav').is(':animated')) {
          $('#nav li:first').before($('#nav li:last'));
          $("#nav").animate({"left": "-=300"}, "slow");
      }
  });
  
  $(".nav-prev").click(function () {
      var pos = $('#nav').position();
      if (!pos.left &lt;= 0 &amp;&amp; !$('#nav').is(':animated')) {
          $('#nav li:first').before($('#nav li:last'));
          $("#nav").animate({"left": "+=300"}, "slow");
      }
  });
  </code></pre>