$().ready(function(){
	
	function scroll(direction){
		 var scrollobj, i, positions = [], here = $(window).scrollTop(), collection = $('.postblock');

        collection.each(function() {
            positions.push(parseInt($(this).offset()['top'],10));
        });
		
        for(i = 0; i < positions.length; i++) {
			if(direction == 'gotopost_next' && positions[i] > here) { scrollobj = collection.get(i); break; }
            if(direction == 'gotopost_prev' && i > 0 && positions[i] >= here) { scrollobj = collection.get(i-1); break; }
        }
		
		if (scrollobj) {
			$('html, body').stop().animate({ scrollTop: $(scrollobj).offset()['top'] }, 120);
		}
		return false;
	}
		
	$("#gotopost_next").click(function(){
		return scroll($(this).attr('id'));
	});
	
	$("#gotopost_prev").click(function(){
		return scroll($(this).attr('id'));
	});
	
	$("#gotopost_top").click(function(){
		$('html, body').stop().animate({ scrollTop: 0 }, 120);
	});
	
});
