﻿var CurrentPageIndex = 0;
var ContentLoadTriggered = false;
var Stop = false;

function carregaFavoritos(paramPageIndex) {
    $("#divCarregando").show();
    $.getJSON(as.c.rootUrl + "/AjaxJson/Favoritos.ashx", { ConteudoId: as.c.conteudoId, PageIndex: paramPageIndex }, function (data) {
        var htmlResultado = "";
        $.each(data, function (i, item) {
            htmlResultado += "<div style=\"padding-top:5px;padding-left:5px;float:left;width:100px;height:125px;\">";
            htmlResultado += "<a href=\"" + as.c.rootUrl + "/" + item.UsuarioLogin + "\"><img src=\"" + as.c.uploadUrl + "/comunidade/avatares/thumb-85x85-" + item.UsuarioAvatar + "\" alt=\"" + item.UsuarioPrefix + item.UsuarioUsuario + "\" width=\"85\" height=\"85\" border=\"0\" /></a><br />";
            htmlResultado += item.UsuarioPrefix + "<a href=\"" + as.c.rootUrl + "/" + item.UsuarioLogin + "\">" + item.UsuarioUsuario + "</a>";
            htmlResultado += "</div>";
        });
        if (data.length < 18)
            Stop = true;
        htmlResultado += "<br clear=\"all\" />";
        $("#divResultado").append(htmlResultado);
        ContentLoadTriggered = false;
        $("#divCarregando").hide();
    });
}

$(document).ready(function () {
    $("#divScroll").scroll(function () {
        if ($("#divScroll").scrollTop() >= ($("#divResultado").height() - $("#divScroll").height()) && ContentLoadTriggered == false && Stop == false) {
            ContentLoadTriggered = true;
            CurrentPageIndex += 1;
            carregaFavoritos(CurrentPageIndex);
        }
    });
});
