﻿//Basic Marker
function load_map(autofocus, divMap, lat, lon, zoom) {

    //Setup Map
    var mapOpt = {
        zoom: zoom,
        center: new google.maps.LatLng(lat, lon),
        navigationControl: false,
        scaleControl: true,
        mapTypeControl: true,
        mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
        navigationControl: true,
        navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    //Create Map
    var map = new google.maps.Map($('#' + divMap)[0], mapOpt);

    var cnt;
    cnt = 0;

    var bounds = new google.maps.LatLngBounds();
    //TODO - Add arrow if map should be focused
    if ($("#map_focus").exists()) {
        var point = new google.maps.LatLng($("#map_focus").attr('lat'), $("#map_focus").attr('lon'));
        bounds.extend(point);
        createArrowMarker(map, point);

    }

    $('.results').each(function () {

        cnt = cnt + 1;
        var point = new google.maps.LatLng($(this).attr('lat'), $(this).attr('lon'));
        createImageMarker(map, point, $(this).attr('type'), $(this).html());
        bounds.extend(point);
        
    });

    //Should we autofocus the map?
    if (autofocus == true) {
        map.fitBounds(bounds);
        map.setCenter(bounds.getCenter());
    } else {
        map.setCenter(stateCenter, zoom);
    }

}