var map;
var geocoder;
var markerOptions;
var navButtons = new Array();
var doc = document;
var worldMap 	= { id : "worldButton", name : "All Flights", lat : 40, lng : -20, zoomLvl : 2 }
var europeMap 	= { id : "europeButton", name : "Europe Flights", lat : 42, lng : 10, zoomLvl : 4 }
var americaMap 	= { id : "usaButton", name : "North America Flights", lat : 37, lng : -90, zoomLvl : 3 }
var indiaMap 	= { id : "indiaButton", name : "Indian Ocean and The Red Sea Flights", lat : 14, lng : 80, zoomLvl : 4 }
var mapZones 	= new Array(worldMap, europeMap, americaMap, indiaMap);

var buttonStyle = { textDecoration : "none",
					color : "#fff",
					backgroundColor : "#70c1ef",
					font : "bold 0.8em Arial",
					border : "2px solid #008fde",
					padding : "2px",
					marginBottom : "1px",
					textAlign : "center",
					width : "100px",
					cursor : "pointer" }
					
function menuDisplay(menu) {

	if (menu == 'usaAndCaribbean'){
		map.setCenter(new GLatLng(37, -90), 3);
	} else if (menu == 'europeFlights'){
		map.setCenter(new GLatLng(42, 10), 4);
	} else if (menu == 'indianOceanRedSea'){
		map.setCenter(new GLatLng(14, 80), 4);
	}
	return false;
}					
					
					
jQuery(document).ready(function($){					
	
	if (GBrowserIsCompatible()) {

		var mapHolder = document.getElementById("displayMap");
	    map = new GMap2(mapHolder);
		map.addControl(new GLargeMapControl3D());
		map.setCenter(new GLatLng(42, 10), 4);

		var ftcIcon = new GIcon(G_DEFAULT_ICON);
		ftcIcon.image = "./images/pin-clear.png";
		ftcIcon.shadow = "./images/pin-shadow.png";
		ftcIcon.shadowSize = new GSize(20, 26);
		ftcIcon.iconSize = new GSize(18, 22);
	    ftcIcon.iconAnchor = new GPoint(4, 20);
	    ftcIcon.infoWindowAnchor = new GPoint(18, 20);
		markerOptions = { icon:ftcIcon };

		function mapButtons() {}
		mapButtons.prototype = new GControl();
		mapButtons.prototype.initialize = function(map) {			
			var container = document.createElement("div");
			$(mapZones).each(function() {
				var area = $(this);
				var button = $(document.createElement("div")).click(function(e){
					map.setCenter(new GLatLng($(area).attr("lat"), $(area).attr("lng")), $(area).attr("zoomLvl"));
				});	
				$(button).css(buttonStyle);
				$(button).text($(this).attr("name"));
				$(button).appendTo(container);
			});	
		  	map.getContainer().appendChild(container);
			return container;
		}
		mapButtons.prototype.getDefaultPosition = function() {
			return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
		}
		map.addControl(new mapButtons());

		$.ajax({
			type: "GET",
			url: "./markers1.xml",
			dataType: "xml",
			success: function(xml) {
				$(xml).find('marker').each(function(){
					var point = new GLatLng($(this).attr('lat'),$(this).attr('lng'));
					var marker = new GMarker(point, markerOptions);	
					var name = $(this).attr('name');
					GEvent.addListener(marker, "click", function() {
						window.location = 'http://book.flythomascook.com/cheap-flights/to-' + name + '/';	
					});
					map.addOverlay(marker);		
				});
			}
		});		

	}	
});				