<?php if ($this->element['singleCoords'] && $this->element['markerType']) : ?>
    var gmap<?= $this->element['id']; ?>_marker = new google.maps.Marker({
    position: new google.maps.LatLng(<?= $this->element['singleCoords']; ?>)
    , map: gmap<?= $this->map; ?>
    <?php if($this->element['markerType']=='ICON') : ?>
        <?php if($this->element['iconSRC'] && $this->element['iconSize'][0] && $this->element['iconSize'][1]) : ?>
            , icon: new google.maps.MarkerImage(
            '<?php echo $this->element['iconSRC']; ?>'
            , new google.maps.Size(<?php echo $this->element['iconSize'][0].','.$this->element['iconSize'][1]; ?>)
            , new google.maps.Point(0,0)
            , new google.maps.Point(<?php echo $this->element['iconAnchor'][0].','.$this->element['iconAnchor'][1]; ?>)
            , new google.maps.Size(<?php echo $this->element['iconSize'][0].','.$this->element['iconSize'][1]; ?>)
            )
        <?php endif; ?>
        <?php if($this->element['shadowSRC'] && $this->element['shadowSize'][0] && $this->element['shadowSize'][1]) : ?>
            , shadow: new google.maps.MarkerImage(
            '<?php echo $this->element['shadowSRC']; ?>'
            , new google.maps.Size(<?php echo $this->element['shadowSize'][0].','.$this->element['shadowSize'][1]; ?>)
            , new google.maps.Point(0,0)
            , new google.maps.Point(<?php echo $this->element['iconAnchor'][0].','.$this->element['iconAnchor'][1]; ?>)
            , new google.maps.Size(<?php echo $this->element['shadowSize'][0].','.$this->element['shadowSize'][1]; ?>)
            )
        <?php endif; ?>
    <?php elseif($this->element['fillColor']): ?>
        , icon: new google.maps.MarkerImage('<?php echo (\Environment::get('ssl') ? 'https://chart.googleapis.com' : 'http://chart.apis.google.com'); ?>/chart?chst=d_map_pin_letter&chld=%E2%80%A2|<?php echo $this->element['fillColor']; ?>'
        , new google.maps.Size(21,34)
        , new google.maps.Point(0,0)
        , new google.maps.Point(10,34))
        , shadow: new google.maps.MarkerImage('<?php echo (\Environment::get('ssl') ? 'https://chart.googleapis.com' : 'http://chart.apis.google.com'); ?>/chart?chst=d_map_pin_shadow'
        , new google.maps.Size(40,37)
        , new google.maps.Point(0,0)
        , new google.maps.Point(12,35))
    <?php endif; ?>
    <?php if($this->element['markerAction'] == 'LINK' && $this->element['linkTitle']) : ?>
        , title:"<?= $this->element['linkTitle']; ?>"
    <?php elseif ($this->element['markerShowTitle']) : ?>
        , title:"<?= $this->element['title']; ?>"
    <?php endif; ?>
    <?php if ($this->element['zIndex']) : ?>
        , zIndex: <?= $this->element['zIndex']; ?>
    <?php endif; ?>
    <?php if ($this->element['parameter']) : ?>
        , <?= $this->element['parameter']; ?>
    <?php endif; ?>
    });
    <?php if($this->element['markerAction'] == 'INFO') : ?>
        <?php if($this->element['useRouting']) {
            $routingPoint = ($this->element['routingAddress'] ? $this->element['routingAddress'] : $this->element['singleCoords']);
            $routingLink = '<div class="routinglink">' . str_replace('?','<a href="https://www.google.com/maps/preview?saddr=&daddr=' . urlencode($routingPoint) . '&ie=UTF8&hl=' . $GLOBALS['TL_LANGUAGE'] . '" onclick="window.open(this.href); return false;">' . str_replace(' ','[nbsp]',$this->element['labels']['routingLink']) . '</a>', str_replace(' ','[nbsp]',$this->element['labels']['routingLabel'])) . '<br><form action="http://maps.google.com/maps" method="get" target="_new"><input type="hidden" name="daddr" value="' . $routingPoint . '"><input type="hidden" name="ie" value="UTF8"><input type="hidden" name="hl" value="' . $GLOBALS['TL_LANGUAGE'] . '"><input type="text" class="text" name="saddr" /><input type="submit" class="submit" value="' . $this->element['labels']['routingSubmit'] . '" /></form><\/div>';
        } else {
            $routingLink = '';
        } ?>
        var gmap<?= $this->element['id']; ?>_infowindow = new google.maps.InfoWindow({
        position: new google.maps.LatLng(<?= $this->element['singleCoords']; ?>),
        <?php if ($this->element['infoWindowAnchor'][0]!=0 || $this->element['infoWindowAnchor'][1]!=0) : ?>
            pixelOffset: new google.maps.Size(<?= $this->element['infoWindowAnchor'][0].','.$this->element['infoWindowAnchor'][1]; ?>),
        <?php endif; ?>
        content: '<div<?= $this->element['infoWindowSize']; ?>><?= $this->element['infoWindow'] . $routingLink; ?><\/div>'
        <?php if ($this->element['infoWindowMaxWidth']) : ?>
            , maxWidth: <?= $this->element['infoWindowMaxWidth'] ?>
        <?php endif; ?>
        });
        google.maps.event.addListener(gmap<?= $this->element['id']; ?>_marker, 'click', function() {
            <?php if ($this->element['infoWindowUnique']): ?>
            if (lastInfoWindow != null)
                lastInfoWindow.close();

            lastInfoWindow = gmap<?= $this->element['id']; ?>_infowindow;
            <?php endif; ?>

            gmap<?= $this->element['id']; ?>_infowindow.open(gmap<?= $this->map; ?>);
        });
        <?php if($this->element['popupInfoWindow']) : ?>
            gmap<?= $this->element['id']; ?>_infowindow.open(gmap<?= $this->map; ?>);
        <?php endif; ?>
    <?php elseif($this->element['markerAction'] == 'LINK') : ?>
        google.maps.event.addListener(gmap<?= $this->element['id']; ?>_marker, 'click', function() {
        <?php if($this->element['target']) : ?>
            window.open('<?= $this->element['url']; ?>','_blank','resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes');
        <?php else :?>
            window.location.href='<?= $this->element['url']; ?>';
        <?php endif; ?>
        });
    <?php elseif($this->element['markerAction'] == 'MODAL') : ?>
        google.maps.event.addListener(gmap<?= $this->element['id']; ?>_marker, 'click', function(e) {
            var $modal = $('<?= $this->element['target']?>');
            var  $replace = $modal.find('.modal-dialog');

            history.pushState({url: '<?= $this->element['url']?>'}, null, '<?= $this->element['url']?>');

            $.ajax({
                'url': '<?= $this->element['url']?>',
                'data' : {
                    'scope' : 'modal',
                    'target': $modal.attr('id')
                }
            }).done(function(responseText, textStatus, jqXHR){
                try {
                    dataJson = $.parseJSON(responseText);

                    if (dataJson.type == 'redirect') {
                        if (typeof history.replaceState !== 'undefined')
                        {
                        history.replaceState({url: dataJson.url}, null, dataJson.url);
                        }
                        $replace.load(dataJson.url, function (responseText, textStatus, jqXHR) {
                            $modal.modal('show');
                         });
                        return false;
                    }
                } catch (e) {
                // fail silently
                }
                $replace.html(responseText);
                $modal.modal('show');
            });
        });
    <?php endif; ?>
<?php endif; ?>