<?php
// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) {
	exit;
}
?>
<?php 
/**
 * Template Name: Home Page
 */ 
?>

<?php get_header(); ?> 

<?php 
$frag = new IMI_Fragment_Cache( 'sli' );

if ( !$frag->output() ) {
?>

	<?php if ( $sl_rows = get_field( 'fp_sl_rep' , 'option' ) ) { ?>

		<div class="oh"><section id="home_slider" class="rela">

			<div class="border"></div>
			
			<div id="image_appender" data-interval="<?php echo get_field('sl_interval','option'); ?>"></div>
			
			<div class="rela white_strip"><div class="hide_margin"><div class="mock_table">
			
				<?php 
				foreach ( $sl_rows as $sl_k => $sl_v ) { 
					$url_type = $sl_v['home_slider_box_url_type'];

					if ( $url_type == 0 ) {
						$tag = 'div';
						//$attr = $tag . '';
						$attr =  $tag . ' class="hs_link divin"';
					} elseif ( $url_type == 1 ) {
						$tag = 'a';
						$url = get_permalink( $sl_v['home_slider_box_url'] );
						$attr = $tag . ' class="hs_link divin" href="' . $url . '"';
					} else {
						$tag = 'a';
						$attr = $tag . ' class="hs_link divin" target="_blank" href="' . $sl_v['home_slider_box_url'] . '"';						
					}
				?>
				
				<div class="hs_item td t<?php if ($sl_k == 0) { ?> on first<?php } elseif (($sl_k+1) == count($sl_rows)) { ?> last<?php } ?>" data-img="<?php echo $sl_v['fp_sl_r_img']['sizes']['slider-size']; ?>" data-alt="<?php echo $sl_v['fp_sl_r_img']['alt']; ?>">
					<<?php echo $attr; ?>>
					<div class="home_sliter_btn_tab">
					
						<div class="icon"><span class="hs_ic_in<?php if (!$sl_v['fp_sl_r_icon']) { ?> no_icon<?php } ?>">
							
							<?php if ($sl_v['fp_sl_r_icon']) { ?>
							
							<img src="<?php echo $sl_v['fp_sl_r_icon']['url']; ?>" alt="<?php echo ($sl_v['fp_sl_r_icon']['alt']) ? $sl_v['fp_sl_r_icon']['alt'] : __('landmark icon','profile'); ?>"/>
							
							<?php } ?>
							
						</span></div>
						
						
						
						<div class="text runner_s"><?php echo $sl_v['fp_sl_r_text']; ?></div>
						
					</div>
					<?php if($url_type == 0) {echo '</div>';} else {echo '</a>';} ?> 
				</div>
				
				<?php } ?>
				
			</div></div></div>
			
		</section></div>

	<?php
	}
	
	$frag->store();
}
?>

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

<div class="grid">
	
	<?php
	$frag = new IMI_Fragment_Cache( 'htb' );
	
	if ( !$frag->output() ) {
	?>
	
		<div id="home_top_boxes"><div class="divin"><div><!--
		
			--><section class="ib side"><div class="box_bg"><div class="box_style"></div></div><div class="box_in">
			
				<h2 class="ff"><?php the_field( 'htb_title' , 'option' ); ?></h2>
				
				<p class="text runner_s"><?php the_field( 'htb_text' , 'option' ); ?></p>
				
				<?php if ( $htb_links = get_field( 'htb_rep' , 'option' ) ) { ?>
				
				<nav class="box_nav">
					
					<?php foreach ( $htb_links as $htb_l ) { ?>
					
						<?php
						$target = false;
						
						switch ($htb_l['htb_r_type']) {
							
							case 'page':
								$link = ( !empty( $htb_l['htb_r_page'] ) ) ? get_permalink($htb_l['htb_r_page']) : false;
								break;
							
							case 'category':
								$link = ( !empty( $htb_l['htb_r_category'] ) ) ? get_category_link($htb_l['htb_r_category']) : false;
								break;
							
							case 'url':
								$link = $htb_l['htb_r_url'];
								$target = true;
								break;
							
							default:
								$link = false;
								break;
						}
						?>
						
						<?php if ($link) { ?>
						
						<a href="<?php echo $link; ?>" class="bna" <?php if ($target) { ?>target="_blank"<?php }?>>
							<div class="bna_svg">
								<svg preserveAspectRatio="none" viewBox="0 0 200 200">
									<polygon points="190,0 200,0 200,200, 190,200 0,100"></polygon>
								</svg>								
							</div>
						<?php } else { ?>
						
						<div class="bna">
							<div class="bna_svg">
								<svg preserveAspectRatio="none" viewBox="0 0 200 200">
									<polygon points="180,0 200,0 200,200, 180,200 0,100"></polygon>
								</svg>	
							</div>													
						<?php } ?>
						
							<span class="ff"><?php echo $htb_l['htb_r_title']; ?></span>
						
						<?php if ($link) { ?>
						
						</a>
						
						<?php } else { ?>
						
						</div>
						
						<?php } ?>
					
					<?php } ?>
					
				</nav>
				
				<?php } ?>
				
			</div></section><!--
			
			--><section class="mid ib"><div class="box_bg"><div class="box_style"></div></div><div class="box_in wide_top">
				<div class="mock_table">
					<div class="text_flach td m">
					
						<h2 class="ff"><?php the_field( 'htb_mid_title' , 'option' ); ?></h2>
						
						<div class="text runner_s">
						
							<h3 class="ff"><?php the_field( 'htb_mid_subtitle' , 'option' ); ?></h3>
							
							<?php the_field( 'htb_mid_text' , 'option' ); ?>
							
						</div>
						
					</div>
					
					<?php if ($htb_mid_image = get_field( 'htb_mid_image' , 'option' )) { ?>
					
					<figure class="td m">
					
						<img src="<?php echo $htb_mid_image['sizes']['htb-mid-image']; ?>" alt="<?php echo $htb_mid_image['alt']; ?>"/>
						
					</figure>
					
					<?php } ?>
				</div>	
			</div></section><!--
			
			--><section class="ib side"><div class="box_bg"><div class="box_style"></div></div><div class="box_in">
				<div class="news_list">
					<?php
						 if (function_exists('dynamic_sidebar')) { dynamic_sidebar('home_top_sidebar'); }
					?>
				</div>
			</div></section><!--
			
		--></div></div></div>
	
		<?php
	
		$frag->store();
	}
	?>
	
	<aside class="home_bottom"><div class="divin"><div>
		
		<?php if (function_exists('dynamic_sidebar')) { dynamic_sidebar('widget-home'); } ?>
			
	</div></div></aside>
	
		
	
</div>

<?php get_footer(); ?>