﻿if (window.attachEvent)
{
    window.attachEvent("onload", 
        function() {
            window.attachEvent("onunload", GUnload);
        });
}
else
{
    window.addEventListener("load", 
        function() {
            window.addEventListener("unload", GUnload, false);
        }, 
        false);
}


var googlemap_pos;
var googlemap_marker;
var googlemap_loaded = false;
var map = null;

function showMap(latitude, longitude)
{
    googlemap_loaded = false;
    
    if (GBrowserIsCompatible())
    {
        if (map)
            map.clearOverlays();
        else
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(latitude,longitude), 16);
        
        // Create a base icon for all of our markers that specifies the
        // shadow, icon dimensions, etc.
        var baseIcon = new GIcon();
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);

        // Creates a marker whose info window displays the letter corresponding
        // to the given index.
        function createMarker(point, index) {
            // Create a lettered icon for this point using our icon class
            var letter = String.fromCharCode("X".charCodeAt(0) + index);
            var icon = new GIcon(baseIcon);
            icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
            var marker = new GMarker(point, icon);

            GEvent.addListener(marker, "mouseover", 
                function() {
                    marker.openInfoWindowHtml("<strong>Esmevi</strong><br/>c/ Ter 44<br/>08570 Torrelló<br/>Barcelona<br />Tel. <strong>93 859 07 35</strong>");
                });
            return marker;
        }

        // Add 1 markers to the map at the location
        var point = new GLatLng(latitude,longitude);
        map.addOverlay(createMarker(point, 0));

        googlemap_loaded = true;
        
        map_open("map");
        
        return false;
        }
    }
   