var block1 = document.getElementById('infinite-scroll');
var timeout1;
block1.addEventListener("scroll", function(){
    if (timeout1 != null) {
    clearTimeout(timeout1)};
    timeout1 = setTimeout(scroll__load, 500)});
scroll__load = function(){
        var blockheight = block1.offsetHeight;
        var contentheight = block1.scrollHeight;      // 1) высота блока контента вместе с границами
        var scrolltop       = block1.scrollTop;      // 2) текущее положение скролбара
        var y             = contentheight - scrolltop;
        
        // если пользователь достиг конца
        if(y <= blockheight * 1.5)
        {
            //загружаем новое содержимое в элемент
            scroll_load();
        }
 };
 var i = 32;
 var i_old;
 scroll_load = function() {
    if (i_old != i) {
        console.log(i);
        var params = 'zapros='+i+'';
        var xmlHttp = new XMLHttpRequest();
            xmlHttp.onreadystatechange = function() {
                if(xmlHttp.readyState == 4 && xmlHttp.status == 200)    {
                    block1.insertAdjacentHTML('beforeend', xmlHttp.responseText);
                    i_old = i;
                    i = i+6;
                    filtrus();
                }
            }
            xmlHttp.open("POST", "php/scroll__load.php");
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlHttp.send(params);
    }
} 
  
  if (timeout != null) {
  clearTimeout(timeout);
}let timeout = null;
if (timeout != null) {
  clearTimeout(timeout);
}
open__kod__timer = function () {open__kod = 1};
timeout = setTimeout(open__kod__timer, 1000);setTimeout(open__kod__timer, 1000)};const block1 = document.getElementById('infinite-scroll');
let timeout1 = null;
let i = 32;
let isLoading = false;
let isEmpty = true;
function scroll__load() {
  const blockheight = block1.offsetHeight;
  const contentheight = block1.scrollHeight;
  // Высота невидимой, прокрученной в данный момент, части элемента сверху
  const scrolltop = block1.scrollTop;
  const y = contentheight - scrolltop;
  // «Схлопнутый» элемент, например пустой div без высоты и ширины, будет считаться невидимым. И offsetHeight 0
  // Но сделаем проверку на пустоту элемента надежной
  // если пользователь достиг конца
  if (isEmpty || y <= blockheight * 1.5) {
    //загружаем новое содержимое в элемент
    scroll_load();
  }
}
function filtrus() {
  console.log(filtrus.name)
}
function scroll_load() {
  if (!isLoading) {
    isLoading = true;
    console.log(i);
    const params = 'zapros=' + i + '';
    const xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() {
      if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
        block1.insertAdjacentHTML('beforeend', xmlHttp.responseText);
        i = i + 6;
        isLoading = false;
        isEmpty = false;
        filtrus();
      }
    };
    xmlHttp.open('POST', 'php/scroll__load.php');
    xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlHttp.send(params);
  }
}
block1.addEventListener('scroll', function() {
  if (timeout1 != null) {
    clearTimeout(timeout1);
  }
  timeout1 = setTimeout(scroll__load, 500);
});var block1 = document.getElementById('infinite-scroll');
var i = 32;
var i_old;
var scrolltop__old = 0;
scroll_load = function() {
    if (i_old != i) {
        i_old = i;
//        console.log(i);
        var params = 'zapros='+i+'';
        var xmlHttp = new XMLHttpRequest();
            xmlHttp.onreadystatechange = function() {
                if(xmlHttp.readyState == 4 && xmlHttp.status == 200)    {
                    block1.insertAdjacentHTML('beforeend', xmlHttp.responseText);
                    i = i+6;
                    filtrus();
                }
            }
            xmlHttp.open("POST", "php/scroll__load.php");
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlHttp.send(params);
    }
}
scroll__load = function(){
    var contentheight = block1.scrollHeight;      // 1) высота блока контента вместе с границами
    var scrolltop = block1.scrollTop;      // 2) текущее положение скролбара
    var y = contentheight - scrolltop;
    
    // если пользователь достиг конца
    if(scrolltop > contentheight*0.5 && scrolltop > scrolltop__old) {
//        console.log(''+scrolltop+' > '+contentheight*0.5+''+'----'+scrolltop__old+'');
        scrolltop__old = scrolltop;
        //загружаем новое содержимое в элемент
        scroll_load();
    }
};
if (document.getElementById('infinite-scroll') != null) {
block1.addEventListener("scroll", scroll__load);
}; 
             
            