// endless_page.js
var currentPage = 1;

function checkScroll() {
  if (nearBottomOfPage()) {
    $('global-content-stamp').update("loading...");
    currentPage++;
    //site.serverCall('blog_posts/?page=' + currentPage,null,null);
    new Ajax.Request('/blog/?page=' + currentPage, {asynchronous:true, evalScripts: true, method:'get'});
  } else {
    endlessTimeOut = setTimeout("checkScroll()", 250);
  }
}

function nearBottomOfPage() {
  return scrollDistanceFromBottom() < 150;
}

function scrollDistanceFromBottom(argument) {
  return pageHeight() - (window.pageYOffset + self.innerHeight);
}

function pageHeight() {
  return Math.max(document.body.scrollHeight, document.body.offsetHeight);
}
document.observe('dom:loaded', checkScroll);