/**************************************************
 * Custom map-type control:
 * more or less from Google's own documentation
 **************************************************/
function GV_MapTypeControl(selectorName) {
   this.selectorName = selectorName; 
}

if (gv_api_version > 1) {
	GV_MapTypeControl.prototype = new GControl();
	GV_MapTypeControl.prototype.initialize = function(map) {
		if(showMapButtons) {
               GV_Add_Custom_Layers(map);
  }
		var map_types = [
			{ label:'Google map',type:'G_NORMAL_MAP',title:'Google street map',bounds:[-180,-90,180,90],excluded:[] }
			,{ label:'Google satellite',type:'G_SATELLITE_MAP',title:'Google satellite map',bounds:[-180,-90,180,90],excluded:[] }
			,{ label:'Google hybrid',type:'G_HYBRID_MAP',title:'Google "hybrid" map',bounds:[-180,-90,180,90],excluded:[] }
			,{ label:'Google terrain',type:'G_PHYSICAL_MAP',title:'Google terrain map',bounds:[-180,-90,180,90],excluded:[] }
			,{ label:'Google Earth (3D)',type:'G_SATELLITE_3D_MAP',title:'Google earth map',bounds:[-180,-90,180,90],excluded:[] }
			,{ label:'USGS topo (US only)',type:'USGS_TOPO_TILES',title:'USGS topographic map',bounds:[-169,18,-66,72],excluded:[] }
			,{ label:'USGS satellite (US only)',type:'USGS_AERIAL_TILES',title:'USGS aerial photos (black/white)',bounds:[-152,17,-65,65],excluded:[] }
		//	,{ label:'Canada topo',type:'NRCAN_TOPO_TILES',title:'NRCan/Toporama maps with contour lines',bounds:[-141,41.7,-52,85],excluded:[-141,41.7,-86,48] }
		//	,{ label:'Blue Marble',type:'BLUEMARBLE_TILES',title:'NASA "Visible Earth" image',bounds:[-180,-90,180,90],excluded:[] }
		//	,{ label:'Daily "Terra"',type:'DAILY_TERRA_TILES',title:'Daily imagery from "Terra" satellite',bounds:[-180,-90,180,90],excluded:[] }
		//	,{ label:'Daily "Aqua"',type:'DAILY_AQUA_TILES',title:'Daily imagery from "Aqua" satellite',bounds:[-180,-90,180,90],excluded:[] }
		];
	//	var center_lat = map.getCenter().lat();
//		var center_lng = map.getCenter().lng();

		if (gv_maptypecontrol_style == 'menu') {
			var map_selector = document.createElement("select");
			if(this.selectorName) {
                  map_selector.id = this.selectorName;
               } else {
			   map_selector.id = 'map_selector';
			}
			map_selector.style.font = '10px Verdana';
			map_selector.style.backgroundColor = '#FFFFFF';

			for (j=0; j<map_types.length; j++) {
			/*	if (!gv_filter_map_types || gv_filter_map_types < 0 ||
                       ( (center_lng >= map_types[j]['bounds'][0] && center_lat >= map_types[j]['bounds'][1] && center_lng <= map_types[j]['bounds'][2] && 
                          center_lat <= map_types[j]['bounds'][3]) && !(center_lng >= map_types[j]['excluded'][0] && center_lat >= map_types[j]['excluded'][1] && 
                          center_lng <= map_types[j]['excluded'][2] && center_lat <= map_types[j]['excluded'][3]) 
                        ) ) {
               */
					var opt = document.createElement("option");
					opt.value = map_types[j]['type'];
					opt.appendChild(document.createTextNode(map_types[j]['label']));
					map_selector.appendChild(opt);
					if (map.getCurrentMapType() == eval(opt.value)) { map_selector.selectedIndex = map_selector.length - 1; }
			//	}
			}
			GEvent.addDomListener(map_selector, "change", function(){map.setMapType(eval(this.value));} );
		
              // typeTitle = document.createElement('div');
             //  typeTitle.innerHTML = "Map Type";



              // map.getContainer().appendChild(typeTitle)
          	map.getContainer().appendChild(map_selector);           
			return map_selector;
		} else {
			var map_type_container = document.createElement("div");
			for (j=0; j<map_types.length; j++) {
				if (!gv_filter_map_types || gv_filter_map_types < 0 || ( (center_lng >= map_types[j]['bounds'][0] && center_lat >= map_types[j]['bounds'][1] && center_lng <= map_types[j]['bounds'][2] && center_lat <= map_types[j]['bounds'][3]) && !(center_lng >= map_types[j]['excluded'][0] && center_lat >= map_types[j]['excluded'][1] && center_lng <= map_types[j]['excluded'][2] && center_lat <= map_types[j]['excluded'][3]) ) ) {
					var maplink = document.createElement("div");
					maplink.className = 'gv_maptypelink';
					if (self.gv_maptypecontrol && map.getCurrentMapType() == eval(map_types[j]['type'])) {
						maplink.className = 'gv_maptypelink gv_maptypelink_selected';
					}
					maplink.title = map_types[j]['title'];
					maplink.type = map_types[j]['type'];
					map_type_container.appendChild(maplink);
					maplink.appendChild(document.createTextNode(map_types[j]['label']));
					GEvent.addDomListener(maplink, "click", function(){
						map.setMapType(eval(this.type));
						if (self.gv_maptypecontrol) {
							map.removeControl(gv_maptypecontrol);
							map.addControl(gv_maptypecontrol);
						}
					} );
				}
			}
			map.getContainer().appendChild(map_type_container);
			return map_type_container;
		}
	}
	GV_MapTypeControl.prototype.getDefaultPosition = function() {
		return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7,7));
	}
}




