var addContent = {
	start: 5,
	init: function(){
		$(window).bind('scroll', addContent.update);
		$(".previous").hide();
	},
	pageSize: function(){
		return document.getElementsByTagName('body')[0].offsetHeight;
	},
	scrollOffset: function(){
		var viewportheight = 0;
		var scroll = 0;
		if (typeof window.innerWidth != 'undefined') {
			viewportheight = window.innerHeight;
		} else {
			viewportheight = document.documentElement.clientHeight + document.documentElement.scrollTop;
		}
		if ( self.pageYOffset ){
			scroll = self.pageYOffset;
		} else if( document.body.scrollTop ) {
			scroll = document.getElementsByTagName('body')[0].scrollTop;
		} else if( document.documentElement.scrollTop ) {
			scroll = document.documentElement.scrollTop;
		}
		return (viewportheight + scroll);
	},
	update: function(e){
		if(addContent.scrollOffset() > (addContent.pageSize() - 250)){
			addContent.getMore();
		}
	},
	getMore: function(){
		$(window).unbind('scroll', addContent.update);
		$.get(
			"/mumblings/more", 
			{ start: addContent.start },
			function(data){
				$(".posts").append(data);
				addContent.start += 5;
				if(data != ''){
					$(window).bind('scroll', addContent.update);
				} else {
					$(".loading").remove();
				}
			}
		);
	}
}
$(document).ready(addContent.init);
