﻿google.load("maps", "2");
var map;
var baseIcon;
var i;
var markers;
var bounds;
     
function initialize()
{
}

function initMap()
{
    i = 1;
    markers = [10];
    bounds = new GLatLngBounds();

    if (GBrowserIsCompatible())
    {
        map = new google.maps.Map2(document.getElementById("map"));
        map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
        
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.enableDoubleClickZoom();
        map.addControl(new GOverviewMapControl());

        baseIcon = new GIcon();
        //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(35, 31);
        //baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(0, 0);
        baseIcon.infoWindowAnchor = new GPoint(18, 18);
        baseIcon.infoShadowAnchor = new GPoint(18, 18);
        
        //createMarker(37.4219, -122.1219, "Test Store", "123 Some Street", "801-123-4567", i++);
        //createMarker(37.4519, -122.1519, "Test Store5", "1235 Some Street", "801-123-4567", i++);
    }
}

function initPrintMap()
{
    i = 1;
    markers = [1];
    bounds = new GLatLngBounds();

    if (GBrowserIsCompatible())
    {
        map = new google.maps.Map2(document.getElementById("map"));
        map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
        
        //map.addControl(new GSmallMapControl());
        //map.addControl(new GMapTypeControl());
        //map.enableDoubleClickZoom();
        //map.addControl(new GOverviewMapControl());

        baseIcon = new GIcon();
        //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(35, 31);
        //baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(0, 0);
        baseIcon.infoWindowAnchor = new GPoint(18, 18);
        baseIcon.infoShadowAnchor = new GPoint(18, 18);
        
        //createMarker(37.4219, -122.1219, "Test Store", "123 Some Street", "801-123-4567", i++);
        //createMarker(37.4519, -122.1519, "Test Store5", "1235 Some Street", "801-123-4567", i++);
    }
}
    
function createMarker(lat, lng, name, content, i)
{
    // Create a lettered icon for this point using our icon class

    //var marker;
    var _icon = new GIcon(baseIcon);
    _icon.image = "./images/Marker" + i + ".png";
    _icon.iconSize = new GSize(28, 28);

    // Set up our GMarkerOptions object
    markerOptions = { icon:_icon, title:name };
    var point = new GLatLng(lat, lng);
    markers[i] = new GMarker(point, markerOptions);
    
    map.addOverlay(markers[i]);
    bounds.extend(markers[i].getLatLng());

    GEvent.addListener(markers[i], "click", function()
    {
        markers[i].openInfoWindowHtml(content);
    });
}

function zoomAndCenter()
{
    map.setZoom(map.getBoundsZoomLevel(bounds));
    map.setCenter(bounds.getCenter());
}

function zoomAndCenterPrint()
{
    map.setZoom(15);
    map.setCenter(bounds.getCenter());
}

function CenterMap(_i)
{
    if(_i == 0)
    {
        map.setCenter(bounds.getCenter()); map.getInfoWindow().hide()
    }
    else
    {
        map.setZoom(13);
        map.setCenter(markers[_i].getPoint());
        GEvent.trigger(markers[_i], "click");             
    }
}

google.setOnLoadCallback(initialize);
