﻿var gicons = [];
gicons["Hotel"] = new GIcon();
gicons["Hotel"].image = "/images/googlemap/hotels.png";
gicons["Hotel"].shadow = "/images/googlemap/hotels_s.png";
gicons["Hotel"].iconSize = new GSize(14, 14);

gicons["Hotel"].iconAnchor = new GPoint(7, 7);
gicons["Hotel"].infoWindowAnchor = new GPoint(14, 0);

gicons["Event"] = new GIcon(gicons["Hotel"]);
gicons["Event"].image = "/images/googlemap/events.png";

gicons["Attraction"] = new GIcon(gicons["Hotel"]);
gicons["Attraction"].image = "/images/googlemap/attractions.png";

gicons["OutdoorRecreation"] = new GIcon(gicons["Hotel"]);
gicons["OutdoorRecreation"].image = "/images/googlemap/outdoorRecreation.png";

var starIcon = new GIcon();
starIcon.image = "/images/googlemap/superstar.gif";
starIcon.iconSize = new GSize(21, 20);
starIcon.iconAnchor = new GPoint(10, 10);

gicons["Star"] = starIcon;

var gmarkers = [];
var markerCount = 0;

function createDirectMarker(point, url) {

    var marker = new GMarker(point);

    GEvent.addListener(marker, "click", function() {
        //window.location = url; 
    });

    gmarkers[markerCount] = marker;
    markerCount += 1;
    return marker;
}
function createMarker(point, html) {

    var marker = new GMarker(point);

    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
    });

    gmarkers[markerCount] = marker;
    markerCount += 1;
    return marker;
}
function createCustomMarker(point, icon, html) {

    var marker = new GMarker(point, icon);

    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
    });

    gmarkers[markerCount] = marker;
    markerCount += 1;
    return marker;
}
function createMarkerWithRecenter(point, html, map) {

    var marker = new GMarker(point);

    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);

        var currentCenter = map.getCenter();
        var targetDest = marker.getLatLng();
        var zoom = map.getZoom();

        if (zoom < 10) {
            if (currentCenter.lat() < targetDest.lat()) {
                var destination = new GLatLng(targetDest.lat() - .04, targetDest.lng());
                map.panTo(destination);
            }
            else // if the center is above and we're moving down, move down a little more...
            {
                var destination = new GLatLng(targetDest.lat() + .04, targetDest.lng());
                map.panTo(destination);
            }
        }
        else {
            //map.setCenter(targetDest);
        }
    });

    gmarkers[markerCount] = marker;
    markerCount += 1;
    return marker;
}
function createCustomMarkerWithRecenter(point, icontype, html, map) {

    var marker = new GMarker(point, gicons[icontype]);

    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);

        var currentCenter = map.getCenter();
        var targetDest = marker.getLatLng();
        var zoom = map.getZoom();
        //alert("Current zoom level is " + zoom);

        if (zoom < 10) {
            if (currentCenter.lat() < targetDest.lat()) {
                var destination = new GLatLng(targetDest.lat() - .04, targetDest.lng());
                map.panTo(destination);
            }
            else // if the center is above and we're moving down, move down a little more...
            {
                var destination = new GLatLng(targetDest.lat() + .04, targetDest.lng());
                map.panTo(destination);
            }
        }
        else {
            //map.setCenter(targetDest);
        }
    });

    gmarkers[markerCount] = marker;
    markerCount += 1;
    return marker;
}
