
$(document).ready(function(){
//jQuery(function(){
  
  var loading = false;	
  $('#footer-wrap').hide();
   
	function lastAddedLiveFunc() 
	{ 
		
		loading = true;
		
		$('div#lastPostsLoader').html("<img src='./inc/images/loading.gif' />");
		
		var lastId=$("div#div-guestbook-items > blockquote:last").attr("id");
		$.ajax({
        type: "POST",
        url: "./inc/ajax_function.php",
        data: "f=getGuestBookItem&start="+lastId,
        success: function(msg)
        {
         if (msg=="") 
            {
            $('div#lastPostsLoader').html("Odczytano wszystkie opinie.");			       
            $('#footer-wrap').fadeIn('slow');            
            }  
         else
            {
            $("div#div-guestbook-items > blockquote:last").after(msg);			       
            $('div#lastPostsLoader').empty();
            //pokazanie stopki w ff
            if ($("div#div-guestbook-items > blockquote:last").attr("id")==1)
                {
                $('#footer-wrap').fadeIn('slow');                       
                loading=true;
                }
            }   
        },
        complete: function()
        {
        loading=false;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown)
        {
          $("div#div-guestbook-items > blockquote:last").after('Error-> o: '+XMLHttpRequest+' k: '+textStatus+' r: '+ errorThrown);
        }
      }); 
	
	};  
	
	$(window).scroll(function(){
      if (($(window).scrollTop() > $(document).height() - $(window).height() - 2)  && !loading)
      //if (!loading && $(document).scrollHeight-$(document).scrollTop-$(document).offsetHeight<$(document).offsetHeight)
      {      
		  lastAddedLiveFunc();
		  }
	}); 

});


