<?php
/**
 * Template Name: Team Page
 * The main template file for display page.
 *
 * @package WordPress
*/

get_template_part("lib/fallback.home.lib");

/**
*	Get Current page object
**/
$page = get_page($post->ID);

/**
*	Get current page id
**/
if(!isset($current_page_id) && isset($page->ID))
{
    $current_page_id = $page->ID;
}

if(!isset($hide_header) OR !$hide_header)
{
	get_header(); 
}

if(!isset($hide_header) OR !$hide_header)
{
?>	
</div>

<?php
	if(has_post_thumbnail($current_page_id, 'full'))
    {
        $image_id = get_post_thumbnail_id($current_page_id); 
        $image_thumb = wp_get_attachment_image_src($image_id, 'full', true);
        $pp_page_bg = $image_thumb[0];
?>
<style>
.page_caption { background: #f9f9f9 url('<?php echo $pp_page_bg; ?>') center center no-repeat; background-size: cover; }
</style>
<?php
	}
?>

<?php
if(!is_front_page())
{
?>
<div class="page_caption">
	<div class="caption_inner">
		<div class="caption_header">
			<h1 <?php if(!empty($pp_page_bg)) { ?>class="withbg"<?php } ?>><span><?php the_title(); ?></span></h1>
			<?php
			$page_description = get_post_meta($current_page_id, 'page_description', true);
			
			if(!empty($page_description))
			{
			?>
			    <div class="page_description<?php if(!empty($pp_page_bg)) { ?> withbg<?php } ?>"><?php echo $page_description; ?></div>
			<?php
			}
			?>
		</div>
	</div>
	
	<hr class="hr_page_caption"/>
</div>
<br class="clear"/>

<!-- Begin content -->
<div id="content_wrapper">

    <div class="inner">
    
    	<!-- Begin main content -->
    	<div class="inner_wrapper">
    	
    		<div class="standard_wrapper">
    	
<?php
}

} //End is not front page
?>		

    			<?php if ( (!isset($hide_header) OR !$hide_header) && have_posts() ) while ( have_posts() ) : the_post(); ?>
    	
    				<?php the_content(); break;  ?>

    			<?php endwhile; ?>
    			
    			<?php
    				//Display team member
    				$temp = $wp_query; 
					$wp_query = null; 
					$wp_query = new WP_Query(); 
					$wp_query->query('showposts=-1&post_type=team&orderby=menu_order&order=ASC');
					$key = 0;
					
			    	while ($wp_query->have_posts()) : $wp_query->the_post(); 
			        	$image_url = '';
			        	$member_ID = get_the_ID();
			    
			        	if(has_post_thumbnail($member_ID, 'portfolio3'))
			        	{
			        		$image_id = get_post_thumbnail_id($member_ID);
			        		$image_url = wp_get_attachment_image_src($image_id, 'portfolio3', true);
			        	}
			        	
			        	$last_class = '';
			        	if(($key+1) % 3 == 0)
			        	{	
			        		$last_class = ' last';
			        	}
			        	$key++;
			        	
			        	$member_position = get_post_meta($member_ID, 'member_position', true);
			        	$member_facebook = get_post_meta($member_ID, 'member_facebook', true);
			        	$member_twitter = get_post_meta($member_ID, 'member_twitter', true);
			        	$member_google = get_post_meta($member_ID, 'member_google', true);
			        	$member_linkedin = get_post_meta($member_ID, 'member_linkedin', true);
			    ?>
					<div class="one_third <?php echo $last_class; ?> member_item">
						<img src="<?php echo $image_url[0]?>" alt="" class="member_img" />
						<div class="member_item_info">
							<h4 class="member_name"><?php the_title(); ?></h4>
							<span class="member_position"><?php echo $member_position; ?></span>
							<?php the_content(); ?>
							<ul class="social_wrapper team">
						    	<?php
						    		if(!empty($member_twitter))
						    		{
						    	?>
						    	<li><a title="<?php _e( 'Contact', THEMEDOMAIN ); ?> <?php the_title(); ?> <?php _e( 'on', THEMEDOMAIN ); ?> Twitter" target="_blank" class="tipsy" href="http://twitter.com/<?php echo $member_twitter; ?>"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/team_social/twitter.png" alt=""/></a></li>
						    	<?php
						    		}
						    	?>
						    	<?php
						    		if(!empty($member_facebook))
						    		{
						    	?>
						    	<li><a title="<?php _e( 'Contact', THEMEDOMAIN ); ?> <?php the_title(); ?> <?php _e( 'on', THEMEDOMAIN ); ?> Facebook" target="_blank" class="tipsy" href="http://facebook.com/<?php echo $member_facebook; ?>"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/team_social/facebook.png" alt=""/></a></li>
						    	<?php
						    		}
						    	?>
						    	<?php
						    		if(!empty($member_google))
						    		{
						    	?>
						    	<li><a title="<?php _e( 'Contact', THEMEDOMAIN ); ?> <?php the_title(); ?> <?php _e( 'on', THEMEDOMAIN ); ?> Google+" target="_blank" class="tipsy" href="<?php echo $member_google; ?>"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/team_social/google.png" alt=""/></a></li>
						    	<?php
						    		}
						    	?>
						    	<?php
						    		if(!empty($member_linkedin))
						    		{
						    	?>
						    	<li><a title="<?php _e( 'Contact', THEMEDOMAIN ); ?> <?php the_title(); ?> <?php _e( 'on', THEMEDOMAIN ); ?> Linkedin" target="_blank" class="tipsy" href="<?php echo $member_linkedin; ?>"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/team_social/linkedin.png" alt=""/></a></li>
						    	<?php
						    		}
						    	?>
						    </ul>
						    <br class="clear"/>
						</div>
					</div>
					
				<?php
					endwhile;
	    			//End while loop
	    		?>
    
    		</div>
    		<br class="clear"/>
    		
   		 </div>
   	 	<!-- End main content -->
   	 	
</div>
			
<?php 
if(!isset($hide_header) OR !$hide_header OR is_null($hide_header))
{
?>			
<?php get_footer(); ?>

<?php
}
?>