﻿// JScript File
var geocoder;
var map;
var mgr;
var count = 0;

function initialize() 
{      
    if (!GBrowserIsCompatible())     
    {    
        var div = document.getElementById("map_canvas");
        div.text = "Not Available";
    }
    else
    {
        initializeMap();
    }
}

function initializeMap()        
{
    map = new GMap2(document.getElementById("map_canvas"));
    geocoder = new GClientGeocoder();
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());

    geocoder.getLocations("Kansas City, Kansas", 
        function(response)
        {
            if (!response || response.Status.code != 200) 
            {    
                map.setCenter(new GLatLng(37.4419, -122.1419), 3);
//                GEvent.addListener(map, "infowindowclose",
//                    function() {
//                        map.setCenter(new GLatLng(37.4419, -122.1419), 3);
//                    }
//                );
            }        
            else
            {
                place  = response.Placemark[0];
                map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), 3);
//                GEvent.addListener(map, "infowindowclose",
//                    function() {
//                        map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), 3);
//                    }
//                );

                populate();
            }
        }
    );

    }

function addOverlay(response) {
    if (!response || response.Status.code != 200) 
        return;
    else
    {
        var place  = response.Placemark[0];
        var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);              
        var marker = new GMarker(point);
        marker.jobs = eval(response.name.replace(" ", "")); //eval(response.name.split(",",2)[1]);
        map.addOverlay(marker);
        GEvent.addListener(marker, "click",
            function() 
            {  
             var myHtml;
             myHtml = this.jobs;
             map.openInfoWindowHtml(this.getLatLng(), myHtml);
            }
        );
    }
}


function pause(numberMillis) 
{
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) 
    {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}

//function getPoint(address)
//{
//    var geocoder = new GClientGeocoder();
//    geocoder.GetLocations(address, addOverlay);
//}


