﻿var itemIndex = 4; // three articles initially posted.
var pageSize = 3;
var count = 0;
var url = "/common/handlers/get-buzz.ashx?itemIndex="
var complete = true;

$(document).ready(function () {
    if ($("#buzz-list").length > 0) // make sure the element exists
        addItems();
});
$(window).scroll(function () {
    if ($("#buzz-list").length > 0) // make sure the element exists
        addItems();
});

function addItems() {
    var scrolltop = $(window).scrollTop() + 150;
    var windowtop = $(document).height() - $(window).height();
    if (scrolltop >= windowtop && complete == true) {
        complete = false;
        $.ajax({ url: url + itemIndex + "&pageSize=" + pageSize, asych: false, success: function (data) {
            $("#buzz-items").append(data);
            complete = true;
        }
        }, 'html');
        itemIndex += pageSize;        
    }
}

