// JavaScript Document
$(document).ready(function() {
(function($){
  $.base_url = 'http://localhost:8888/'; // Your website name
  function grid() {
    var forEach = Array.prototype.forEach;
  var images = document.querySelectorAll('img');
  var numImages = images.length;

  // Simple lazy load
  forEach.call(images, function(img){
    var image = new Image();
    image.addEventListener('load', function() {
      if (--numImages === 0) {
        // all images loaded
        minigrid('.grid', '.grid-item', 10);
        document.querySelector('.grid').style.opacity = 1;
      }
    });
    image.src = img.src;
  });

  }
  
  function loadMore() {
    $("div.grid").append(html).each(function() {});
    grid();
  }
  
  function ajax() {
    // fake request
    setTimeout(function(){
      loadMore();
    },1300);
  }
  
    
	$('body').on("click", '.nextphotos', function() {
    var ID = $(this).attr("id");
    var P_ID = $(this).attr("rel");
    var URL = $.base_url + 'more_photos_ajax.php';
    var dataString = "lastrmid=" + ID + "&profile_id=" + P_ID;
    if (ID) {
      $.ajax({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        beforeSend: function() {
          $(".post_loader").fadeIn(200);
        },
        success: function(html) {
			setTimeout(function(){
              $("div.grid").append(html).each(function() {});
			   grid();
            },5000);
             
          $("#more" + ID).remove();
        }
      });
    } else {
      $("#more").html('The End');

    }

    return false;
  });
      
  grid();
  
})(jQuery);