﻿var centerPoint;
var magnification;

magnification = 15;

//function WaitForGoogle(andThenCall) {
//    if (typeof (GMap2) != 'undefined') {
//        andThenCall();
//    }
//    else {
//        setTimeout(function() { WaitForGoogle(andThenCall); andThenCall = null; }, 200)
//    }
//}

function initialize(mapClientID, searchString) {
    var map;
    var ALS = [];
    var localSearch;

    //alert(mapClientID + "|" + searchString);
    if (GBrowserIsCompatible()) {
        // Create and Center a Map
        map = new GMap2(document.getElementById(mapClientID));
        map.setCenter(new GLatLng(0, 0), magnification);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        //create search 1 
        localSearch = new GlocalSearch();
        localSearch.setSearchCompleteCallback(null, function() { SearchCallBack(localSearch, map, searchString, ALS) });                 //ddlAircraftType.options(ddlAircraftTypeID.selectedIndex).value, 
        localSearch.setCenterPoint("London");
        //localSearch.setAddressLookupMode(GlocalSearch.ADDRESS_LOOKUP_DISABLED);

        SearchMap(localSearch, searchString)
    }
}

function SearchMap(localSearch, sFromLocation) {
    localSearch.execute(sFromLocation);
    return false;
}

function SearchCallBack(localSearch, map, searchString, results) {
    map.clearOverlays();

    if (localSearch.results == null || localSearch.results.length == 0) {
        return;
    }
    var first = localSearch.results[0];
    map.setCenter(new GLatLng(first.lat, first.lng), magnification, G_NORMAL_MAP);

    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_orange.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);
    map.addOverlay(new GMarker(new GLatLng(first.lat, first.lng), icon));
}

//function loadLocation(map, lat, lng, results) {
//    map.setCenter(new GLatLng(lat, lng), 4, G_NORMAL_MAP);

//    var icon = new GIcon();
//    icon.image = "http://labs.google.com/ridefinder/images/mm_20_orange.png";
//    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
//    icon.iconSize = new GSize(12, 20);
//    icon.shadowSize = new GSize(22, 20);
//    icon.iconAnchor = new GPoint(6, 20);
//    icon.infoWindowAnchor = new GPoint(5, 1);
//    map.addOverlay(new GMarker(new GLatLng(lat, lng), icon));

//    PlotNearestALS(map, mapdetailsid, lat, lng, aircraftType, aircraftType, results);

//}