<div class="feedFacebookWall clearfix img-rounded">
  <h4 class="img-rounded">What's New on<a href='<?php echo FACEBOOK_URL;?>'><img src='/Kickstrap/img/FacebookLogos.png' width='65' style='margin:-6px 0 0 10px; display: inline-block;' alt="Facebook Logo"/></a></h4>
  <a class="fb-control left" href="#" data-slide="prev">&lsaquo;</a>
  <a class="fb-control right" href="#" data-slide="next">&rsaquo;</a>
  <div id="facebookWall">
  </div>
</div>

<script src="https://afsshareportal.com/js/moment.min.js"></script>
<script src="/js/jquery.neosmart.fb.wall.js" type="text/javascript"></script>
<?php
  $allFBTokens = json_decode(file_get_contents('https://afsshareportal.com/inc/usableFBTokens.php'));
  $feedID = "169094599865515";
  $feedToken = isset($allFBTokens->{$feedID}->token) ? $feedToken = $allFBTokens->{$feedID}->token : "";
?>
<script>
  $(document).ready(function(e) {
	var myInterval = setInterval(function(){
	  $(".fb-content-hide").unbind().bind("click", function(e){
		  e.preventDefault();
		  var $this =	$(this);
		  var theContent = $this.siblings(".fb-wall-data, .fb-wall-media").toggleClass("hideObject");
		  var theText = $this.text() == "Hide this post" ? "View this post" : "Hide this post";
		  $this.text(theText);
	  });
	  
	  if($(".fb-wall-box").length < 1){
		$(".fb-control").addClass("hideObject");
	  }else{
		$(".fb-control.left").removeClass("hideObject");
		$(".fb-control.right").addClass("hideObject");
	  }
	}, 1000);
	
	$('.fb-control').on("click", function(e){
	  e.preventDefault();
	  var $thePosts = $(this).siblings("#facebookWall");
	  var theIndex = $thePosts.children().not(".hideObject").index();
	  var total = $thePosts.children().length;
	  
	  
	  if($(this).is(".left")){
		var shouldHide = (theIndex + 2) < total ? false : true;
		if(shouldHide){
		  $(".fb-control.left").addClass("hideObject");
		}else{
		  $(".fb-control.right").removeClass("hideObject");
		}
		var next = (theIndex + 1) < total ? theIndex + 1 : theIndex;
	  }else{
		var shouldHide = (theIndex - 2) < 0 ? true : false;
		if(shouldHide){
		  $(".fb-control.right").addClass("hideObject");
		}else{
		  $(".fb-control.left").removeClass("hideObject");
		}
		var next = (theIndex - 1) >= 0 ? theIndex - 1 : theIndex;
	  }
	  
	  $thePosts.children().eq(theIndex).addClass("hideObject");
	  $thePosts.children().eq(next).removeClass('hideObject');
	  
	  //console.log("shouldHide: " + shouldHide + "\ntotal: " + total + "\nthe index is: " + theIndex + "\nnext: " + next);
	});
	
	setTimeout(function(){
		clearInterval(myInterval);
	}, 7000);
  });
	
  $(function(){
	  $('#facebookWall').fbWall({ id:'<?php echo $feedID ?>',accessToken:'<?php echo $feedToken ?>'});
  });
    
</script>
