﻿
// Note that using Google Gears requires loading the Javascript
// at http://code.google.com/apis/gears/gears_init.js

var gm_map;
var gm_geocoder;

function gm_Init(zoom, bigMap) {
    gm_geocoder = new google.maps.Geocoder();
    var myOptions = {
        zoom: zoom,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    gm_map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    if (bigMap) {
        gm_map.setCenter(new google.maps.LatLng(62.573106, 18.676758));
    }
}

function gm_InitInfoWindows(setCenter) {
    for (var i = 0; i < _varuhusArr.length; i++) {
        var addr = "Bygma " + _varuhusArr[i][3];
        var lat = parseFloat(_varuhusArr[i][7].split(",")[0]);
        var lng = parseFloat(_varuhusArr[i][7].split(",")[1]);
        var pos = new google.maps.LatLng(lat, lng);
        if (_varuhusArr[i][7] != "") {
            gm_CodeAddress(
                pos,
                "<a href=\"" + _varuhusArr[i][8] + "\" style=\"text-decoration:none\">" +
                "<strong>" + addr + "</strong><br /><br />" +
                "<span style=\"color:#000\">" +
                _varuhusArr[i][1] + "<br />" +
                _varuhusArr[i][2] + " " + _varuhusArr[i][3] + "<br /><br />" +
                "Telefon: " + _varuhusArr[i][4] + "<br />" +
                "E-post: " + _varuhusArr[i][5] + "<br /><br />" +
                "</span>" +
                "Mer information" +
                "</a>",
                setCenter
            );
        }
    }
}

var _gm_OpenInfoWindow = null;

function gm_CodeAddress(pos, content, setCenter) {
    var image = "/images/map-marker.png";
    var marker = new google.maps.Marker({
        position: pos,
        map: gm_map,
        icon: image
    });
    if (setCenter)
        gm_map.setCenter(pos);
    if (content != null) {
        var infowindow = new google.maps.InfoWindow({
            content: content,
            maxWidth: "150"
        });
        google.maps.event.addListener(marker, 'click', function () {
            if (_gm_OpenInfoWindow)
                _gm_OpenInfoWindow.close();
            _gm_OpenInfoWindow = infowindow;
            infowindow.open(gm_map, marker);
        });
    }
}

/*
function gm_CodeAddress(address, content, setCenter) {
    gm_geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var pos = results[0].geometry.location;
            var image = "/images/map-marker.png";
            var marker = new google.maps.Marker({
                position: pos,
                map: gm_map,
                icon: image
            });
            if (setCenter)
                gm_map.setCenter(pos);
            if (content != null) {
                var infowindow = new google.maps.InfoWindow({
                    content: content,
                    maxWidth: "150"
                });
                google.maps.event.addListener(marker, 'click', function () {
                    if (_gm_OpenInfoWindow)
                        _gm_OpenInfoWindow.close();
                    _gm_OpenInfoWindow = infowindow;
                    infowindow.open(gm_map, marker);
                });
            }
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
}
*/
