if (!(typeof post_per_page === 'undefined' || typeof items === 'undefined') ) {   	
    var posts = parseInt(load_galleries);
	jQuery.each(items,function(i){		
        if(i < posts )
        {		
            jQuery('#portfolio-items').append(items[i]);           
        }
    });   	 
}

jQuery(document).ready(function($){
    if (typeof items === 'undefined') return false;
    if (typeof load_galleries === 'undefined') return false;
    if (typeof post_per_page === 'undefined') return false;   
   
    $('#load-more-works1').click(function(){
        $(this).html('<i class="icon-spinner icon-spin icon-3x"></i>');
		var from_page = '#portfolio-items';
        var load_more_btn = $(this).attr('id');
        load_works1(from_page, load_more_btn);
    });
	
});

if (!(typeof post_per_page === 'undefined' || typeof items1 === 'undefined') ) {   
    var posts = parseInt(load_galleries);
	jQuery.each(items1,function(i){		
        if(i < posts ){		
            jQuery('#portfolio2-items').append(items1[i]);           
        }
    });   	 
}

jQuery(document).ready(function($){
    if (typeof items1 === 'undefined') return false;
    if (typeof load_galleries === 'undefined') return false;
    if (typeof post_per_page === 'undefined') return false;   
   
    $('#load-more-works2').click(function(){
        $(this).html('<i class="icon-spinner icon-spin icon-3x"></i>');
		var from_page = '#portfolio2-items';
        var load_more_btn = $(this).attr('id');
        load_works1(from_page, load_more_btn);
    });
	
});
var paged_ = 1;
var loadgallerypost = true;
function load_works1(from_page, load_more_btn)
{	
	
    var load_more_btn = load_more_btn;
	if(loadgallerypost){
    var num_of_posts = parseInt(load_galleries); 
		var data = {
                "action" : "loadmore_works1",               
				"paged_" : paged_  ,
				"num_of_posts": num_of_posts,
				"from_page":from_page
            };
		jQuery.post(ajax_url,data,function(data){
			var d = jQuery.parseJSON(data);
			if(d.length!=0){
			var item = '';
			$.each(d,function(i,val){
				item += val;
			})
		$container = $(from_page);
		var $newItem = $(item);
		console.log($newItem);
        //setTimeout(function(){
            imagesLoaded($newItem, function() {
                $container.isotope( 'insert', $newItem);
            });
        //},500)
		if(maxNumPages == paged_){
			$("#" + load_more_btn).css("display", "none");
		}
		
		}
		else{
			loadgallerypost = false;
		}
    })
        .done(function(){
		
			if(loadgallerypost){
				$("#" + load_more_btn).html('LOAD <br> MORE </br>...');
				}
			else{
				$("#" + load_more_btn).css("display", "none");
			}
        });
	paged_ = paged_ +1;				
	}
	else{
		$("#" + load_more_btn).css("display", "none");
	}
}
