﻿var imgHelaBilen = new google.maps.MarkerImage(
  '/wp-content/themes/helabilen/images/hela_bilen_pin.png',
  new google.maps.Size(100,90),
  new google.maps.Point(0,0),
  new google.maps.Point(20, 90)
);
var helabilenPlaces = [
    {
        title:     'HelaBilen Västkustvägen',
        address:   'Västkustvägen 21<br />21124 Malmö',
        telephone: '040 - 185454',
        email:     'info@helabilen.se',
        www:       'www.helabilen.se',
        booking:   'http://helabilen.se/boka-tid',
        longLat:   [55.614803, 13.033023]
    }
    ,{
        title:     'HelaBilen Fosie',
        address:   'Agnesfridsvägen 185c<br />21375 Malmö',
        telephone: '040 - 221143',
        email:     'info@helabilen.se',
        www:       'www.helabilen.se',
        booking:   'http://helabilen.se/boka-tid',
        longLat:   [55.563666, 13.043418]
    }
    ,{
        title:     'HelaBilen Västerås',
        address:   'Gunnilbogatan 2<br />72340 Västerås',
        telephone: '021 - 180030',
        email:     'vasteras@helabilen.se',
        www:       'vasteras.helabilen.se',
        booking:   '',
        longLat:   [59.626767, 16.583527]
    }
    ,{
        title:     'HelaBilen Västerås',
        address:   'Kokillgatan 2<br />72133 Västerås',
        telephone: '021 - 180030',
        email:     'vasteras@helabilen.se',
        www:       'vasteras.helabilen.se',
        booking:   '',
        longLat:   [59.597504,16.489406]
    }
];
function RenderMap(id, height, zoom, centerLat, centerLng)
{
    document.write('<div id="' + id + '" style="height: ' + height + 'px;"></div>');
    var map = new google.maps.Map(document.getElementById(id), {
        zoom:      zoom,
        center:    new google.maps.LatLng(centerLat, centerLng),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    
    for(var i in helabilenPlaces){
        var place = helabilenPlaces[i];
        createMarker(map, place);
    }
}
function createMarker(map, place){
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(place.longLat[0], place.longLat[1]),
        map:      map,
        icon:     imgHelaBilen
    });
    var info = new google.maps.InfoWindow({
        content: [
            '<strong>', place.title, '</strong><br>',
            place.address, '<br >/',
            'Tel:', place.telephone, '<br>',
            'Mail: <a href=mailto:"', place.email, '">', place.email, '</a><br>',
            '<a href="', place.www, '">Hemsida</a> | ',
            place.booking ? '<a href="' + place.booking + '">Boka tid</a>' : ''
            ].join('')
    });
    google.maps.event.addListener(marker, 'click', function(){ 
        info.open(map, marker); 
    });
}
