<?php
// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) {
	exit;
}	
?>

<?php get_header(); ?>	

</div> <!-- // top_wrap -->

<div class="grid"><!--
	
	<?php
	global $post; 
	$siblings ="";
	
	$frag = new IMI_Fragment_Cache( 'crb' , get_permalink( $post->ID ) );
	
	if ( !$frag->output() ) {
	?>
	
		<?php echo '-->'; the_breadcrumbs(); echo '<!--'; ?>
	
		<?php
		
		$frag->store();
	}
	?>
	
	<?php
	$sb = ( get_field( 'p_sidebar' ) );

/*	$sb = false;
	if (function_exists('dynamic_sidebar'))
	{
		ob_start();
		dynamic_sidebar('widget-posts');
		$sidebar = ob_get_contents();
		ob_end_clean();
		if($sidebar)
		{
			$sb = true;
		}
	}*/
	
	$frag = new IMI_Fragment_Cache( 'pst' , get_permalink( $post->ID ) );

	if ( !$frag->output() ) {
	?>
		
		<?php
		if ( $term = get_the_category() ) {
			
			if ( $side_menu = get_field( 'c_menur', $term[0] ) ) {
				
				$query = new WP_Query(
					
					array( 
						'category__and' 	=> $term[0]->term_id,
						'hide_empty' 		=> 0,
						// 'post__not_in'		=> array( $post->ID ),
						'posts_per_page' 	=> -1,
					)
				);
				
				$siblings = $query->get_posts();
			}
		}
		?>
		
		--><main id="main_internal" class="category ib<?php if ($siblings) { ?> has_side_menu<?php } ?><?php if (!$sb) { ?> full_width<?php } ?>"><div class="divin"><div class=" mock_table with_side_menu_hold">
			
			<?php if ($siblings) { ?>
			
				<aside class="in_content_sidebar td t">
					
					<div class="open_side_menu" onclick="">
						
						<div class="line top"></div>
						
						<div class="line middle"></div>
						
						<div class="line bottom"></div>
					
					</div>
					
					<nav><ul class="ul side_menu">
						
						<?php foreach ( $siblings as $sib ) { ?>
						
							<?php if ( $sib->ID == $post->ID ) { ?>
						
							<li class="active"><span class="ff sma"><?php echo $sib->post_title; ?></span></li>
							
							<?php } else { ?>
							
							<li><a class="ff sma" href="<?php echo get_permalink( $sib->ID ); ?>"><?php echo $sib->post_title; ?></a></li>
							
							<?php } ?>
							
						<?php } ?>
						
					</ul></nav>
					
				</aside>
			
				<?php
				
				wp_reset_postdata();
			}
			?>
			
			<article <?php if ($siblings) { ?>class="near_menu td t"<?php } ?>>
			
				<h1 class="c1"><?php the_title(); ?></h1>
				
				<?php if( have_rows('fc_post') ) { ?>
				
					<?php while ( have_rows('fc_post') ) { the_row(); ?>
						
						<?php if( get_row_layout() == 'fc_p_figure' ) { ?>
						
							<?php if ($image = get_sub_field('fc_p_fi_image')) { ?>
						
								<figure class="box_style main_image">
									
									<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"/>
									
								</figure><br/>
							
							<?php } ?>
							
						<?php } elseif ( get_row_layout() == 'fc_p_desc' ) { ?>
							
							<?php if ($text = get_sub_field('fc_p_de_text')) { ?>
							
								<div class="description runner"><?php echo $text; ?></div>
							
							<?php } ?>
							
						<?php } elseif ( get_row_layout() == 'fc_p_gal' ) { ?>
							
							<section class="content_part">
								
								<?php if ( $gl_h2 = get_sub_field( 'fc_p_gl_title' ) ) { ?>
								
								<h2><?php echo $gl_h2; ?></h2>
								
								<?php } ?>
								
								<?php if ( $items = get_sub_field( 'fc_p_gl_items' ) ) { ?>
								
									<?php if ( get_sub_field( 'fc_p_gl_slider' ) ) { ?>
								
										<div class="internal_slider effect_slide gradient">
										
											<button title="<?php echo __( 'Next image' , 'profile' ); ?>" class="hs_next" onclick=""></button>
										
											<button title="<?php echo __( 'Previous image' , 'profile' ); ?>" class="hs_prev" onclick=""></button>
										
											<div class="viewport"><div class="slider_row">
												
												<?php foreach ( $items as $it ) { ?>
												
													<div class="slide">
													
														<div class="holidmg">
															
															<div class="table_hold">
															
																<div class="mock_table slider_table">
																	<div class="slider_img_hold">
																		<span>
																		
																			<img alt="<?php echo $it['alt']; ?>" src="<?php echo $it['sizes']['int-slider']; ?>" />
																		
																		</span>
																	</div>
																	
																	<?php if ( $it['caption'] ) { ?>
																	
																	<figcaption class="slider_caption">
																	
																		<span><?php echo $it['caption']; ?>

																		</span>
																		
																	</figcaption>
																	
																	<?php } ?>
																																
																</div>
																
															</div>
															

															
														</div>
														
													</div>
												
												<?php } ?>
												
											</div>
											
										</div></div>
									
									<?php } else { ?>
										
										<?php if ( get_sub_field( 'fc_p_gl_layout' ) == 'x3' ) { ?>
										
											<div class="content_gallery gallery_x3 lightbox"><div><!--
												
												<?php foreach ( $items as $it ) { ?>
												
													--><section class="box ib">
													
															<div class="bg"><div class="box_style"></div></div>
															
															<div class="divin">
																
																<a href="<?php echo $it['url']; ?>" class="lb" data-alt="<?php echo $it['caption']; ?>">
																	
																	<figure>
																	
																		<img src="<?php echo $it['sizes']['x-size']; ?>" alt="<?php echo $it['alt']; ?>"/>
																		<?php if ( $it['caption'] ) { ?>
																		
																		<figcaption><?php echo $it['caption']; ?></figcaption>
																		
																		<?php } ?>																		
																		
																	</figure>
																	
																</a>
																
															</div>
														
													</section><!--
												
												<?php } ?>
												
											--></div></div>		
										
										<?php } elseif ( get_sub_field( 'fc_p_gl_layout' ) == 'x4' ) { ?>
											
											<div class="gal_boxes4 lightbox"><div><!--
												
												<?php foreach ( $items as $it ) { ?>
												
												--><section class="box ib"><div class="bg"><div class="box_style"></div></div>
													
													<div class="divin">
													
														<a href="<?php echo $it['url']; ?>" class="lb" data-alt="<?php echo $it['caption']; ?>">
															
															<figure>
															
																<img src="<?php echo $it['sizes']['x4-size']; ?>" alt="<?php echo $it['alt']; ?>"/>
																<?php if ( $it['caption'] ) { ?>
																
																<figcaption><?php echo $it['caption']; ?></figcaption>
																
																<?php } ?>																
															</figure>
															
														</a>
														
													</div>
												
												</section><!--
												
												<?php } ?>
												
											--></div></div>
											
										<?php } ?>
										
									<?php } ?>
								
								<?php } ?>
								
							</section>
							
						<?php } elseif ( get_row_layout() == 'fc_p_files' ) { ?>
							
							<section class="content_part">
								
								<?php if ( $fl_h2 = get_sub_field( 'fc_p_fl_title' ) ) { ?>
								
								<h2><?php echo $fl_h2; ?></h2>
								
								<?php } ?>
								
								<?php if ( $items = get_sub_field( 'fc_p_fl_rep' ) ) { ?>
								
									<?php foreach ( $items as $ik => $iv ) { ?>
										
										<?php $ext = pathinfo($iv['fc_p_fl_r_file']['filename'], PATHINFO_EXTENSION); ?>
										
										<a href="<?php echo $iv['fc_p_fl_r_file']['url']; ?>" class="file <?php echo $ext; ?>" download><?php echo $iv['fc_p_fl_r_title']; ?></a>
										
										<?php if (($ik+1) < count($items)) { ?><br/><?php } ?>
										
									<?php } ?>
									
								<?php } ?>
								
							</section>
							
						<?php } elseif ( get_row_layout() == 'fc_p_youtube' ) { ?>
							
							<section class="content_part">
								
								<?php if ( $yt_h2 = get_sub_field( 'fc_p_yt_title' ) ) { ?>
								
								<h2><?php echo $yt_h2; ?></h2>
								
								<?php } ?>
								
								<?php if ( $video_src = parse_youtube( get_sub_field( 'fc_p_yt_url' ) ) ) { ?>
								
									<div class="vid_hold">
									
										<iframe src="<?php echo $video_src; ?>" frameborder="0" allowfullscreen></iframe>
										
									</div>
								
								<?php } ?>
								
							</section>
						
						<?php } elseif ( get_row_layout() == 'fc_p_items' ) { ?>
							
							<section class="content_part">
								
								<?php if ( $it_h2 = get_sub_field( 'fc_p_it_title' ) ) { ?>
								
								<h2><?php echo $it_h2; ?></h2>
								
								<?php } ?>
								
								<?php if ( $items = get_sub_field( 'fc_p_it_rep' ) ) { ?>
								
									<?php foreach ( $items as $it ) { ?>
										
										<?php
										$target = false;
										
										switch ($it['fc_p_it_r_type']) {
											
											case 'page':
												$link = ( !empty( $it['fc_p_it_r_page']) ) ? get_permalink($it['fc_p_it_r_page']) : false;
												break;
											
											case 'category':
												$link = ( !empty( $it['fc_p_it_r_category'] ) ) ? get_category_link($it['fc_p_it_r_category']) : false;
												break;
											
											case 'url':
												$link = $it['fc_p_it_r_url'];
												$target = true;
												break;
											
											default:
												$link = false;
												break;
										}
										?>
										
										<section class="team"><div class="mock_table">
											
											<?php if ( $it['fc_p_it_r_image'] ) { ?>
											
											<figure>
												
												<?php if ($link) { ?>
												
												<a href="<?php echo $link; ?>" <?php if ($target) {?>target="_blank"<?php } ?>>
												
												<?php } ?>
												
													<img src="<?php echo $it['fc_p_it_r_image']['url']; ?>" alt="<?php echo $it['fc_p_it_r_image']['alt']; ?>"/>
												
												<?php if ($link) { ?>
												
												</a>
												
												<?php } ?>
												
											</figure>
											
											<?php } ?>
											
											<div class="text">
												
												<h3>
													
													<?php if ($link) { ?>
													
													<a href="<?php echo $link; ?>" <?php if ($target) {?>target="_blank"<?php } ?>>
													
													<?php } ?>
													
														<?php echo $it['fc_p_it_r_title']; ?>
														
													<?php if ($link) { ?>
												
													</a>
												
													<?php } ?>
												
												</h3>
												
												<?php echo $it['fc_p_it_r_text']; ?>
												
											</div>
											
										</div></section>
								
									<?php } ?>
									
								<?php } ?>
								
							</section>
						
						<?php } elseif ( get_row_layout() == 'fc_p_faq' ) { ?>
						
							<section class="faq_widget content_part">
								
								<?php if ( $fq_h2 = get_sub_field( 'fc_p_fq_title' ) ) { ?>
								
								<h2 class="faq_title"><?php echo $fq_h2; ?></h2>
								
								<?php } ?>
								
								<?php if ( $faq = get_sub_field( 'fc_p_fq_rep' ) ) { ?>
								
									<div class="faq_controls">
										<span class="sr-only"><?php _e('FAQ','profile'); ?></span>
										<a  class="open_faq" href="javascript:void(0)"><span aria-label="<?php _e('Frequently asked questions','profile'); ?>" class="btn"></span><?php echo __( 'Open all' , 'profile' ); ?></a>
										<a aria-label="Frequently asked questions" class="close_faq" href="javascript:void(0)"><span aria-label="<?php _e('Frequently asked questions','profile'); ?>" class="btn"></span><?php echo __( 'Close all' , 'profile' ); ?></a>
										
									</div>
									
									<?php foreach ( $faq as $fq ) { 
										$id = random_string(5);
										?>	
									
										<div class="single_faq">
										
											<a id="<?php echo $id; ?>" href="javascript:void(0)" role="tab" class="ff open_ans" aria-expanded="true"><span aria-label="<?php _e('Press enter to open answer','profile'); ?>" class="btn"></span><?php echo $fq['fc_p_fq_r_question']; ?></a>
											
											<p aria-labelledby="<?php echo $id; ?>" role="tabpanel"><?php echo $fq['fc_p_fq_r_answer']; ?></p>
											
										</div>
									
									<?php } ?>
								
								<?php } ?>
								
							</section>
						
						<?php } elseif ( get_row_layout() == 'fc_p_social' ) { ?>
							
							<?php get_template_part('social'); ?>
						
						<?php } elseif ( get_row_layout() == 'fc_p_x3' ) { ?>
							
							<?php if ( $items = get_sub_field( 'fc_p_x3_rep' ) ) { ?>
								
								<div class="gallery_x3"><div><!--
								
								<?php foreach ( $items as $x3 ) { ?>
									
									<?php
									$target = false;
									
									switch ($x3['fc_p_x3_r_type']) {
										
										case 'page':
											$link = ( !empty( $x3['fc_p_x3_r_page']) ) ? get_permalink($x3['fc_p_x3_r_page']) : false;
											break;
										
										case 'category':
											$link = ( !empty( $x3['fc_p_x3_r_category'] ) ) ? get_category_link($x3['fc_p_x3_r_category']) : false;
											break;
										
										case 'url':
											$link = $x3['fc_p_x3_r_url'];
											$target = true;
											break;
										
										default:
											$link = false;
											break;
									}
									?>
									
									--><section class="box ib">
									
											<div class="bg"><div class="box_style"></div></div>
											
											<div class="divin">
												
												<?php if ( $x3['fc_p_x3_r_image'] ) { ?>
												
												<figure>
													
													<?php if ($link) { ?>
													
													<a href="<?php echo $link; ?>" <?php if ($target) {?>target="_blank"<?php } ?>>
													
													<?php } ?>
													
														<img src="<?php echo $x3['fc_p_x3_r_image']['sizes']['x-size']; ?>" alt="<?php echo $x3['fc_p_x3_r_image']['alt']; ?>"/>
													
													<?php if ($link) { ?>
													
													</a>
													
													<?php } ?>
													
												</figure>
												
												<?php } ?>
                                                
                                                <?php if($x3['fc_p_x3_r_title']) { ?>
												
												<div class="text runner_s">
													
													<h3 class="c1">
														
														<?php if ($link) { ?>
														
														<a href="<?php echo $link; ?>" <?php if ($target) {?>target="_blank"<?php } ?>>
														
														<?php } ?>
														
															<?php echo $x3['fc_p_x3_r_title']; ?>
														
														<?php if ($link) { ?>
														
														</a>
														
														<?php } ?>
														
													</h3>
													
													<?php echo $x3['fc_p_x3_r_text']; ?>
												
												</div>
                                                
                                                <?php } ?>
												
											</div>
											
									</section><!--
									
								<?php } ?>
								
								--></div></div>
								
							<?php } ?>
						
						<?php } elseif ( get_row_layout() == 'fc_p_x5' ) { ?>
						
							<?php if ( $items = get_sub_field( 'fc_p_x5_rep' ) ) { ?>
								
								<nav class="gallery_x5"><div><!--
								
								<?php foreach ( $items as $x5 ) { ?>
									
									<?php
									$target = false;
									
									switch ($x5['fc_p_x5_r_type']) {
										
										case 'page':
											$link = ( !empty( $x5['fc_p_x5_r_page']) ) ? get_permalink($x5['fc_p_x5_r_page']) : false;
											break;
										
										case 'category':
											$link = ( !empty( $x5['fc_p_x5_r_category'] ) ) ? get_category_link($x5['fc_p_x5_r_category']) : false;
											break;
										
										case 'url':
											$link = $x5['fc_p_x5_r_url'];
											$target = true;
											break;
										
										default:
											$link = false;
											break;
									}
									?>
									
									--><section class="box ib">
										
										<div class="bg"><div class="box_style"></div></div>
										
										<div class="divin">
											
											<?php if ( $x5['fc_p_x5_r_image'] ) { ?>
											
											<figure>
												
												<?php if ($link) { ?>
												
												<a href="<?php echo $link; ?>" <?php if ($target) {?>target="_blank"<?php } ?>>
												
												<?php } ?>
												
													<img src="<?php echo $x5['fc_p_x5_r_image']['sizes']['x5-size']; ?>" alt="<?php echo $x5['fc_p_x5_r_image']['alt']; ?>"/>
												
												<?php if ($link) { ?>
												
												</a>
												
												<?php } ?>
												
											</figure>
											
											<?php } ?>
											
											<?php if ( $x5['fc_p_x5_r_title'] ) { ?>
											
											<h3>
												
												<?php if ($link) { ?>
												
												<a href="<?php echo $link; ?>" <?php if ($target) {?>target="_blank"<?php } ?>>
												
												<?php } ?>
												
													<?php echo $x5['fc_p_x5_r_title']; ?>
												
												<?php if ($link) { ?>
												
												</a>
												
												<?php } ?>
												
											</h3>
											
											<?php } ?>
											
										</div>
										
									</section><!--
								
								<?php } ?>
								
								--></div></nav>
								
							<?php } ?>
						
						<?php } ?>
						
					<?php } ?>
				
				<?php } ?>
				
			</article>
			
		</div></div></main><!--
	
		<?php 
	
		$frag->store();
	}
	?>
	
	<?php if ($sb) { ?>
	
	--><aside id="main_sidebar" class="ib"><div class="divin"><div>
		
		<?php if (function_exists('dynamic_sidebar')) { dynamic_sidebar('widget-posts'); } ?>
	
	</div></div></aside><!--
	
	<?php } ?>
	
--></div>
	<!-- <div id="bottom-form-single" class="grid box_style shaded">
		<?php // if (function_exists('dynamic_sidebar')) { dynamic_sidebar('widget-bottom'); } ?>
	</div>
	-->

	<?php if ( get_field( 'p_bform', $post ) ) { ?>

		<?php get_template_part('form'); ?>

	<?php } ?>



<?php get_footer(); ?>