<?php
/*
Template Name: Team
*/

$page = get_page(get_the_ID());
$currentlang = pll_current_language();
get_header();

$teamId = ($currentlang=='eng'?'9':'79');
if($biedrs = get_post($page->ID)){
	if($biedrs->post_parent != $teamId){
		unset($biedrs);
	}
}
?>
<div class="con">
	<div class="col side-row">
		<a href="<?=($currentlang=='eng'?'http://www.amrop.ee/eng/team':'http://www.amrop.ee/est/meeskond')?>" class="round-block" style="background-image:url(img/team.png)">
			<span class="middle"><?=get_the_title(($currentlang=='eng'?'9':'79'))?></span>
		</a>
		<nav class="side-menu">
			<ul>
				<?
				$args = array(
					'sort_order' => 'asc',
					'sort_column' => 'menu_order',
					'hierarchical' => 1,
					'parent'=> $teamId,
					'exclude' => $page->ID,
					'post_type' => 'page',
					'post_status' => 'publish'
				); 
				$pgs = get_pages($args); 
				foreach ( $pgs as $pg ) {
					echo '<li><a '.($page->ID == $pg->ID?'class="active"':'').' href="'. get_page_link( $pg->ID ) .'">'. $pg->post_title .'</a></li>';
				}?>
			</ul>
		</nav>
	</div>

	<div class="col middle-row">
		<?if(isset($biedrs)){
			$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $biedrs->ID ), 'team_member' );
			?>
			<div class="contact" style="<?if ( ! empty( $large_image_url[0] ) ) {?>background-image:url('<?=$large_image_url[0]?>');<?}?>margin-top: 0;">
				<a><h3><?=$biedrs->post_title?></h3></a>
				<span class="amats"><?=get_field('position', $biedrs->ID)?></span>
				<span class="location"><?=get_field('location', $biedrs->ID)?></span>
				<span class="mail"><?=get_field('emails', $biedrs->ID)?></span>
				<span class="tel"><?=get_field('phone', $biedrs->ID)?></span>
			</div>
		<?}?>
		<div class="top-block">
			<?=apply_filters('the_content', $page->post_content)?>
		</div>
		<div class="mid-con">
			<?the_field("lower_text");?>
		</div>
		<?
		if(!isset($biedrs)){
			$args = array(
				'sort_order' => 'asc',
				'sort_column' => 'menu_order',
				'hierarchical' => 1,
				'parent'=> $teamId,
				'exclude' => $page->ID,
				'post_type' => 'page',
				'post_status' => 'publish'
			); 
			$pgs = get_pages($args); 
			foreach ( $pgs as $pg ) {
				$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $pg->ID ), 'team_member' );
				?>
				<div  href="<?=get_permalink($pg->ID)?>" onclick="window.location.href=this.getAttribute('href');" class="contact conhover" <?if ( ! empty( $large_image_url[0] ) ) {?>style="background-image:url('<?=$large_image_url[0]?>')"<?}?>>
					<a><h3><?=$pg->post_title?></h3></a>
					<span class="amats"><?=get_field('position', $pg->ID)?></span>
					<span class="location"><?=get_field('location', $pg->ID)?></span>
					<span class="mail"><?=get_field('emails', $pg->ID)?></span>
					<span class="tel"><?=get_field('phone', $pg->ID)?></span>
				</div>
			<?}?>
		<?}?>
	</div>
	<?get_sidebar();?>
</div>
<?php get_footer(); ?>