<!-- indexer::stop -->
<div class="<?= $this->class; ?>block"<?= $this->cssID; ?><?php if ($this->style): ?> style="<?= $this->style; ?>"<?php endif; ?>>
    <?php if ($this->headline): ?>

    <<?= $this->hl; ?>><?= $this->headline; ?></<?= $this->hl; ?>>
<?php endif; ?>

<div class="dlh_googlemap block" id="dlh_googlemap_<?= $this->map['id']; ?>"
     style="width: <?= preg_replace('#\s+#', '', $this->map['mapSize'][0]) . (preg_match('#\d+(\s+)?(%|pcnt)#', $this->map['mapSize'][0]) == 1 ? '' : 'px'); ?>;height:<?= $this->map['mapSize'][1] . $this->map['mapSize'][2]; ?>;">
    <noscript><p><?= ($this->map['staticMapNoscript'] ? $this->map['staticMap'] : $this->labels['noscript']); ?></p></noscript>
</div>

<script>
    if (typeof jQuery == "function") {
        jQuery('#dlh_googlemap_<?= $this->map['id']; ?>').css('width', '<?= $this->map['mapSize'][0] . $this->map['mapSize'][2]; ?>');
        jQuery('#dlh_googlemap_<?= $this->map['id']; ?>').css('height', '<?= $this->map['mapSize'][1] . $this->map['mapSize'][2]; ?>');

        <?php if (!empty($this->map['responsiveSizes'])): ?>
        <?php sort($this->map['responsiveSizes']); foreach ($this->map['responsiveSizes'] as $intBreakpointMax => $arrSize): ?>
        if ($(window).width() <= <?= $intBreakpointMax ?>) {
            jQuery('#dlh_googlemap_<?= $this->map['id']; ?>').css('width', '<?= $arrSize[0] . $arrSize[2]; ?>');
            jQuery('#dlh_googlemap_<?= $this->map['id']; ?>').css('height', '<?= $arrSize[1] . $arrSize[2]; ?>');
        }
        <?php endforeach; ?>
        <?php endif; ?>
    }

    function gmap<?= $this->map['id']; ?>_initialize() {
        var <?php if ($this->map['infoWindowUnique']): ?>lastInfoWindow = null,<?php endif; ?>
            gmap<?= $this->map['id']; ?>_Options = {

                zoom: <?= $this->map['zoom']; ?>
                , center: new google.maps.LatLng(<?= $this->map['center']; ?>)
                , mapTypeId: google.maps.MapTypeId.<?= $this->map['mapTypeId']; ?>
                , draggable: <?= $this->map['draggable']; ?>
                , disableDoubleClickZoom: <?= $this->map['disableDoubleClickZoom']; ?>
                , scrollwheel: <?= $this->map['scrollwheel']; ?>


                <?php if ($this->map['useMapTypeControl']) : ?>
                , mapTypeControl: true
                , mapTypeControlOptions: {
                    style: google.maps.MapTypeControlStyle.<?= $this->map['mapTypeControlStyle']; ?>
                    , position: google.maps.ControlPosition.<?= $this->map['mapTypeControlPos']; ?>
                    <?php if (is_array($this->map['mapTypesAvailable'])) : ?>
                    , mapTypeIds: [
                        <?php foreach($this->map['mapTypesAvailable'] as $k=>$v) : ?>
                        <?php if ($k > 0)
                        {
                            echo ',';
                        } ?>google.maps.MapTypeId.<?= $v; ?>
                        <?php endforeach; ?>
                    ]
                    <?php endif; ?>
                }
                <?php else : ?>
                , mapTypeControl: false
                <?php endif; ?>


                <?php if ($this->map['useOverviewMapControl']) : ?>
                , overviewMapControl: true
                , overviewMapControlOptions: {
                    opened: <?= ($this->map['overviewMapControlOpened'] ? 'true' : 'false'); ?>
                }
                <?php else : ?>
                , overviewMapControl: false
                <?php endif; ?>


                <?php if ($this->map['useStreetViewControl']) : ?>
                , streetViewControl: true
                , streetViewControlOptions: {
                    position: google.maps.ControlPosition.<?= $this->map['streetViewControlPos']; ?>
                }
                <?php else : ?>
                , streetViewControl: false
                <?php endif; ?>


                <?php if ($this->map['useRotateControl']) : ?>
                , rotateControl: true
                , rotateControlOptions: {
                    position: google.maps.ControlPosition.<?= $this->map['rotateControlPos']; ?>
                }
                <?php else : ?>
                , rotateControl: false
                <?php endif; ?>


                <?php if ($this->map['usePanControl']) : ?>
                , panControl: true
                , panControlOptions: {
                    position: google.maps.ControlPosition.<?= $this->map['panControlPos']; ?>
                }
                <?php else : ?>
                , panControl: false
                <?php endif; ?>


                <?php if ($this->map['useZoomControl']) : ?>
                , zoomControl: true
                , zoomControlOptions: {
                    style: google.maps.ZoomControlStyle.<?= $this->map['zoomControlStyle']; ?>,
                    position: google.maps.ControlPosition.<?= $this->map['zoomControlPos']; ?>
                }
                <?php else : ?>
                , zoomControl: false
                <?php endif; ?>


                <?php if ($this->map['useScaleControl']) : ?>
                , scaleControl: true
                , scaleControlOptions: {
                    position: google.maps.ControlPosition.<?= $this->map['scaleControlPos']; ?>
                }
                <?php else : ?>
                , scaleControl: false
                <?php endif; ?>


                <?php if ($this->map['parameter']) : ?>
                , <?= $this->map['parameter']; ?>
                <?php endif; ?>

            };

        gmap<?= $this->map['id']; ?> = new google.maps.Map(document.getElementById("dlh_googlemap_<?= $this->map['id']; ?>"), gmap<?= $this->map['id']; ?>_Options);

        // create your own custom control
        <?php if ($this->map['useCustomControl']) : ?>
        var centerControlDiv = document.createElement('button');
        centerControlDiv.className = 'button googleMaps_customControl';
        <?php if ($this->map['customControlHTML'] !== '') : ?>
        centerControlDiv.innerHTML = '<?= $this->map['customControlHTML']; ?>';
        <?php endif; ?>
        centerControlDiv.index = 1;
        gmap<?= $this->map['id']; ?>.controls[google.maps.ControlPosition.<?= $this->map['customControlPos']; ?>].push(centerControlDiv);
        <?php else : ?>
        <?php endif; ?>

        <?php if ($this->map['customControlAction'] === 'RESIZE') : ?>
        $(document).on('click', '.googleMaps_customControl', function () {
            google.maps.event.trigger(gmap<?= $this->map['id']; ?>, "resize");
            gmap<?= $this->map['id']; ?>.setCenter(new google.maps.LatLng(<?= $this->map['elements'][0]['data']['singleCoords']; ?>));
        });
        <?php endif; ?>

        <?php if ($this->map['moreParameter']) : echo $this->map['moreParameter']; endif; ?>

        // create bounds object to fit markers into current map boundaries
        var bounds = new google.maps.LatLngBounds();

        var markers = [];

        // Auto-generated map elements
        <?php foreach($this->map['elements'] AS $element): ?>
        //extend the bounds to include each marker's position
        <?= $element['parsed']; ?>
        // extend the bounds with current marker position
        if (typeof gmap<?= $element['data']['id'] ?>_marker !== 'undefined'){
            markers.push(gmap<?= $element['data']['id'] ?>_marker);
            if (typeof gmap<?= $element['data']['id'] ?>_marker.position !== 'undefined')
                bounds.extend(gmap<?= $element['data']['id'] ?>_marker.position);
        }
        <?php endforeach; ?>

        <?php if($this->map['cluster']): ?>
            var markerCluster = new MarkerClusterer(gmap<?= $this->map['id']; ?>, markers,{imagePath: '<?= $this->map['clusterImagePath']; ?>'});
        <?php endif; ?>

        //now fit the map to the newly inclusive bounds
        <?php if(count($this->map['elements']) > 1): ?>
        gmap<?= $this->map['id']; ?>.fitBounds(bounds);
        <?php elseif(count($this->map['elements']) == 1): ?>
        gmap<?= $this->map['id']; ?>.setCenter(bounds.getCenter());
        gmap<?= $this->map['id']; ?>.setZoom(<?= $this->map['zoom'] > 16 ? 16 : $this->map['zoom']; ?>);
        <?php endif; ?>

        if (window.gmap<?= $this->map['id']; ?>_dynmap) {
            gmap<?= $this->map['id']; ?>_dynmap(gmap<?= $this->map['id']; ?>);
        }

        <?php
        // tabcontrol
        echo $this->tabs ? $this->map['tabsCode'] : ''; ?>
    }

    if (window.addEvent) {
        window.addEvent('domready', function () {
            gmap<?= $this->map['id']; ?>_initialize();
        });
    } else if (typeof jQuery === "function") {
        jQuery(document).ready(function () {
            gmap<?= $this->map['id']; ?>_initialize();
        });

        jQuery(document).on('shown.bs.modal', function () {
            google.maps.event.trigger(gmap<?= $this->map['id']; ?>, "resize");
            gmap<?= $this->map['id']; ?>.setCenter(new google.maps.LatLng(<?= $this->map['elements'][0]['data']['singleCoords']; ?>));
        });
    } else {
        window.setTimeout("gmap<?= $this->map['id']; ?>_initialize()", 500);
    }
</script>

</div>
<!-- indexer::continue -->

