title: jquery + Scrolling + Check what element is visible
body: <p>I would like to know if its possible with jQuery to do the following:</p>
  
  <p><strong><a href="http://jsfiddle.net/AzFJR/2/" rel="nofollow">http://jsfiddle.net/AzFJR/2/</a></strong></p>
  
  <p>-check which ".main" is visible at the moment and dynamically add ".active" to the corresponding link in the "nav" ?</p>
  
  <p>Regards!</p>
  
  <p>Edit:</p>
  
  <p>I have worked it out using this <a href="http://www.appelsiini.net/projects/viewport" rel="nofollow">Viewport Plugin</a> and following code:</p>
  
  <pre><code>//find what element is in view
  var inview = '#' + $('.sectionSelector:in-viewport:first').attr('id'),
  
  //find the corresponding link
  $link = $('.mainNav li a').filter('[hash=' + inview + ']');
  
  //check i its already active or not and if not
  if ($link.length &amp;&amp; !$link.is('.active')) {
  
      //remove all previous active links and make the current one active
      $('.mainNav li a').removeClass('active');
      $link.addClass('active');    
  
  }
  
  //Start same proccess on every scroll event again
  $(window).scroll(function () {
      var inview = '#' + $('.sectionSelector:in-viewport:first').attr('id'),
      $link = $('.mainNav li a').filter('[hash=' + inview + ']');
      if ($link.length &amp;&amp; !$link.is('.active')) {
          $('.mainNav li a').removeClass('active');
          $link.addClass('active');    
      }
  });
  </code></pre>
  
  <p>Thanks every1 for the help!</p>