<?php
/**
 * Template Name: Home
 *
 * A custom page template for our home page
 *
 * @package WordPress
 * @subpackage ThinkPlace
 * @since ThinkPlace 1.0
 */
global $post;
$metadata		= get_post_custom($post->ID);
global $extraBodyClass;
$ancestorPostId	= $post->ID;
// Get list of people-to-authors
$people = thinkplace::getPeopleAuthors();

if (! empty($post->ancestors)){
	$ancestorPostId	= $post->ancestors[ count($post->ancestors) -1];
}
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php
	/*
	 * Print the <title> tag based on what is being viewed.
	 * We filter the output of wp_title() a bit -- see
	 * thinkplace_filter_wp_title() in functions.php.
	 */
	wp_title( '|', true, 'right' );

	?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css" type="text/css" media="screen" />
<!--[if lte IE 6]>
	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie6.php" type="text/css" media="screen" />
<![endif]-->
<!--[if IE 7]>
	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie7.php" type="text/css" media="screen" />
<![endif]-->
<!--[if IE 8]>
	<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie8.php" type="text/css" media="screen" />
<![endif]-->
<?php
	

	/* Always have wp_head() just before the closing </head>
	 * tag of your theme, or you will break many plugins, which
	 * generally use this hook to add elements to <head> such
	 * as styles, scripts, and meta tags.
	 */
	wp_head();
?>
</head>

<body <?php body_class($extraBodyClass); ?>>
<div id="header-wrapper" class="hfeed">
	<div id="header">
		<div id="masthead">
			<div id="branding" role="banner">
                <ul class="utility-nav">
                    <li><a href="<?php echo get_permalink(13); ?>">Contact</a></li>
                    <li><a href="<?php echo get_permalink(306); ?>">Careers</a></li>
                    <li>Download
                    	<ul>
                            <li class="first"><a href="<?php echo get_permalink(665); ?>">Factsheet</a></li>
                            <li><a href="<?php echo get_permalink(316); ?>">Services</a></li>
                        </ul></li>
                </ul><!--utility-nav-->
				<?php $heading_tag = ( is_home() || is_front_page() ) ? 'h1' : 'div'; ?>
				<<?php echo $heading_tag; ?> id="site-title">
						<a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
				</<?php echo $heading_tag; ?>>
				<?php
					if ((isset($metadata[thinkplace::$prefix.'byline'])) && (! empty($metadata[thinkplace::$prefix.'byline'][0]) )){
							echo '<div class="page-byline">'.$metadata[thinkplace::$prefix.'byline'][0].'</div>';
					}
				?>
                </div><!--branding -->
                <div id="access" role="navigation">
                  <?php /*  Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff */ ?>
                    <div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'thinkplace' ); ?>"><?php _e( 'Skip to content', 'thinkplace' ); ?></a>
                    </div>
                    <?php /* Our navigation menu.  If one isn't filled out, wp_nav_menu falls back to wp_page_menu.  The menu assiged to the primary position is the one used.  If none is assigned, the menu with the lowest ID is used.  */ ?>
                    <div id="nav">
                        <ul>
                            <?php wp_list_pages('child_of=0&title_li=&depth=2&sort_column=menu_order&exclude=13,25,306,312');?>
                        </ul>
                    <div id="header-bg"></div>
                    </div>
                </div><!--access -->
            </div><!--masthead--> 
            <div id="content-head">
			<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
                <div id="overview">
                    <h1>What we can do for you</h1>
                </div>
                <?php the_content(); ?>
            </div><!--content_head -->
	</div><!--header -->
</div><!--header-wrapper-->
<div id="wrapper" class="hfeed">
	<div id="content-container">

		<div id="content" role="main">
            <?php edit_post_link( __( 'Edit', 'thinkplace' ), '<span class="edit-link">', '</span>' ); ?>
            <?php endwhile; ?>
            <div id="thinkpieces">
                <h1>What we're thinking...</h1>
				<?php
					if ((isset($metadata[thinkplace::$prefix.'Overview'])) && (! empty($metadata[thinkplace::$prefix.'Overview'][0]) )){
							echo 
				'<div class="intro"><p>'.$metadata[thinkplace::$prefix.'Overview'][0].'</p></div>';
					}
				?>
				<?php $temp_query = $wp_query; ?>
                <?php query_posts('cat=7&showposts=4'); ?>
                        <?php while (have_posts()) : the_post(); ?>
                    		<div>
                            <h2><a href="<?php the_permalink(); ?>" title="<?php the_permalink(); ?>" rel="bookmark"><?php the_title() ?></a></h2>
                            <p class="date"><span><?php the_date(); ?></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; ?>
            </div>
            <div id="extra-sidebar">
            	<div id="latest-links">
                	<h2>Latest papers from Thinkplace</h2>
					<?php $temp_query = $wp_query; ?>
                    <?php $args	= array(
                  				'numberposts'	=> 1,
                  				'post_type' 	=> 'papers',
                  				'showposts'		=> 6
                  				);
                  	$papersQuery = new WP_Query($args); ?>
						<ul>
						<?php while ($papersQuery->have_posts()) : $papersQuery->the_post(); ?>
                            <li><a href="<?php echo get_bloginfo('url') . '/ideas/papers-and-presentations/?paper_id='.get_the_ID(); ?>" title="<?php the_permalink(); ?>" rel="bookmark"><?php the_title() ?></a></li>
                        <?php endwhile; ?>
                        </ul>
                </div>
            </div>
        </div><!-- #content -->
            
 		<div id="sidebar">
            <div id="twitter">
                <ul id="twitter_update_list">
                	<li>&nbsp;</li>
                </ul>
            </div><!--related-links-->
            <div id="tag-cloud">
                <h2>Tag cloud</h2>
                <?php wp_tag_cloud('smallest=8&largest=14&number=50'); ?>
            </div><!--tag-cloud-->
        </div><!--sidebar-->
	</div> <!--content-container-->
            <?php get_footer(); ?>