<?php
  include_once($_SERVER['DOCUMENT_ROOT'] . "/admin/inc/sessionStartGeneral.php");
?>
<?php
  function strtotitle($title, $separator){
	$smallwordsarray = array('of','a','the','and','an','or','nor','but','is','if','then','else','when',	'at','from','by','on','off','for','in','out','over','to','into','with');
	
	$words = explode($separator, $title);
	
	foreach ($words as $key => $word){
	  if ($key == 0 or !in_array($word, $smallwordsarray))
	  $words[$key] = ucwords($word);
	}
	
	$newtitle = implode(' ', $words);
	
	return $newtitle;
  }
  
  $type = "more";
  $thePage = 1;
  $theDept = "Blog";
  
  if(isset($_GET['name']) && $_GET['name'] != ""){
    if($_GET['name'] == "more"){
	  $thePage = isset($_GET['more']) ? $_GET['more'] : 1;
	  $theDept = "Blog";
	  $type = "more";
	}else if($_GET['name'] == "search"){
	  $thePage = isset($_GET['more']) ? $_GET['more'] : 1;
	  $theDept = "Blog";
	  $type = "search";
	}else{
	  $theDept = strtotitle($_GET['name'], "-");
	  $type = "single";
	}
  }
  
  $pageTitle = $theDept;
  $pageDescription = "Blog Posts";
  $pageKeywords = "blog, news";
?>
<?php
  include_once($_SERVER['DOCUMENT_ROOT'] . "/common/header.php"); 
?>
<meta name="robots" content="noindex">
<script type="text/javascript" src="/admin/js/blogJS.js"></script>
<script src="//afsshareportal.com/js/moment.min.js"></script>
<link href="https://afsshareportal.com/css/wordpress.css" rel="stylesheet" type="text/css"/>
<style>
	  #mainContent .row .span12{
			width: 95%;
	  }
	  
	  #pinBtn{
		margin-left:10px;
	  }
	  
	  
	  /*TAKE THESE TO BOOTSTRAP.LESS*/
	  
	  
	  
</style>

<?php require($_SERVER['DOCUMENT_ROOT'] . '/common/mainNav.php'); ?>

    <section class="container">
      <div id="blankBuffer"></div>
      <section class="container" id="mainContent">
		<br>
		  <div class="span8 leftSide">
			<div id="blogOffset" class="clearfix">
			  <?php
				if($theDept == "Blog"){
			  ?>
				  <div id="searchContain" class="pull-right input-append">
					<input type="text" class="span3">
					<span class="add-on" id="blogSearch"><i class="icon-search"></i></span>
				  </div>
				  <h1 class="headerUnderline">Blog</h1>
				  <?php
					if($type == "search"){
				  ?>
					<div id="searchNotification">
					  <h4>You are currently viewing blog posts that contain: <b><?php echo $_GET['term']; ?></b></h4><br>
					</div>
				  <?php
					}//if($theType == "search")
				  ?>
				  <div id="allBlogPosts"></div>
				  <div id="blogNavigation"></div>
				  <script>
					var thePage = "<?php echo isset($thePage) ? $thePage : "1"; ?>";
					var theType = "<?php echo isset($type) ? $type : "all"; ?>";
					var theTerm = "<?php echo isset($_GET['term']) ? $_GET['term'] : ""; ?>";
					var numWanted = 5;
					var beginURL = "posts";
					
					if(theType == "search"){
					  getCategoryID(blogSlug, thePage, "search", theTerm, numWanted, beginURL);
					}else{
					  getCategoryID(blogSlug, thePage, "list", false, numWanted, beginURL);
					}
				  </script>
				
			  <?php
				}//end if($theDept == "Home")
				else{
			  ?>
				<div id="theBlogPost"></div>
				
				<script>
				  var theName = "<?php echo $_GET['name'] ?>";
				   
				  getOnePost(true, "posts");
				</script>
			  <?php
				}// end else (single post)
			  ?>
			  
			</div> 
		  </div>
		
		  <div class="span4 rightSide">
			<?php include($_SERVER['DOCUMENT_ROOT'] . "/includes/sidebar.php"); ?>
		  </div>
		  <!--</form>-->
	    
	    
      </section>
      
    </section>
      
    
    
    
    
    
    

  
  <script>
   
   
	  
   
   ks.ready(function() {
	  // JavaScript placed here will run only once Kickstrap has loaded successfully.
      $(".aTray:last").css("margin-right", "0");
      /*$.pnotify({
         title: 'Hello World',
         text: 'To edit this message, find me at the bottom of this HTML file.'
      });*/
   });
  </script>
  <!-- Please call pinit.js only once per page -->
  <script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
<?php require($_SERVER['DOCUMENT_ROOT'] . '/common/footer.php'); ?>
