<?php
if ( function_exists('get_field') ):

	if (get_field('page_sections')){
		$sectionCount = count( get_field('page_sections') ); //GET THE COUNT 
		$previousSection = 'none'; 
	}
	$sliderCount = 0;
	// check if the flexible content field has rows of data
	if( have_rows('page_sections') ):
		$count = 1;
		while ( have_rows('page_sections') ) : the_row(); ?>
			<?php 
			$anchor = get_sub_field('anchor');
			$style = get_sub_field('background_colour');
			$pre_title = get_sub_field('pre_title'); 
			$main_title = get_sub_field('main_title'); 
			$introduction = get_sub_field('introduction'); 
			?>

			<section id="<?php echo $anchor; ?>" class="clearfix
			row-index-<?php echo $count; ?> 
			page-section style-<?php echo $style; ?> <?php if ($count == $sectionCount) { echo 'last'; } ?>" >


			<?php if ($pre_title OR $main_title OR $introduction): ?>
				<div class="section-introduction center-align">
					<div class="container ">
						<?php if ($pre_title): ?>
								<h5 class="pre-title wow fadeInUp" data-wow-delay=".2s">
									<?php echo $pre_title; ?> 
								</h5>
						<?php endif; ?>

						<?php if ($main_title): ?>
								<h2 class="section-title wow fadeInUp" data-wow-delay=".4s">
									<span><?php echo $main_title; ?></span> 
								</h2>
						<?php endif; ?>

						<?php if ($introduction): ?>
							<div class="lead-para <?php if( get_row_layout() != 'plain_text' ) { echo 'introduction-text-top'; } ?> wow fadeInUp" data-wow-delay=".6s">
								<?php echo $introduction; ?> 
							</div>
						<?php endif; ?>
					</div>
				</div> 
			<?php endif; ?>

			<?php 

			if( have_rows('section_content') ):
				$contentCount = 1;
				while ( have_rows('section_content') ) : the_row(); ?>

					<div class="section-inner <?php echo get_row_layout(); ?> ">

					<!-- plain text  -->	
					<?php if( get_row_layout() == 'plain_text' ): ?>

						<?php 
						$content = get_sub_field('content'); 
						$buttons = get_sub_field('buttons'); 
						?>

						<div class="container ">
							<div class="row">
								<div class="col s12 m10 push-m1 l8 push-l2">
									<div class="wysiwyg plain_text_content fff">
										<?php the_sub_field('content'); ?>
									</div>
								</div>
							</div>
						</div>
						<?php elseif( get_row_layout() == 'fullwidth_section' ): ?>
							<?php 
							$content = get_sub_field('content'); 
							?>

							<div class="wysiwyg ">
								<?php the_sub_field('content'); ?>
							</div>
						<?php elseif( get_row_layout() == 'instagram_feed' ): ?>
							<?php 
							$content = get_sub_field('content'); 
							?>
							<div class="wide-container">
								<div class="wysiwyg ">
									<?php the_sub_field('content'); ?>
								</div>
							</div>


			        <!-- latest news -->
			        <?php elseif( get_row_layout() == 'news' ): ?>
			        	<?php
			        	$title = get_sub_field('title'); 
			        	$buttons = get_sub_field('buttons'); 
			        	?>
			        	<div class="container">
			        		<div class="feature-title-wrapper">
				        		<h3 class="section-title"><?php echo $title; ?></h3>
				        	</div>

				        	<div class="row">
				        		<div class="col s12 m12">

				        				<div class="news-slider" data-slick-range data-slick='{
													"dots": false,
													"infinite": false,
													"arrows": false,
													"slidesToShow": 4,
													"slidesToScroll": 4,
													"adaptiveHeight": true,
													"respondTo": "window",
													"swipeToSlide": true,
													"responsive": [
															{
																	"breakpoint": 1280,
																	"settings": {
																			"slidesToShow": 4,
																			"slidesToScroll": 4,
																			"infinite": false,
																			"dots": false
																	}
															},
															{
																	"breakpoint": 940,
																	"settings": {
																			"slidesToShow": 2,
																			"slidesToScroll": 2
																	}
															},
															{
																	"breakpoint": 480,
																	"settings": {
																			"slidesToShow": 1,
																			"slidesToScroll": 1
																	}
															}
													]
											}'>
						        	<?php 
						        	   // the query
						        	   $the_query = new WP_Query( array(
						        	      'post_type' => 'news',
						        	      'posts_per_page' => 15,
						        	   )); 
						        	   $postCount = 0;
						        	?>

						        	<?php if ( $the_query->have_posts() ) : ?>
						        	  <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

						        	    	<?php get_template_part('partials/template', 'post-card'); ?>
						        	
						        	    <?php $postCount++; ?>
						        	  <?php endwhile; ?>						        	
						        	  <?php wp_reset_postdata(); ?>
						        	<?php else : ?>
						        	  <p><?php __('No News'); ?></p>
						        	<?php endif; ?>
											</div>
											<div class="control-range">
												<input type="range" min="0" max="5" step="1" value="0" data-rangeslider />
											</div>
									</div>
								</div>
								<div class="center-align news-buttons">
			        				<?php if ($buttons){ displayButtons($buttons, 'dark'); } ?>
			        			</div>
							</div>
			    	<!-- accordion -->
			        <?php elseif( get_row_layout() == 'accordion' ): ?>
			        	<?php $title = get_sub_field('title'); ?>
			        	<div class="container">
			        		<h2 class='center-align'>
			        			<?php echo $title; ?>
			        		</h2>

			        		<div class="row">
			        			<div class="col s12 m10 push-m1 l8 push-l2">
			 						<?php if (get_sub_field('accordion_items')): ?>

			 					    	<div class="accordion">
					 					    <?php while ( have_rows('accordion_items') ) : the_row(); ?>
					 	    					<?php 
					 	    					$accordion_item_title = get_sub_field('accordion_item_title');
					 	    					$accordion_item_content = get_sub_field('accordion_item_content');
					 	    					?>

					 					    		<div class="accordion-item">
					 					    			<div class="accordion-title">
					 					    				<h3><?php echo $accordion_item_title; ?></h3>
					 					    				<div class="chevron">
									                            <?php echo file_get_contents(get_template_directory() . '/assets/img/icons/plus.svg'); ?>
									                        </div>
					 					    			</div>
					 					    			<div class="accordion-content">
					 					    				<div class="wysiwyg">
					 					    					<?php echo $accordion_item_content; ?>
					 					    				</div>
					 					    			</div>
					 					    				
					 					    		</div>
					 						<?php endwhile; ?>
			 							</div>
				 					<?php endif; //end if accordion ?>
				 				</div>
				 			</div>
		 				</div>




					<!-- tabs -->
			        <?php elseif( get_row_layout() == 'tabs' ): ?>
	 					<?php if (get_sub_field('tabs')): ?>

	 					    <div class="tabs">

	 					    	<div class="container">
		 					    	<div class="tab-select">
				 					    <?php while ( have_rows('tabs') ) : the_row(); ?>
				 	    					<?php 
				 	    					$title = get_sub_field('tab_title');
				 	    					$content = get_sub_field('tab_inner_content');
				 	    					$content_blocks = get_sub_field('content_blocks');

				 	    					?>

				 					    		<div class="tab" data-id="<?=strtolower(str_replace(' ','-',$title));?>">
				 					    			<div class="tab-label btn btn-outline-gray" >
				 					    				<?php echo $title; ?>
				 					    			</div>
				 					    			<div class="tab-mobile-content hide-on-med-and-up <?=strtolower(str_replace(' ','-',$title));?>">
					 					    				<div class="wysiwyg">
					 					    					<?php echo $content; ?>
					 					    				</div>
	<?php if( have_rows('content_blocks') ): ?>
							    						    <ul class="tab-content-blocks">
							    						    <?php while( have_rows('content_blocks') ): the_row(); 
							    						        $content = get_sub_field('content');
							    						        ?>
							    						        <li> 					    	<?php echo $content; ?>
							    						        </li>
							    						    <?php endwhile; ?>
							    						    </ul>
							    						<?php endif; ?>
					 					    			</div>
				 					    		</div>
				 						<?php endwhile; ?>
		 							</div>
		 						</div>

	 					    	<div class="tab-content-container hide-on-small-only">
	 					    		<div class="container">
									    <?php while ( have_rows('tabs') ) : the_row(); ?>
					    					<?php
												$title = get_sub_field('tab_title');
					    					$content = get_sub_field('tab_inner_content');
					    					$content_blocks = get_sub_field('content_blocks');
					    					?>

									    		<div class="tab-content <?=strtolower(str_replace(' ','-', $title));?>">
							    					<div class="tab-content-inner">
							    						<div class="wysiwyg">
							    							<?php echo $content ?>
							    						</div>
															<?php if( have_rows('content_blocks') ): ?>
							    						    <ul class="tab-content-blocks">
							    						    <?php while( have_rows('content_blocks') ): the_row(); 
							    						        $content = get_sub_field('content');
							    						        ?>
							    						        <li> 					    	<?php echo $content; ?>
							    						        </li>
							    						    <?php endwhile; ?>
							    						    </ul>
							    						<?php endif; ?>
							    					</div>
								    			</div>								    		
									    			
										<?php endwhile; ?>
									</div>
								</div>

	 						</div>

	 					<?php endif; //end if tabs ?>


			        <?php elseif( get_row_layout() == 'google_map' ): ?>
			        	<?php $map = get_sub_field('google_map'); 
			        	?>
			        	<div class="map" id="googlemap <?php echo $sectionCount; ?>" data-lat="<?php echo $map['lat']; ?>" data-lng="<?php echo $map['lng']; ?>" data-text="<?php echo $map['address']; ?>">
			        	</div>
			        <?php elseif( get_row_layout() == 'whats_on_slider' ): ?>

	        		<!-- this is the spaced slider -->
	        		<?php
	       	 			$title = get_sub_field('title'); 
	       	 			$populate_with = get_sub_field('populate_with'); 
	       	 			$buttons = get_sub_field('buttons'); 
	       	 			$term = get_sub_field('term'); 
	       	 			$slides = get_sub_field('slides'); 
	       	 			$expand_wide = get_sub_field('expand_wide'); 

	       	 			$numSlides = get_sub_field('number_of_slides_displayed_on_desktop');
	       	 		
	       	 			if (!$numSlides) {
	       	 				$numSlides = 2; 
	       	 			}

	       	 			if (is_array($numSlides)) {
	       	 				$numSlides = $numSlides[0]; 
	       	 			}

	       	 			// print_r( $numSlides);
	       	 		?>
	       	 		
	       	 		<div class="container">
	       	 			<?php if ($title): ?>
	       	 				<div class="header-buttons clearfix">
    	       	 				<h2 class="section-inner-title">
    	       	 					<?php echo $title; ?>
    	       	 				</h2>
    						</div>
	       	 			<?php endif; ?>
	       	 		</div>

	       	 		<div class="slider-section-wrapper">
    	       	 		<div class="wide-container">

    	       	 			<div class="event-slider-container">
	    	       	 		<div class="slider event-slider slider-count-<?php echo $numSlides; ?>">
	    	       	 			<?php if ($populate_with == 'manual'): ?>
		    							<?php if ($slides): ?>
		    							    <?php while ( have_rows('slides') ) : ?>
		    								    <?php the_row(); ?>

		    								    <?php 
		    								    	$image = get_sub_field('image');
		    								    	$date = get_sub_field('date'); 
		    								    	$title = get_sub_field('title'); 
		    								    	$category = get_sub_field('category'); 
		    								    	$link_url = get_sub_field('link_url'); 
													$class='';
													if($link_url) {
														$postid = url_to_postid($link_url);
														
														if($postid > 1 && get_post_type($postid)=='tribe_events')	{
															$class='tribe-event-url event-modal';
														} else {
															$class='custom-url not-in-md';
														}
													}
		    								    ?>
		    								    <div class="slide">
			    								    <div class="card">

							    		       	 			<div class="card-image-container">
							    	       	 					<?php if ($image): ?>
			    								    				<a href="<?php echo $link_url; ?>" class="<?php echo $class;?>">
	    	       	 			       	 							<div class="card-ratio-image-container">
							    		       	 						<img src="<?php echo $image['sizes']['small-card-size']; ?>" alt="<?php echo $image['title']; ?>">
							    		       	 					</div>
							    		       	 					</a>
							    		       	 				<?php endif; ?>
							    		       	 				
							    		       	 				<div class="card-event-category">
			    								    				<?php echo $category; ?>
							    		       	 				</div>
							    		       	 			</div>

			    								    	<div class="card-inner">
			    								    		<div class="card-event-date">
			    								    			<?php echo $date; ?>
			    								    		</div>
			    								    		<div class="card-event-name">
			    								    		<a href="<?php echo $link_url; ?>" class="<?php echo $class;?>">
			    								    			<?php echo $title; ?>
			    								    		</a>
			    								    		</div>
			    								    	</div>
			    								    </div>
			    								</div>


		    									<?php endwhile; ?>
		    							<?php endif; ?>
	    	       	 			<?php elseif ($populate_with == 'term'): ?>
	    	       	 				<?php 
	    	       	 				$slugs = array(); 
	    	       	 				foreach ($term as $termeach) {
	    	       	 					array_push($slugs, $termeach->slug);
	    	       	 				}

	    	       	 				$number_of_events = get_sub_field('number_of_events'); 
	    	       	 				if (!$number_of_events) {
	    	       	 					$number_of_events = 6; 
	    	       	 				}
			       	 				$events = tribe_get_events(
			       	 					array('post_type' => 'tribe_events', 
			       	 						'posts_per_page' => $number_of_events,
											'meta_key'		=>'_EventStartDate',
											'orderby'		=>'_EventStartDate',
											'order'			=>'ASC',
			       	 						'eventDisplay'=>'upcoming',
			       	 						'tax_query'=> array(
		   	 						            array(
		   	 						                'taxonomy' => 'tribe_events_cat',
		   	 						                'field' => 'slug',
		   	 						                'terms' => $slugs
		   	 						                )
		   	 						            )
			       	 					) 
			       	 				);

	    	       	 				if ( $events ) {
	    	       	 					foreach ($events as $post ) {

	    	       	 						setup_postdata( $post ); ?>

		    								    <div class="slide">
			    								    <?php get_template_part('templates/template', 'event-card'); ?>
			    								</div>

	    	       	 							<?php }
	    	       	 							/* Restore original Post Data */
	    	       	 							wp_reset_postdata();
	    	       	 						} else {
	    	       	 							echo "No upcoming events";
	    	       	 						} ?>
       	 						<?php else: ?>

	    	       	 				<?php 
	    	       	 				$slugs = array(); 

	    	       	 				$number_of_events = get_sub_field('number_of_events'); 
	    	       	 				if (!$number_of_events) {
	    	       	 					$number_of_events = 6; 
	    	       	 				}
			       	 				$events = tribe_get_events(
			       	 					array('post_type' => 'tribe_events', 
			       	 						'posts_per_page' => $number_of_events,
											'meta_key'		=>'_EventStartDate',
											'orderby'		=>'_EventStartDate',
											'order'			=>'ASC',
			       	 					) 
			       	 				);

	    	       	 				if ( $events ) {
	    	       	 					foreach ($events as $post ) {

	    	       	 						setup_postdata( $post ); ?>

		    								    <div class="slide">
			    								    <?php get_template_part('template-parts/template', 'event-card'); ?>
			    								</div>

	    	       	 							<?php }
	    	       	 							/* Restore original Post Data */
	    	       	 							wp_reset_postdata();
	    	       	 						} else {
	    	       	 							echo "No upcoming events";
	    	       	 						} ?>


	    	       	 			<?php endif; ?>

	    	       	 		</div>

		    	       	 		<div class="event-slider-navigation">
		    	       	 		</div>
    	       	 			<div class="event-slider-container">

	    	       	 	</div>
	    	       	 	<div class="button-container">
		    	       	 	<a href="<?php echo tribe_get_events_link(); ?>" class="theme-button">View event calendar</a>
		    	       	 </div>
	    	       	 </div>

	       	 		<div class="container"> 
						<?php if ($buttons): ?>
						    <div class="theme-buttons hide-on-large-only">
						    <?php while ( have_rows('buttons') ) : ?>
							    <?php the_row(); ?>
							    <?php 
							    	$button_label = get_sub_field('button_label');
							    	$button_link = get_sub_field('button_link'); 
   	 	    				    	$is_pdf = strpos($button_link, '.pdf');

							    ?>
									<a href="<?php echo $button_link; ?>" class="theme-button light chevron" target="<?php if ($is_pdf){ echo '_none';} ?>">
			        					<?php if ($button_label){ echo $button_label; } else { echo 'Read more'; } ?>
			        				</a>
								<?php endwhile; ?>
							</div>
						<?php endif; ?>
					</div>
					<!-- content columns  -->
				    <?php elseif( get_row_layout() == 'content_columns' ): ?>
				    	<div class="wide-container">
				    	<?php 
				    		$number_of_columns = get_sub_field('number_of_columns');
				    		$colClass = "m6";

				    		if ($number_of_columns == 2) {
				    			$colClass = "m6";
				    		} elseif ($number_of_columns == 3) {
				    			$colClass = "m4";
				    		} elseif ($number_of_columns == 4) {
				    			$colClass = "m3";
				    		}
				    	?>
	 					<?php if (get_sub_field('columns')): ?>

	 					    <div class="content-columns column-count-<?php echo $number_of_columns; ?>">

		 					    <?php while ( have_rows('columns') ) : the_row(); ?>
		 	    					<?php 
		 	    					$image = get_sub_field('image');
		 	    					$title = get_sub_field('title');
		 	    					$content = get_sub_field('content');
		 	    					$buttons = get_sub_field('buttons');


		 	    					?>

		 					    		<div class="content-column-card <?php echo $colClass; ?>">
		 					    				<?php if ($image): ?>
											         <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['title']; ?>" class="card-image-real">
											    <?php endif; ?>

		 					    				<h3><?php echo $title; ?></h3>
		 					    				<div class="wysiwyg">
		 					    					<?php echo $content; ?>
		 					    				</div>
	    				        				<?php 
	    				        				if ($buttons){ displayButtons($buttons); } ?>


		 					    		</div>
		 						<?php endwhile; ?>
								</div>


	 					<?php endif; //end if columns ?>
	 				</div>
				<?php elseif( get_row_layout() == 'feature_background_image_row' ): ?>
					<?php 
					$background_image = get_sub_field('background_image'); 
					$content = get_sub_field('content'); 
					?>
					<div class="feature-background-box " style="background-image: url(<?php if ($background_image) { echo $background_image['url']; } ?>">
						<div class="container">
							<div class="feature-background-box-content content">
								<div class="feature-background-box-content-inner">
									<?php echo $content; ?>
								</div>
							</div>
						</div>

					</div>
				<?php elseif( get_row_layout() == 'introduction_feature_boxes' ): ?>

		        	<?php 
		        	$introduction = get_sub_field('introduction'); 
		        	$feature_boxes = get_sub_field('feature_boxes'); 
		        	?>

		        	<div class="container">
		        		<div class="feature-boxes-container row">
		        		<div class="feature-boxes-introduction col s12 m4">
			        		<?php echo $introduction; ?>
			        	</div>


		        		<div class="feature-grid col s12 m8">
				        	<?php // Check rows exists.
				        	if( have_rows('feature_boxes') ):

				        	    // Loop through rows.
				        	    while( have_rows('feature_boxes') ) : the_row();

				        	        // Load sub field value.
				        	        $background_image = get_sub_field('background_image');
				        	        $title = get_sub_field('title');
				        	        $content = get_sub_field('content');
				        	        $link = get_sub_field('button');
				        	        ?>
				        	        <div class="feature-grid-box style-dark" style="background-image:url(<?php if ($background_image){ echo $background_image['url']; }?>)">
			        	       	 		<a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>">
				        	        
			        	        			<h4><?php echo $title; ?></h4>
			        	        			<div class="feature-box-content hide-on-small-only">
				        	        			<?php echo $content; ?>
				        	        		</div>	
				        	        		<?php if ($link): ?>
					        	        		<div class="btn btn-outline-white hide-on-small-only" >Learn more</div>
					        	        	<?php endif;?>
			        	        		</a>
		        	        		</div>
				        	    <?php // End loop.
				        	    endwhile;

				        	// No value.
				        	else :
				        	    // Do something...
				        	endif;
				        	?>
				        </div>
				    </div>
				</div>

				<!-- alternating rows -->
				<?php elseif( get_row_layout() == 'split_row' ): ?>


					<?php 

					$background_title = get_sub_field('background_title'); 
					$content = get_sub_field('content'); 

					$image = get_sub_field('image'); 
					$buttons = get_sub_field('buttons'); 
					$image_position = get_sub_field('image_position'); 

					// echo $contentCount;
					if ($contentCount% 2 == 0) {
						$imageDirection = 'fadeInLeft';
						$titleDirection = 'fadeInRight';
					} else {
						$imageDirection = 'fadeInRight';
						$titleDirection = 'fadeInLeft';
					}
					?>

					<div class="alt-row clearfix image-<?php echo $image_position; ?>">
						<div class=" <?php if ($style != 'extrawide') {echo 'container';} else { echo 'extrawide '; } ?> clearfix">

							<div class="alt-row-inner-container">
								<div class="alt-row-column alt-row-image-column">
									<?php if ($image): ?>
										<div class="alt-row-image wow <?php echo $imageDirection; ?>" data-wow-delay=".3s" >
											<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
										</div>
										<?php endif; ?>
								</div>
								<div class="alt-row-column">

									<div class="alt-row-content">
										<div class="wysiwyg wow fadeIn" data-wow-delay=".8s">
											<?php echo $content; ?>
										</div>
										<?php if ($buttons) {displayButtons($buttons); } ?>
									</div>	
								</div>
							</div>

							</div>
						</div>
			        <?php elseif( get_row_layout() == 'image_cta' ): ?>

			        	<?php 

			        	$style = get_sub_field('style'); 
			        	$button = get_sub_field('button'); 
			        	$background_image = get_sub_field('background_image'); 
			        	$title = get_sub_field('title'); 
			        	?>

			        	<?php if ($style != 'full-width'): ?>
			        		<div class="container">

					        	<div class="image-cta style-dark nospace-mobile <?php echo $style; ?>" style="background-image: url(<?php if ($background_image) { echo $background_image['url']; } ?>">
					        		<div class="image-cta-content">
					        			<h3><?php echo $title; ?></h3>
					        			<?php if ($button):?>
					        				<a class="btn btn-color btn-large" href="<?php echo $button['url']; ?>"><?php if ($button['title']){ echo $button['title'];} else {echo'Learn more';} ?></a>
					        			<?php endif;?>
					        		</div>
					        	</div>

			        		</div>
		        		<?php else: ?>
		        			<div class="image-cta style-dark <?php echo $style; ?>" style="background-image: url(<?php if ($background_image) { echo $background_image['url']; } ?>">
		        				<div class="container">
			        				<div class="image-cta-content">
			        					<h3><?php echo $title; ?></h3>
			        					<?php if ($button):?>
			        					<a class="btn btn-dark" href="<?php echo $button['url']; ?>"><?php if ($button['title']){ echo $button['title'];} else {echo 'Learn more';} ?></a>
			        				<?php endif;?>
			        				</div>
			        			</div>
		        			</div>
		        		<?php endif;?>

					<!-- card grid  -->	
			        <?php elseif( get_row_layout() == 'card_grid' ): ?>

			        	<?php 
			        	$title = get_sub_field('title');  
			        	$buttons = get_sub_field('buttons');  
			        	$populate_with = get_sub_field('populate_with');  
			        	$card_image_style = get_sub_field('card_image_style');
			        	//retain-ar
			        	if (isset($populate_with)) {
			        		//nothing
			        	} else {
			        		$populate_with = 'manual';
			        	}
			        	?>

			        	<div class="container">
			        		<h3 class="center-align section-title"><?php echo $title; ?></h3>
			        		<?php if ($populate_with == 'manual' OR !$populate_with): ?>

			        			<?php $cards = get_sub_field('cards');?>
			        			<div class=" cards mobile-slider-cards sss">
		    						<?php while ( have_rows('cards') ) : the_row(); ?>
		    							<?php 
		    							$link = get_sub_field('button'); 
		    							$image = get_sub_field('image'); 
		    							$content = get_sub_field('content'); 
		    							$title = get_sub_field('title'); 
		    							// print_r($image);
		    							?>
										<div class="card-slide">

		    								<?php if ($image){

		    									if ($card_image_style == 'retain-ar') { ?>
										             <div class="card general-card">
										            <?php if ($image): ?>
										                <?php if ($link): ?>
										                  <a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>" title="<?php echo $link['title']; ?>" class="">
																			<?php endif; ?>

																			<img src="<?php echo $image['url']; ?>">
										                <?php if ($link): ?>
										                  </a>
										                <?php endif; ?>
										               <?php endif; ?>
										              <div class="card-inner">
										                <h5 class="bold simple-card-title"><?php echo $title; ?></h5>
										                <div class="wysiwyg">
										                  <?php echo $content; ?>
										                </div>

										                <?php if ($link): ?>
										                  <a class="btn btn-outline-gray btn-grey-outline" href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>" title="<?php echo $link['title']; ?>">
										                    <?php  if ($link['title']) { echo $link['title']; } else { echo 'explore'; } ?> 
										                </a>
										                <?php elseif ($url): ?>
										                  <a class="btn btn-outline-gray btn-grey-outline" href="<?php echo $url; ?>" target="" title="<?php echo $title; ?>">
										                    <?php  if ($link['title']) { echo $link['title']; } else { echo 'Explore'; } ?>
										                  </a>
										                <?php endif; ?>
										              </div>
										             </div>
		    									<?php } else {
		    									displaySimpleCard($image['sizes']['card-single'], $content, $title, $link); 
		    									}
		    								} else {
		    									displaySimpleCard('none', $content, $title, $link); 
		    								}
		    								?>
		    							</div>


									<?php endwhile; ?>
	    						</div>
	    					<?php else: ?>

	    						<?php 
	    						if ($populate_with == 'term'){
	    							$term = get_sub_field('term');

		    						foreach ( $term as $term ) {
										$taxonomy = $term->taxonomy;
								        $term_ids[] = $term->term_id;
									}

									$args = array('tax_query' => array(
										array( 'taxonomy' => $taxonomy,
											'field' => 'id',
											'terms' => $term_ids
										)
									), 'posts_per_page' => '3');

	    						} else {
	    							$args = array('post_type' => $populate_with, 'posts_per_page' => '3');
	    						}
	    						



	    						$term_query = new WP_Query($args);

	    						// print_r($args);

	    						if ( $term_query->have_posts() ) { ?>
				        			<div class="row">
				        			    <?php while ( $term_query->have_posts() ) {
				        			        $term_query->the_post(); ?>
		    							<div class="col s12 m4">
				        			        <?php get_template_part('templates/template', 'archivelisting'); ?>
										</div>			        			        
				        			    <?php } ?>
				        			</div>
	    						<?php } wp_reset_query(); ?>

			        		<?php endif; ?>


			        							<div class="center-align news-buttons">
			        		        				<?php if ($buttons){ displayButtons($buttons, 'dark'); } ?>
			        		        			</div>


			        	</div>

			        <?php elseif( get_row_layout() == 'slider' ): ?>
			        	<?php 
							$slider_style = get_sub_field('slider_style');
							$slides = get_sub_field('slides');
							$first_slide_label = get_sub_field('first_slide_label');
							$last_slide_label = get_sub_field('last_slide_label');
							$sliderCount++; 
							$numSlides = count($slides);
							$startingSlideIndex = 0;


			        	?>

				        			<?php if ($slides): 
				        				$activeCount = 0;?>
			    						<?php while ( have_rows('slides') ) : the_row(); ?>
			    							<?php 
			    							$starting_slide = get_sub_field('starting_slide');
			    							if ($starting_slide) {
												$startingSlideIndex = $activeCount;
			    							}
			    							$activeCount++;
			    							?>
										<?php endwhile; ?>

				        			<?php endif; ?>

			        	<div class="container">

			        		<div class="slider-container <?php echo $slider_style; ?>">

		        				<div class="ranger-slider " data-slick-range data-slick='{
											"dots": <?php if ($slider_style == 'split'){ echo 'true'; } else { echo 'false';} ?>,
											"infinite": false,
											"arrows": true,
											"slidesToShow": 1,
											"slidesToScroll": 1,
											"adaptiveHeight": true,
											"respondTo": "window",
											"swipeToSlide": true, 
											"fade": <?php if ($slider_style == 'split'){ echo 'false'; } else { echo 'true';} ?>, 
											"initialSlide": <?php echo $startingSlideIndex; ?>										
									}'>
				        			<?php if ($slides): ?>
			    						<?php while ( have_rows('slides') ) : the_row(); ?>
			    							<?php 
			    							$slide_image = get_sub_field('slide_image'); 
			    							$slide_content = get_sub_field('slide_content'); 
			    							$starting_slide = get_sub_field('starting_slide'); 
			    							?>
											<div class="large-slide">
												<?php if ($slider_style == 'split'): ?>

														<div class="alt-row clearfix image-left">
															<div class="clearfix">
																<div class="alt-row-inner-container">
																	<div class="alt-row-column alt-row-image-column">
																		<?php if ($slide_image): ?>
																			<img class="alt-row-image" src="<?php echo $slide_image['url']; ?>" alt='<?php echo $slide_image['alt']; ?>'>
																		<?php endif; ?>
																	</div>
																	<div class="alt-row-column">
																		<div class="alt-row-content">
																			<div class="wysiwyg wow fadeIn" data-wow-delay=".8s">
											    								<?php echo $slide_content; ?>
																			</div>
																		</div>	
																	</div>
																</div>

															</div>
														</div>
												<?php else: ?>

				    								<?php if ($slide_image): ?>
				    									<img src="<?php echo $slide_image['url']; ?>" alt='<?php echo $slide_image['alt']; ?>'>
				    								<?php endif; ?>

				    							<?php endif; ?>

			    							</div>


										<?php endwhile; ?>
				        			<?php endif; ?>
				        		</div>

				        		<?php if ($slider_style == 'image'): ?>
				        			<div class="control-range">
				        				<input type="range" min="0" max="5" step="1" value="0" data-rangeslider />
				        			</div>
			        			<?php else: ?>
			        				<div class="split-slider-nav hide-on-small-only">
			        					<button class="gotofirstslide btn btn-outline-gray btn-transparent"><?php echo $first_slide_label; ?></button>
			        					<button class="gotolastslide btn btn-outline-gray btn-transparent" data-go-to="<?php echo $numSlides; ?>"><?php echo $last_slide_label; ?></button>
			        				</div>
			        			<?php endif; ?>
			        		</div>

			        	</div>

					<!-- basic gallery -->
					<?php elseif( get_row_layout() == 'gallery' ): ?>
						<?php 
							$title = get_sub_field('title');
							$images = get_sub_field('gallery');	//pr($images);
						?>
						<div class="container">
							<div class="row">
								<h3 class="center-align section-title">
									<?php echo $title; ?>		
								</h3>

							<div class="theme-gallery nospace-mobile" data-photoswipe>
								<?php 

				        		if( $images ):
				        			foreach( $images as $image ): ?>
				        				<figure class="gallery-item">
													<a href="<?=$image['sizes']['medium_large'];?>" data-size="<?=$image['sizes']['medium_large-width'];?>x<?=$image['sizes']['medium_large-height'];?>">
					        					<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>">
													</a>
													<figcaption>
													<div class="row">
														<div class="col-md-3">
															<button class="btn btn-outline-gray btn-transparent" data-toggle="modal" data-target="#download" data-media="<?=$image['url'];?>" >Download High Quality</button>
														</div>
													</div>
													</figcaption>
					        			</figure>

				        			<?php endforeach; 

				        		endif; ?>
				        	</div>

			        	</div>
			        </div>


			        <!-- single image -->
			        <?php elseif( get_row_layout() == 'icon_grid' ): ?>
			        	<?php $icon_grid_boxes = get_sub_field('icon_grid_boxes'); ?>

			        	<div class="container">
			        		<div class="row">
					        	<?php // Check rows exists.
					        	$iconsDelay = .2;
					        	if( have_rows('icon_grid_boxes') ):

					        	    // Loop through rows.
					        	    while( have_rows('icon_grid_boxes') ) : the_row();

					        	        // Load sub field value.
					        	        $image = get_sub_field('image');
					        	        $title = get_sub_field('title');
					        	        $content = get_sub_field('content');
					        	        ?>

					        	        <div class="col s12 m4">
					        	        	<div class="icon-grid-box center-align">
					        	        	<div class="icon-grid-image wow fadeInUp" data-wow-delay="<?php echo $iconsDelay; ?>s">
					        	        		<?php if ($image): ?>
				        	        				<img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>">
				        	        			<?php endif; ?>
			        	        			</div>					        	        
			        	        			<h4 class="wow fadeIn" data-wow-delay="<?php echo $iconsDelay+.2; ?>s""><?php echo $title; ?></h4>
			        	        			<div class="wow fadeIn" data-wow-delay="<?php echo $iconsDelay+.4; ?>s">
				        	        			<?php echo $content; ?>
				        	        		</div>	
			        	        		</div>
			        	        		</div>
					        	    <?php // End loop.
					        	    $iconsDelay += .2;
					        	    endwhile;

					        	// No value.
					        	else :
					        	    // Do something...
					        	endif;
					        	?>
					        </div>
					    </div>






			        <?php endif; //end if contents get_row_layout?>
					<?php $contentCount++; ?>
			    </div>
			    <?php endwhile; ?>
			<?php endif; ?>


		</section> 

		<?php $count++; ?>

	<?php endwhile; ?>

<?php endif; ?>
<?php  $previousSection = get_row_layout(); ?>
<?php endif; ?>