<?php
/*
Template Name: Thinkpieces
*/
global $post;
$people = thinkplace::getPeopleAuthors();

$metadata		= get_post_custom($post->ID);
$extraBodyClass	= get_the_title($post->post_parent);
$ancestorPostId	= $post->ID;
if (! empty($post->ancestors)){
	$ancestorPostId	= $post->ancestors[ count($post->ancestors) -1];
}
get_header();
?>

<?php /**
* A pagination function
* @param integer $range: The range of the slider, works best with even numbers
* Used WP functions:
* get_pagenum_link($i) - creates the link, e.g. http://site.com/page/4
* previous_posts_link(' « '); - returns the Previous page link
* next_posts_link(' » '); - returns the Next page link
*/
function get_pagination($range = 4){
  // $paged - number of the current page
  global $paged, $wp_query;
  // How much pages do we have?
  if ( !$max_page ) {
    $max_page = $wp_query->max_num_pages;
  }
  // We need the pagination only if there are more than 1 page
  if($max_page > 1){
    if(!$paged){
      $paged = 1;
    }
    // On the first page, don't put the First page link
    if($paged != 1){
      echo "<a href=" . get_pagenum_link(1) . "> First </a>";
    }
    // To the previous page
    previous_posts_link(' « ');
    // We need the sliding effect only if there are more pages than is the sliding range
    if($max_page > $range){
      // When closer to the beginning
      if($paged < $range){
        for($i = 1; $i <= ($range + 1); $i++){
          echo "<a href='" . get_pagenum_link($i) ."'";
          if($i==$paged) echo "class='current'";
          echo ">$i</a>";
        }
      }
      // When closer to the end
      elseif($paged >= ($max_page - ceil(($range/2)))){
        for($i = $max_page - $range; $i <= $max_page; $i++){
          echo "<a href='" . get_pagenum_link($i) ."'";
          if($i==$paged) echo "class='current'";
          echo ">$i</a>";
        }
      }
      // Somewhere in the middle
      elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
        for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){
          echo "<a href='" . get_pagenum_link($i) ."'";
          if($i==$paged) echo "class='current'";
          echo ">$i</a>";
        }
      }
    }
    // Less pages than the range, no sliding effect needed
    else{
      for($i = 1; $i <= $max_page; $i++){
        echo "<a href='" . get_pagenum_link($i) ."'";
        if($i==$paged) echo "class='current'";
        echo ">$i</a>";
      }
    }
    // Next page
    next_posts_link(' » ');
    // On the last page, don't put the Last page link
    if($paged != $max_page){
      echo " <a href=" . get_pagenum_link($max_page) . "> Last </a>";
    }
  }
}
?>
            
		<div id="content" role="main">
            <div id="thinkpieces">
            <h1>Thinkpieces</h1>
				<?php if (have_posts()) : ?>
                    <?php query_posts('cat=7'); ?>
                    <?php while (have_posts()) : the_post(); ?>
                        <div>
                            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                            <p class="date"><span><?php the_time('F jS, Y') ?></span> - By
                              <?php echo '<a href="'.get_bloginfo('url').'/about/the-team/?person_id='.$people[get_the_author_meta('ID')].'">';?><?php the_author(); ?></a>
                              </p>
                            <p><?php the_advanced_excerpt() ?></p>
                        </div>
                    <?php endwhile; ?>
                    
                        <!-- <ul class="paging">
              <?php get_pagination(); ?>
                        </ul> -->
                    
                    
                    <div class="navigation">
                        <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
                        <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
                    </div>
            
                <?php else : ?>
            
                    <h2 class="center">Not Found</h2>
                    <p class="center">Sorry, but you are looking for something that isn't here.</p>
                    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
            
                <?php endif; ?>
                
                
            </div>
		</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>