title: Infinite scroll is not a function error
body: <p>I'm having a bit of trouble with Paul Irish's infinite scroll plugin. If I only have 1 page of results, it works perfectly fine, but if I have more than one page of results it repeats the last page over and over again. Here is my infinite scroll configuration:</p>
  
  <pre><code>$('#grid').infinitescroll({
  navSelector  : "#paginationControl:first",
  nextSelector : "#paginationControl a#next:first",
  itemSelector : "#grid .entry",
  debug : true,
  bufferPx : 500
  },
  function(newElements){
  //Apply masonry
  var $newElems = $( newElements );
  $newElems.imagesLoaded( function(){
      $("#grid").masonry( 'appended', $newElems );
  });
      //See if this is the last page
  if( curPage &gt;= pages ){
      alert("Infinite scroll is paused.");
      $('#grid').infinitescroll('pause');
  }
  });
  </code></pre>
  
  <p>And here are my pagination controls:</p>
  
  <pre><code>&lt;?php if ($this-&gt;pageCount): ?&gt;
  &lt;div class="paginationControl" id="paginationControl"&gt;
  &lt;!-- Previous page link --&gt;
  &lt;?php if (isset($this-&gt;previous)): ?&gt;
      &lt;a href="&lt;?php echo $this-&gt;url(array('page' =&gt; $this-&gt;previous)); ?&gt;" id="previous"&gt;
          &amp;lt; Previous
      &lt;/a&gt; |
  &lt;?php else: ?&gt;
      &lt;span class="disabled"&gt;&amp;lt; Previous&lt;/span&gt; |
  &lt;?php endif; ?&gt;
  
  &lt;!-- Numbered page links --&gt;
  &lt;div id="numberedPages"&gt;
  &lt;?php foreach ($this-&gt;pagesInRange as $page): ?&gt;
      &lt;?php if ($page != $this-&gt;current): ?&gt;
          &lt;a href="&lt;?php echo $this-&gt;url(array('page' =&gt; $page)); ?&gt;"&gt;
          &lt;?php echo $page; ?&gt;
          &lt;/a&gt; |
      &lt;?php else: ?&gt;
          &lt;?php echo $page; ?&gt; |
      &lt;?php endif; ?&gt;
  &lt;?php endforeach; ?&gt;
  &lt;/div&gt;
  &lt;!-- Next page link --&gt;
  &lt;?php if (isset($this-&gt;next)): ?&gt;
      &lt;a id="next" href="&lt;?php echo $this-&gt;url(array('page' =&gt; $this-&gt;next)); ?&gt;" &gt;
      Next &amp;gt;
      &lt;/a&gt;
  &lt;?php else: ?&gt;
      &lt;span id="next" class="disabled"&gt;Next &amp;gt;&lt;/span&gt;
  &lt;?php endif; ?&gt;
  &lt;/div&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>I figured that since the next page selector on the last page is disabled it would stop when it hit the last page. Why does it keep loading the last page over and over again and how can I stop it from happening?</p>
  
  <p>EDIT:</p>
  
  <p>I added an if check to the callback function to try to stop the scroll after a while, inspired by this question <a href="https://stackoverflow.com/questions/9352389/jquery-infinitescroll-plugin-loads-the-last-page-over-and-over">jQuery InfiniteScroll plugin loads the last page over and over</a>. </p>
  
  <pre><code>//See if this is the last page
  if( curPage &gt;= pages ){
      alert("Infinite scroll is paused.");
      $('#grid').infinitescroll('pause');
  }
  </code></pre>
  
  <p>Where pages is defined as the last page available and curPage is the current page, incremented each call. The check was working perfectly at one point, but I changed something, I'm not sure what, and now for some reason now I'm getting the error <code>$("#grid").infinitescroll is not a function
  $('#grid').infinitescroll('pause');</code> I have no idea how infinite scroll is not a function at that point when it clearly had to be for javascript to get to it in the first place. How can I get rid of this not a function error?</p>