/**************************************************
 * Custom map-type control:
 * more or less from Google's own documentation
 **************************************************/
maptypecontrol_style = (self.maptypecontrol_style) ? maptypecontrol_style : 'menu';
filter_map_types = (self.filter_map_types!=null) ? filter_map_types : true;

function MapTypeControl() {}
	MapTypeControl.prototype = new GControl();
	MapTypeControl.prototype.initialize = function(map) {
		//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:'USGS - Topo',type:'USGS_TOPO_TILES',title:'USGS topographic map',bounds:[-169,18,-66,72],excluded:[] }
			,{ label:'USGS - Aerial',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 (maptypecontrol_style == 'menu') {
			var map_selector = document.createElement("select");
			map_selector.id = "map_selector";
//			map_selector.style.font = "12px Verdana bold";
			map_selector.style.fontFamily = "Verdana";
			map_selector.style.fontSize = "12px";
			map_selector.style.fontWeight = "normal";
			for (j=0; j<maps.length; j++) {
				//if (!filter_map_types || 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 = maps[j]['val'];
					opt.appendChild(document.createTextNode(maps[j]['label']));
					map_selector.appendChild(opt);
					if (maps[j]['selected']) { map_selector.selectedIndex = map_selector.length - 1; }
				//}
			}
			GEvent.addDomListener(map_selector, "change", function(){changeMap(this.value);} );
			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 (!filter_map_types || 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 = 'maptypelink';
					if (self.maptypecontrol && map.getCurrentMapType() == eval(map_types[j]['type'])) {
						maplink.className = 'maptypelink 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.maptypecontrol) {
							map.removeControl(maptypecontrol);
							map.addControl(maptypecontrol);
						}
					} );
				}
			}
			map.getContainer().appendChild(map_type_container);
			return map_type_container;
		}*/
	}
	MapTypeControl.prototype.getDefaultPosition = function() {
		return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(100,15));
}

var api_version = 2;
function GPSV_MapTypeControl() {}
//if (api_version >= 2) { GPSV_MapTypeControl.prototype = MapTypeControl.prototype; }
GPSV_MapTypeControl.prototype = MapTypeControl.prototype;
//
//////////////////////
/**************************************************
 * End Custom map-type control:
 **************************************************/

function changeMap(mapDate) {
	location.href = 'index.php?date=' + mapDate;
}
