<?php
/**
 * Template Name: Contact
 *
 * The "Template Name:" bit above allows this to be selectable
 * from a dropdown menu on the edit page screen.
 *
 * @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	= '<a href="'.htmlentities(get_page_link( $bc_ancestor_id )).'">'.get_the_title($bc_ancestor_id).'</a> &gt; '.$breadcrumb;
                }
                $breadcrumb	= '<a href="'.home_url( '/' ).'">Home</a> &gt; '.$breadcrumb;
                echo '<div class="breadcrumbs">'.$breadcrumb.'</div>';
            ?>
            <h1><?php the_title(); ?></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>';
					}
				?>
			<div class="general-content"><?php the_content(); ?></div>
            
            
			<?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 $page)
                        { 
							$contactMetadata = get_post_custom($page->ID);
							
							$imageSrc		= wp_get_attachment_image_src( $contactMetadata[thinkplace::$prefix.'image'][0], 'full' );
							$imageMetadata	= wp_get_attachment_metadata( $contactMetadata[thinkplace::$prefix.'image'][0] );
                            echo '<div><a href="'.$page->post_name.'">
							'."<img class='thumbnail' src='".$imageSrc[0]."' height='".$imageSrc[2]."' width='".$imageSrc[1]."' alt='".$imageMetadata['image_meta']['title']."' />".'
							<span class="caption">'.$contactMetadata[thinkplace::$prefix.'Nav'][0].'</span></a></div>'
                            ; 
							?>
                        <?php } ?>
    			<?php } ?> </div>
            <br /><br />

            
            
			<?php edit_post_link( __( 'Edit', 'thinkplace' ), '<span class="edit-link">', '</span>' ); ?>
            <?php endwhile; ?>
		</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>