<?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the wordpress construct of pages
 * and that other 'pages' on your wordpress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage ThinkPlace
 * @since ThinkPlace 1.0
 */
global $post;
$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();
?>
    <div id="content" role="main">
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>		
      <?php
                $breadcrumb = '<span class="active">'.get_the_title().'</span>';
                foreach ($post->ancestors as $bc_ancestor_id){
                    $breadcrumb	= '<span><a href="'.htmlentities(get_page_link( $bc_ancestor_id )).'">'.get_the_title($bc_ancestor_id).'</a> &nbsp; &gt;</span> '.$breadcrumb;
                }
                $breadcrumb	= '<span><a href="'.home_url( '/' ).'">Home</a> &nbsp; &gt;</span> '.$breadcrumb.'';
                echo '<div class="breadcrumbs">'.$breadcrumb.'</div>';
            ?>
            <h1><?php the_title(); ?></h1>
				<div class="page-images">
				  <?php
	        $image1Src = wp_get_attachment_image_src( $metadata[thinkplace::$prefix.'image'][0], 'services-thumb' );
	        $image1Metadata	= wp_get_attachment_metadata( $metadata[thinkplace::$prefix.'image'][0] );
	        $image2Src = wp_get_attachment_image_src( $metadata[thinkplace::$prefix.'image_2'][0], 'services-thumb' );
	        $image2Metadata	= wp_get_attachment_metadata( $metadata[thinkplace::$prefix.'image_2'][0] );
	        $image3Src = wp_get_attachment_image_src( $metadata[thinkplace::$prefix.'image_3'][0], 'services-thumb' );
	        $image3Metadata	= wp_get_attachment_metadata( $metadata[thinkplace::$prefix.'image_3'][0] );

	        if ((! empty($metadata[thinkplace::$prefix.'image'][0]) && !is_page('212') && !is_page('319') )){
	          echo "<img src='".$image1Src[0]."' height='".$image1Src[2]."' width='".$image1Src[1]."' alt='".$image1Metadata['image_meta']['title']."' />";
	        }
	        if ((! empty($metadata[thinkplace::$prefix.'image_2'][0]) && !is_page('212') && !is_page('319') )){
	          echo "<img src='".$image2Src[0]."' height='".$image2Src[2]."' width='".$image2Src[1]."' alt='".$image2Metadata['image_meta']['title']."' class='image-2' />";
	        }
	        if ((! empty($metadata[thinkplace::$prefix.'image_3'][0]) && !is_page('212') && !is_page('319') )){
	          echo "<img src='".$image3Src[0]."' height='".$image3Src[2]."' width='".$image3Src[1]."' alt='".$image3Metadata['image_meta']['title']."' />";
	        }

				  ?>
				</div>
				<?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>';
					}
				?>
			<div class="general-content">
        <?php the_content(); ?>
			</div>
			
        <?php
        if (!is_page('212') || !is_page('319')) ?>  
          <?php
          global $post;     // if outside the loop
          if ( is_page() && $post->post_parent ) {
            // This is a subpage
          } else { ?>
            <div id="page-nav">
            <?php
              $mypages = get_pages('child_of='.$post->ID.'&parent='.$post->ID.'&sort_column=menu_order&sort_order=asc');
              foreach($mypages as $key => $page)
              { 
                $custom_fields = get_post_custom($page->ID);
                ?>
                <div class="page-nav-wrapper <?php if($key % 2 == 0) echo 'clear'; ?>">
                  <h2>
                    <a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>
                  </h2>
                  <div class="descrip"><?php echo '<p>'.$custom_fields[thinkplace::$prefix.'Nav'][0].'</p>'; ?></div>
                  <?php
                    $children = get_pages('child_of='.$page->ID.'&parent='.$page->ID.'&sort_column=menu_order&sort_order=asc');
                    if(count($children) > 0) {
                      echo '<ul class="children">';
                      foreach($children as $child) {
                        echo '<li><a href="'.get_page_link($child->ID).'">'.$child->post_title.'</a></li>';
                      }
                      echo '</ul>';
                    }
                  ?>
                </div><!-- .page-nav-wrapper -->
              <?php
              }
              ?>
            </div>
          <?php
          } ?>
          <br /
          ><br />
            
			<?php edit_post_link( __( 'Edit', 'thinkplace' ), '<span class="edit-link">', '</span>' ); ?>
            <?php endwhile; ?>
		</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>