{% set parameters = "" %}
{% set chaineTri = "" %}
{% for keyParameter, viewParameterValue in ezpublish.viewParameters %}
    {% if keyParameter == 'recherche' %}
        {% set parameters = parameters ~ "/(" ~ keyParameter ~ ")/" ~ viewParameterValue %}
    {% elseif keyParameter == 'tri' %}
        {% set chaineTri = '/(tri)/' ~ viewParameterValue %}
    {% endif %}
{% endfor %}
{#<div class="chargement" id="last_msg_loader">
    <img src="{{ asset('bundles/ayalineezsit/images/ajax-loader.gif') }}" alt="" /> <span>Chargement de {{ content.getFieldValue('nb_items_par_page').text }} résultats suivants</span>
</div>#}
{#<input type="hidden" value="1" id="offset" name="offset">#}

<script type="text/javascript" >
    /****Lazy loadind****/
    var loading=0;
    $(document).ready(function(){
        $('div#last_msg_loader').hide();
        function last_msg_funtion(){
            var offset = parseInt($("#offset").val(), 10);
            offset += 1;
            $("#offset").val(offset);
            $('div#last_msg_loader').show();
            console.log("test");
            var parameters = '{{ parameters }}';
            var chaineTri = '{{ chaineTri }}';
            var postQuery = "/lazyloading" + parameters + "/(page)/" + offset + "/(locationId)/{{ location.id }}" + chaineTri;

            $.post(postQuery).done(
                function(data){
                    if (data != "") {
                        $(".xsl-liste").append(data);
                    }
                    $('div#last_msg_loader').hide();
                    loading=0;
            });
        }

        $(window).scroll(function(){
            var height = $(document).height() - $("footer").height() - $(".suivre").height() - $("#mapContainerListe").height() - $(window).height();
            if (loading == 0 && $(window).scrollTop() >= height ){
                loading=1;
                last_msg_funtion();
            }
        });
    });
</script>
