<?php /* Template name: Amenities page */
get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
    <?php if(has_post_thumbnail()){ 
        $id = get_post_thumbnail_id( get_the_ID()  ); 
        $url = wp_get_attachment_image_url($id, 'large'); } 
        else { $url = get_bloginfo('template_url').'/img/hero-image.jpg'; } ?>
    <header id="header" style="background-image:url(<?php echo $url; ?>);">
        <div class="header-info">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-xs-12 col-lg-6 col-lg-offset-3 col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1">
                        <h1><?php the_title(); ?></h1>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12 col-lg-6 col-lg-offset-3 col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1">
                <div class="content">
                    <?php the_content(); ?>
                </div>
            </div>
        </div>
    </div>

    <?php 
        $args = array(
            'post_type' => 'amenity',
            'post_status' => 'publish',
            'showposts' => -1,
            'order' => 'ASC'
            );
        $offices = new WP_Query($args);
        if( $offices->have_posts()): ?>
        <div class="container-fluid">
        <div class="row">
            
            <?php $i=1;
            while( $offices->have_posts() ): $offices->the_post(); ?>
                <?php if(has_post_thumbnail()){ 
                $id = get_post_thumbnail_id( get_the_ID()  ); 
                $url = wp_get_attachment_image_url($id, 'half'); } 
                else { $url = get_bloginfo('template_url').'/img/hero-image.jpg'; } ?>
                <div class="ammenity <?php if($i%2==1){ echo 'image-left';}  ?>">
                    <div class="ammenity-<?php if($i%2==1){ echo 'left';} else { echo 'right'; }?> ammenity-image" style="background-image:url('<?php echo $url; ?>');">
                    </div>
                    <div class="ammenity-<?php if($i%2==1){ echo 'right';} else { echo 'left'; }?>">
                        <div class="ammenity-content" id="content-id-<?php the_ID(); ?>">
                            <?php $cut = check_length(); 
                            if($cut){ ?>
                            <div class="truncated">
                                <h2><?php the_title(); ?></h2>
                                <?php clever_excerpt(200, get_the_content() );?>
                            </div>
                            <div class="full">
                                <h2><?php the_title(); ?></h2>
                                <?php the_content(); ?>
                            </div>
                            <?php } else { ?>
                                <div class="ammenity-content">
                                    <h2><?php the_title(); ?></h2>
                                    <?php the_content(); ?>
                                </div>
                            <?php } ?>
                        </div>
                        <?php if( $cut ){ ?>
                        <button class="btn btn-red ammenity-toggle" data-target="#content-id-<?php the_ID(); ?>">Read More</button>
                        <?php } ?>
                    </div>
                </div>
            <?php $i++; endwhile;
            else:
                get_template_part( 'content', 'none' );
            endif;

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

<?php get_footer(); ?>