//initial load of the map set to a latitude, longitude and zoom level
function show_map(lt, ln, zoom, controls, marker) 
{
	var ltln = new google.maps.LatLng(lt, ln);
	var vars = {
		zoom: zoom,
		center: ltln,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: controls,
		navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN} ,
		mapTypeControl: false,
		scaleControl: false,
		scrollwheel: false,
        streetViewControl: false
	};
	map = new google.maps.Map(document.getElementById("map_canvas"), vars);

    if(marker)
    {
        new google.maps.Marker({
		    position: ltln, 
		    map: map
	    });
    }
    else
    {
        var KmOverlay = new KmBox(map, new google.maps.LatLng(lat, lon), KmOpts);
        var totalBounds = new google.maps.LatLngBounds();
        totalBounds.union(KmOverlay.getBounds());
        map.fitBounds(totalBounds); 
    }
}

function loadMap()
{
   if(lat != undefined && lon != undefined)
	   {
	      show_map(lat, lon, map_zoom, map_controls, map_marker);
	   }
      $('#map_view').click(function(){
    	  removeActive();
    	  $(this).addClass('active');
    	  toggle_map_view('M');
      });
      $('#sat_view').click(function(){
    	  removeActive();
    	  $(this).addClass('active');
    	  toggle_map_view('S');
      });
      $('#hyb_view').click(function(){
    	  removeActive();
    	  $(this).addClass('active');
    	  toggle_map_view('H');
      });
      $('#ter_view').click(function(){
    	  removeActive();
    	  $(this).addClass('active');
    	  toggle_map_view('T');
      });
}

function removeActive()
{
	$('#map_view').removeClass('active');
	$('#sat_view').removeClass('active');
	$('#hyb_view').removeClass('active');
	$('#ter_view').removeClass('active');
}

function toggle_map_view(mode)
{
	if ('S'==mode)
	{
		map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
	}
	else
		if ('H'==mode)
		{
			map.setMapTypeId(google.maps.MapTypeId.HYBRID);
		}
		else
			if ('T'==mode)
			{
				map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
			}
			else
				map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
}


