$(document).ready(function(){
	
	// Init Post Scrolling
	posts.init(10, 0);
	
});


// Sidebar Post Scrolling

var posts = {
	post_offset: 0,
	post_limit: 10,
	next: function(){
		offset = posts.post_offset+posts.post_limit;
		
		did_save = posts.get( posts.post_limit, offset );
		if(did_save){
			posts.post_offset = offset;
		}else{
			$(".blog_list .more").fadeOut('800');
		}
		$(".blog_list .less").fadeIn('800');
	},
	prev: function(){
		offset = posts.post_offset-posts.post_limit;
		if(offset <= 0){
			offset = 0;
		}

		did_save = posts.get( posts.post_limit, offset );
		if(did_save){
			posts.post_offset = offset;
		}else{
			$(".blog_list .less").fadeOut('800');
		}
		$(".blog_list .more").fadeIn('800');
	},
	get: function(limit, offset){
		$.ajax({
			url: base_url+'blog/ajax_load_more_post/'+limit+'/'+offset,
			type: "post",
			dataType: "html",
			success: function(response) {
				if(response){
					posts.save(response);
					return true;
				}
				return false;
			}
		});
	},
	save: function(content){
		$(".blog_list_container ul").fadeOut('800', function () {
			$(this).html(content).fadeIn('800');
		});
	},
	init: function(limit, offset){
		posts.post_limit 	= limit || posts.post_limit;
		posts.post_offset 	= offset || posts.post_offset;
		if(posts.post_offset == 0){
			$(".blog_list .less").hide();
		}
	}
	
};