<?php /* Template name: Contact 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 id="map"></div>
        <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 class="row">
                        <div class="col-xs-12 col-sm-6">
                            <div class="contact-block">
                                <h3>Office</h3>
                                <?php the_field('address', 'options'); ?><br/>
                                <strong>Phone:</strong> <?php the_field('phone', 'options'); ?><br/>
                                <strong>Fax:</strong> <?php the_field('fax', 'options'); ?><br/>
                                <?php the_field('email', 'options'); ?>
                            </div>
                        </div>
                        <div class="col-xs-12 col-sm-6">
                            <div class="contact-block">
                                <h3>Clubhouse &amp; Pool</h3>
                                <strong>Phone:</strong> <?php the_field('pool_phone', 'options'); ?><br/>
                                <?php the_field('pool_email', 'options'); ?>
                            </div>
                        </div>
                    </div>
                    <?php echo do_shortcode('[contact-form-7 id="4"]'); ?>
                </div>
            </div>
        </div>
    </div>

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


<script type="text/javascript">

        jQuery(document).ready(function ($) {

            // Google Map
            var map;
            var geocoder;
            geocoder = new google.maps.Geocoder();

            var keyweb = new google.maps.LatLng(35, 82);
            //var address ="Tuckahoe Presbyterian Church, Park Avenue, Richmond, VA, United States";
            var address ="<?php the_field('address', 'options'); ?>";

            function initialize() {


                var mapOptions = {
                    zoom: 15,
                    center: keyweb,
                    scrollwheel: false,
                    scaleControl: false
                };

                var infowindow = new google.maps.InfoWindow({
                    content: '<h1><?php bloginfo("name"); ?></h1>'
                });

                map = new google.maps.Map(document.getElementById('map'),
                        mapOptions);
                console.log (address);
                geocoder.geocode( { 'address': address}, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        map.setCenter(results[0].geometry.location);
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location,
                            title: '<?php bloginfo("name"); ?>',
                            labelContent: '<?php bloginfo("name"); ?>'
                        });
                        google.maps.event.addListener(marker, 'click', function() {
                          infowindow.open(map,marker);
                        });
                    } else {
                        alert('<?php echo __("Geocode was not successful for the following reason:", "keyweb" ); ?>' + status);
                    }
                });

                
            }

            google.maps.event.addDomListener(window, 'load', initialize);

        });
    </script>

<?php get_footer(); ?>
