
	var newPostBuffer = new Array();

	function checkForNewPosts()
	{
		if ( $("#addPopup").css("display") == "none" && enableLivePosts == true) {
			$.get("checkfornewpost.php", { lastID: lastID , type: liveupdatetype, lastapproveddate: lastapproveddate },
				function(resp){	

					if (resp) { 
					//New post, let's add it to the page
						//Only add it if the newest post on the page is in view to avoid being annoying
						if ( isScrolledIntoView('#posts_top') )
						{
							emptyNewPostBuffer()
							getNewPost(resp);
						}
						else { 
							//Otherwise save it for later and we'll show it when the page is scrolled back up
							newPostBuffer.push(resp);
							lastID = resp;
						}

					}
					//No new post
					else { 	
						//Check for posts in the buffer
						if ( isScrolledIntoView('#posts_top') )
						{ emptyNewPostBuffer(); }
					}
					
			});	
		}
	}
	
	
	
	
	
	function isScrolledIntoView(elem)
	{
		var docViewTop = $(window).scrollTop();
		var docViewBottom = docViewTop + $(window).height();
	
		var elemTop = $(elem).offset().top;
		var elemBottom = elemTop + $(elem).height();
	
		return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
	}
	
	
	
	
	
	function emptyNewPostBuffer()
	{
		
		for ( i=0; i<newPostBuffer.length; i++ )
		{
			getNewPost( newPostBuffer[i] );
		}
		newPostBuffer = new Array();
		
	}
	
	
	
	
	
	
	function checkForNewComments()
	{
		if ($("#commentPopup").css("display") == "none")
		{
			$.get("checkfornewcomment.php", { lastID: lastComment, postID: postID },
				function(resp){	
					resp = $.trim(resp);
					if (resp) { 
						
						getNewComment(resp);
						
						lastComment = resp; 
					}
			});	
		}
	}
	
	