<?php get_header(); ?>
	<!-- SLIDER -->
    <?php while ( have_posts() ) : the_post(); ?>

    <header id="header" class="fill-screen-height" style="background-image:url(<?php echo wp_get_attachment_image_url( get_field('top_bg'), 'large'); ?>);">
        <div class="header-info">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-xs-12 col-md-6 col-md-offset-3 col-sm-10 col-sm-offset-1">
                        <h1><a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="logo-big"><img src="<?php the_field('logo', 'options');?>" alt=""></a></h1>
                        <div class="top-content"><?php the_field('top_text'); ?></div>
                        <a href="<?php the_field('top_button_link'); ?>" class="btn btn-white"><?php the_field('top_button_text'); ?></a>
                    </div>
                </div>
            </div>
        </div>

        <?php 
            $args = array(
                'post_type'=> 'announcements',
                'showposts' => 4,
                'meta_key' => 'featured',
                'meta_value' => 1
                ); 

            $anns = new WP_Query($args);
            
            //print_r($anns);
            if( $anns->have_posts() ):
            ?>
        <div class="announcements-block hidden-xs hidden-sm">
            <div class="panel" id="announcements">
                <div class="panel-header">
                    <h3>
                        <svg version="1.1" id="alert-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 612 792" enable-background="new 0 0 612 792" xml:space="preserve" preserveAspectRatio="xMidYMid meet">
                            <g>
                                <path d="M306.023,593c-76.491,0-152.982-0.087-229.473,0.103 c-10.339,0.025-16.798-4.172-21.05-13.464c-11.782-25.748-7.757-46.894,13.16-66.421c2.557-2.387,5.021-4.919,7.817-6.994 c17.617-13.074,26.971-31.183,30.313-52.229c4.017-25.29,6.604-50.804,10.226-76.161c8.277-57.959,25.863-112.216,64.799-157.525 c21.005-24.443,46.897-41.748,78.102-50.548c3.823-1.078,5.132-2.592,5.361-6.654c1.122-19.867,16.729-36.156,35.955-38.06 c20.658-2.045,39.122,10.501,44.312,30.142c0.468,1.767,1.239,3.654,1.006,5.369c-0.944,6.949,3.217,8.494,8.831,10.228 c40.9,12.625,70.87,39.235,93.713,74.594c22.474,34.785,35.794,73.181,42.771,113.71c3.749,21.783,5.169,43.958,8.274,65.866 c1.864,13.148,4.566,26.215,7.587,39.155c3.787,16.229,12.541,29.413,25.422,40.202c7.353,6.158,14.342,13.049,20.239,20.591 c15.112,19.325,11.062,42.415-0.667,61.135c-3.348,5.344-9.025,6.998-15.228,6.979c-16.997-0.052-33.995-0.018-50.992-0.018 C426.342,593,366.183,593,306.023,593z"/>
                                <path d="M355.841,610.553c1.562,22.07-21.928,44.658-47.655,45.939 c-26.807,1.337-51.692-20.353-52.275-45.939C289.227,610.553,322.537,610.553,355.841,610.553z"/>
                            </g>
                        </svg>
                        Announcements
                    </h3>
                </div>
                <?php announcements_header($anns);?>
            </div>
            <a href="#announcements" class="panel-toggle panel-opened">Announcements</a>
        </div>
    <?php endif; wp_reset_postdata(); ?>
    </header>

    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12 col-md-6 col-md-offset-3 col-sm-10 col-sm-offset-1">
                <div class="content">
                    <?php the_content();?>
                </div>
            </div>
        </div>
    </div>
    
    <?php $ctas = get_field('ctas'); 
    if($ctas){ //print_r($ctas);?>
    <section class="cta-wrapper clearfix">
        <?php foreach ($ctas as $key => $cta) {  ?>
            <div class="cta" style="background-image:url(<?php echo wp_get_attachment_image_url( get_post_thumbnail_id($cta->ID), 'half'); ?>);">
                <div class="cta-content">
                    <h3><?php echo $cta->post_title; ?></h3>
                    <p><?php echo apply_filters('the_excerpt', $cta->post_content); ?></p>
                    <div class="text-center">
                        <span class="btn btn-white"><?php echo get_field('text', $cta->ID); ?></span>
                    </div>
                </div>
                <a href="<?php echo get_field('button_link', $cta->ID); ?>" class="cta-link"></a>
            </div>
        <?php } ?>
    </section>
    <?php } ?>


    <?php endwhile; // end of the loop. ?>

    <?php $args = array(
        'post_type' => 'tribe_events',
        'post_status' => 'publish',
        'orderby' => 'meta_value',
        'meta_key' => '_EventStartDate',
        'order' => 'ASC',
        'meta_query' => array(
        'relation' => 'OR',
            array(
                'key' => '_EventStartDate',
                'value' => Date('Y-m-d H:i:s'),
                'compare' => '>'
            ),
        ),
        'showposts' => 3
    ); 
    $events = new WP_Query($args);
    $i=0;
    //print_r($events);
    if( $events->have_posts() ){ ?>
    <section class="upcoming-events">
        <div class="container-fluid">
            <div class="row">
                <div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="text-center">
                                <h2>Upcoming events</h2>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 col-md-6">
                         <?php while( $events->have_posts() ): $events->the_post();?>
                            <?php if($i==1){ ?>
                                </div>
                                <div class="col-xs-12 col-md-6">
                            <?php } ?>
                            <div class="event <?php if($i==0){ echo 'closest';} ?>">
                                
                                <div class="event-image" style='background-image:url("<?php echo wp_get_attachment_image_url( get_post_thumbnail_id(get_the_ID()), 'half'); ?>");'>
                                    <div class="date">
                                        <span>
                                            <?php  echo tribe_get_start_date( null, false, 'M <br/> d' ); ?></span>
                                    </div>
                                </div>
                                <div class="event-content">
                                    <h3 class="event-title"><?php the_title(); ?></h3>
                                    <div class="event-meta">
                                        Where: <?php echo tribe_get_venue(); ?> <br/>
                                        When: <?php echo tribe_events_event_schedule_details(); ?>
                                    </div>
                                    <?php if($i==0){ ?>
                                    <div class="event-text">
                                        <?php  the_excerpt(); ?>
                                    </div>
                                    <?php } ?>
                                </div>
                                <a href="<?php the_permalink(); ?>" class="event-link"></a>
                            </div>
                        <?php $i++; endwhile; ?>

                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="text-center">
                                <a href="<?php  $event_opt = get_option('tribe_events_calendar_options');
    echo home_url().'/'.$event_opt['eventsSlug']; ?>" class="btn btn-red">full calendar</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    
        
    <?php }  wp_reset_postdata();   ?>
    

<?php get_footer(); ?>