/* Map Code */

function initialize_map() {
	// The Map
	var steppingStonesMap = new google.maps.Map(document.getElementById("map_canvas"), {
		zoom: 5,
		center: new google.maps.LatLng(31.5,-88),
		scrollwheel: false,
		zoomControl: false,
		scaleControl: false,
		scrollwheel: false,
		disableDoubleClickZoom: true,
		navigationControl: false,
		mapTypeControl: false,
		draggable: false,
		streetViewControl: false,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});
	
	// InfoBoxes
	var newOrleansInfo0 = new InfoBox({					// Meta-infobox that links to the other New Orleans infoboxes
		content: $('div#newOrleansInfo0')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-300, -50),
		alignBottom: true
	});
	
	var corpusChristiInfo0 = new InfoBox({				// Meta-infobox that links to the other Corpus Christi infoboxes
		content: $('div#corpusChristiInfo0')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-150, -50),
		alignBottom: true
	});
	
	var sarasotaInfo1 = new InfoBox({					// #1 - Sarasota
		content: $('div#sarasotaInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-450, -50),
		alignBottom: true
	});
	
	var mobileInfo1 = new InfoBox({						// #2 - Mobile
		content: $('div#mobileInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-300, -50),
		alignBottom: true
	});
	
	var galvestonInfo1 = new InfoBox({					// #3 - Galveston
		content: $('div#galvestonInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-150, -50),
		alignBottom: true
	});
	
	var newOrleansInfo1 = new InfoBox({					// #4 - New Orleans 1
		content: $('div#newOrleansInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-300, -50),
		alignBottom: true
	});
	
	var austinInfo1 = new InfoBox({						// #5 - Austin
		content: $('div#austinInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-150, -50),
		alignBottom: true
	});
	
	var veracruzInfo1 = new InfoBox({					// #6 - Veracruz
		content: $('div#veracruzInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-150, -50),
		alignBottom: true
	});
	
	var meridaInfo1 = new InfoBox({						// #7 - Merida
		content: $('div#meridaInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-300, -50),
		alignBottom: true
	});
	
	var newOrleansInfo2 = new InfoBox({					// #9 - New Orleans 2
		content: $('div#newOrleansInfo2')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-300, -50),
		alignBottom: true
	});
	
	var corpusChristiInfo1 = new InfoBox({				// #10 - Corpus Christi 1
		content: $('div#corpusChristiInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-150, -50),
		alignBottom: true
	});
	
	var newOrleansInfo3 = new InfoBox({					// #11 - New Orleans 3
		content: $('div#newOrleansInfo3')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-300, -50),
		alignBottom: true
	});
	
	var stPetersburgInfo1 = new InfoBox({				// #12 - St. Petersburg
		content: $('div#stPetersburgInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-450, -50),
		alignBottom: true
	});

	var corpusChristiInfo2 = new InfoBox({				// #13 - Corpus Christi 2
		content: $('div#corpusChristiInfo2')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-150, -50),
		alignBottom: true
	});
	
	var washingtonDCInfo1 = new InfoBox({				// #14 - Washington, D.C.
		content: $('div#washingtonDCInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-680, -50),
		alignBottom: false
	});
	
	var batonRougeInfo1 = new InfoBox({
		content: $('div#batonRougeInfo1')[0],
		disableAutoPan: true,
		pixelOffset: new google.maps.Size(-300, -50),
		alignBottom: true
	});
	
	var infoBoxes = [newOrleansInfo0, corpusChristiInfo0, sarasotaInfo1, mobileInfo1, galvestonInfo1, austinInfo1, veracruzInfo1, meridaInfo1, stPetersburgInfo1, washingtonDCInfo1, batonRougeInfo1, /* The rest are accessed by meta-infobox, not directly on marker click. */ newOrleansInfo1, newOrleansInfo2, newOrleansInfo3, corpusChristiInfo1, corpusChristiInfo2];
		
	// Markers
	var newOrleans = new google.maps.Marker({ position: new google.maps.LatLng(29.950175, -90.065918), map: steppingStonesMap });
	var corpusChristi = new google.maps.Marker({ position: new google.maps.LatLng(27.716457, -97.328809), map: steppingStonesMap });
	var sarasota = new google.maps.Marker({ position: new google.maps.LatLng(27.332835, -82.577426), map: steppingStonesMap });
	var mobile = new google.maps.Marker({ position: new google.maps.LatLng(30.68, -88.25), map: steppingStonesMap });
	var galveston = new google.maps.Marker({ position: new google.maps.LatLng(29.27, -94.87), map: steppingStonesMap });
	var austin = new google.maps.Marker({ position: new google.maps.LatLng(30.30, -97.70), map: steppingStonesMap });
	var veracruz = new google.maps.Marker({ position: new google.maps.LatLng(19.15, -96.1833), map: steppingStonesMap });
	var merida = new google.maps.Marker({ position: new google.maps.LatLng(20.969995, -89.619985), map: steppingStonesMap });
	var stPetersburg = new google.maps.Marker({ position: new google.maps.LatLng(27.773059, -82.640002), map: steppingStonesMap });
	var washingtonDC = new google.maps.Marker({ position: new google.maps.LatLng(38.85, -77.04), map: steppingStonesMap });
	var batonRouge = new google.maps.Marker({ position: new google.maps.LatLng(30.5465, -91.2092), map: steppingStonesMap });
	
	var markers = [newOrleans, corpusChristi, sarasota, mobile, galveston, austin, veracruz, merida, stPetersburg, washingtonDC, batonRouge];
	
	// Assign infoBoxes to Markers
	for(var i in markers){
		google.maps.event.addListener(markers[i], 'click', function() {
			for(var j in infoBoxes){ infoBoxes[j].close(); }
			var index = $(markers).index(this);
			infoBoxes[index].open(steppingStonesMap, this);
			mapLinkHandler();
		});
	}
	
	function mapLinkHandler(){
		$('a.maplink').click(function(e){
			e.preventDefault();
			mapLink(this);
		});
	}
	
	function mapLink(clicked){
		for(var i in infoBoxes){ infoBoxes[i].close(); }
		var target = $(clicked).attr('href')
		var infoBox = eval(target.substring(1));
		var endPoint = target.length-5;
		var parentMarker = eval(target.substring(1, endPoint));
		infoBox.open(steppingStonesMap, parentMarker);
	}
	
	mapLinkHandler();
}
