var map, tooltip;
var clickPoints = '';
var Polygons = new Array();

function createPoly(pointData) 
{
    var baseIcon = new GIcon();
    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);

    var letteredIcon = new GIcon(baseIcon);
    letteredIcon.image = "/images/marker.png";

    var markerOptions = { icon:letteredIcon };
    var tmpLatLng = new GLatLng(pointData.latitude,pointData.longitude);
    marker = new GMarker(tmpLatLng,markerOptions);

    GEvent.addListener(marker, "click", function() {
        location.href = pointData.url;
    });

    return marker;
}

function init() 
{ 
    //map = new GMap(document.getElementById("map")/*, {draggableCursor: 'crosshair'}*/);
    /*map.addControl(new GLargeMapControl3D());
    map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

    // display the PHP generated markers/polygons
    tooltip = document.createElement("div");
    tooltip.className = "tooltip";
    map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);
    //this is done to get the mouse position and set the tooltip over the polygon. There can only be one mousemove function used on a page.
    GEvent.addListener(map, 'mousemove', function (point)
    {
        currtype = map.getCurrentMapType().getProjection();
        startPoint = currtype.fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0, 0), true), map.getZoom());
        var offset = currtype.fromLatLngToPixel(point, map.getZoom());
        var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - startPoint.x + 7, offset.y - startPoint.y + 7));
        pos.apply(tooltip);
    });*/

    /*for(id in markers)
    {
        var marker = createPoly(markers[id]);
        Polygons[markers[id].id] = marker;
        map.addOverlay(marker);
    }*/
}

function moveToMarker(locationId)
{
    $('body').scrollTo('.rates', 500);
    
    var i = 0;
    for(id in markers) {
        if (locationId == markers[id].id) {
        	$('#mtgt_unnamed_'+i).attr('src', '/images/marker_blue.png');
            map.setCenter(new GLatLng(markers[id].latitude, markers[id].longitude), 16);
        }
        else
        {
        	$('#mtgt_unnamed_'+i).attr('src', '/images/marker.png');
        }
        i++;
    }
}

$(document).ready(init);
window.onunload = GUnload;
