$(document).ready(function() {
		// build the left menu
		var $sections = jQuery('.map_fac'),
			$allMenus = jQuery('ul', $sections);

		// show all the sections we hid with that script in the html
		$sections.show();
		// hide all menus, then open the facilities menu as default
		$allMenus.hide().filter(':last').slideDown('slow');
	
		// build the map
		if (GBrowserIsCompatible()) {
			// set up the basic map
			var map = new GMap2(document.getElementById('map_canvas'));
			map.setCenter(new GLatLng(30.29,-97.76), 11);
			map.setUIToDefault();

			// Because the map jumps off to the right when the scroll wheel is used in IE < 8,
			// disable the scroll wheel zoom for any IE older than v8.
			// FYI: IE8 was the first IE to have case sensitivity for ID's
			// so our filter will allow IE7 and under to pass thru to the disable method.
			if (document.getElementById('MAP_CANVAS')) {
				map.disableScrollWheelZoom();				
			}
			
			// start building the marker icon
			var mapIcon = new GIcon();
			mapIcon.iconSize = new GSize(32, 32);
			mapIcon.shadow = '';
			// mapIcon.shadow = 'icon10s.png';
			// mapIcon.shadowSize = new GSize(59, 32);
			mapIcon.iconAnchor = new GPoint(11, 31);
			mapIcon.infoWindowAnchor = new GPoint(11, 11);

			// drop markers on the map and connect side menu to map
			$sections.each(function(){
				// go back to the menu to add the open accordion stuff
				var $sectionTitle = jQuery('h3', this),
					$thisMenu = jQuery('ul', this);

				$sectionTitle.click(function(){
					$allMenus.slideUp('fast');
					$thisMenu.slideDown('normal');
				});

				// set up the map marker icons for each section
				switch ( $sectionTitle.text() ) {
					case 'High Schools':
						mapIcon.image = 'casetta_red.png';
						break;
					case 'Middle Schools':
						mapIcon.image = 'casetta_yellow.png';
						break;
					case 'Elementary Schools':
						mapIcon.image = 'casetta_green.png';
						break;
					default:
						mapIcon.image = 'casetta_blu.png';
						break;
				}
				// add the icon to the marker options
				var markerOptions = { icon: mapIcon };
			
				// add the individual schools to the map
				jQuery('.vcard', this).each(function() {
					// set up marker information
					var point = new GLatLng(parseFloat(jQuery('.latitude', this).text()), parseFloat(jQuery('.longitude', this).text()));
					var marker = new GMarker(point, markerOptions);
					var bubbleText = '<div style="height:130px;">'+jQuery(this).html()+'</div>';

					// when the map marker is clicked, pop up a text bubble
					GEvent.addListener(marker, 'click', function() {
						marker.openInfoWindowHtml(bubbleText);
						
					});

					// when the side menu is clicked, do the same as above
					jQuery('.url', this).click(function() {
						marker.openInfoWindowHtml(bubbleText);				
						return false;
					});

					// attach the markers to the map
					map.addOverlay(marker);				
				});
			});
		}
});



$(window).unload(GUnload);

