<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package WordPress
 * @subpackage ThinkPlace
 * @since ThinkPlace 1.0
 */
global $metadata;
global $post;
global $extraBodyClass;
$ancestorPostId	= $post->ID;
if (! empty($post->ancestors)){
	$ancestorPostId	= $post->ancestors[ count($post->ancestors) -1];
}

// Default metadata
$keywords	= "thinkplace";
$metadesc	= "Bridging vision and reality.";

?><!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>
<meta name="keywords" content="<?php echo (isset($metadata[thinkplace::$prefix.'keywords'][0]) && (! empty($metadata[thinkplace::$prefix.'keywords'][0]))) ? $metadata[thinkplace::$prefix.'keywords'][0] : $keywords;  ?>">
<meta name="description" content="<?php echo (isset($metadata[thinkplace::$prefix.'metadesc'][0]) && (! empty($metadata[thinkplace::$prefix.'metadesc'][0]))) ? $metadata[thinkplace::$prefix.'metadesc'][0] : $metadesc;  ?>">
<link rel="profile" href="http://gmpg.org/xfn/11" />

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/print.css?v=1" type="text/css" media="print" />
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css?v=1" 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 id="content-head">
                    
                <?php         
					$title = get_the_title($post->post_parent);
				 	foreach((get_the_category()) as $category);
				
					if ( is_single()) {
						// This is a single post
						echo '<h1>'. $category->cat_name .'</h1>';
					} else if ( is_tag() ) {
            // Name for tag. Pulled directly from the $wp_query object because WP is stupid
					  echo '<h1>'.$wp_query->queried_object->name.'</h1>';
				  } else {
					   // This is all other pages
						echo '<h1>'.$title.'</h1>';
					}
				?>
                <div class='nav'>
                    <ul>
                    <?php
                    if(isset($ancestorPostId)) {
                      wp_list_pages('child_of='.$ancestorPostId.'&title_li=&depth=1&sort_column=menu_order');
                    }
                    ?>
                
                    </ul>
                </div>
            </div><!-- #content_head -->
		</div><!-- #masthead -->
	</div><!-- #header -->
</div><!--header-wrapper-->
<div id="wrapper" class="hfeed">
	<div id="content-container">