﻿$(document).ready(function(){
$(window).scroll(function(){
 if ($(window).scrollTop() == $(document).height() - $(window).height()){
 loadContent();
 }
});

var flag=0;
var a=0;
function loadContent() {

if (flag==0){
a++;
var link="http://goldworld.kh.ua/st/example-comments-padge"+a+".html";

var cont = document.getElementById('contentDiv');


var http = createRequestObject();// Создаём объект для связи с сервером
    http.caching = false; //кешируем или не кешируем загружаемую инфу
	if (http.overrideMimeType) { 
        http.overrideMimeType('text/html; charset=utf-8');// Устанавливаем тип содержимого и кодировку
        //http.overrideMimeType('text/plain; charset=utf-8');
        //http.overrideMimeType('text/xml; charset=utf-8');
    }
if( http ) 
{
	http.open('get', link, true); // Открываем соединение
	http.onreadystatechange = function () 
{
		if(http.readyState == 4) {// Если ответ получен
		  if (http.status == 200) {// и если все нормально, то 
			var text=http.responseText;
		    var  s=text.search("Not found");
			if (s==-1){
			document.getElementById('logimg').style.display = 'block';
            cont.innerHTML =cont.innerHTML+http.responseText; // Вствляем полученные от сервера данные в блок на нашей странице
		jQuery('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
		}
			else {flag=1;
					document.getElementById('logimg').style.display = 'none';	
						}    	
          } else {
            flag=1;
			document.getElementById('logimg').style.display = 'none';
          }    
		}
	}
	http.send(null);  // Отправляем запрос серверу   
}
else 
{
	document.location = link;
}
}

}
// создание ajax объекта
function createRequestObject() 
{
try { return new XMLHttpRequest() }
catch(e) 
{
	try { return new ActiveXObject('Msxml2.XMLHTTP') }
	catch(e) 
	{
		try { return new ActiveXObject('Microsoft.XMLHTTP') }
		catch(e) { return null; }
	}
}
}


});
