	var map;
	var arrMarkers = [];
	var arrDirections = [];
	var arrPolylines = [];
	var currentPolylineId = 0;
	var lineIndex = 0;
	
	var todaysDate = new Date();
 



	function setMapCenter(address) {
		var geocoder = new GClientGeocoder();
		
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					alert(address + " not found");
				} else {
					map.setCenter(point, 7);
				}
			}
		);
	}
	
	
	function placeMarkerByAddress(address, markerSrc, markerWidth, markerHeight) {
		var geocoder = new GClientGeocoder();
		
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					alert(address + " not found");
				} else {
					var stadiumIcon = new GIcon(G_DEFAULT_ICON);
					stadiumIcon.image = markerSrc;
					stadiumIcon.iconSize = new GSize(markerWidth, markerHeight);
	
					markerOptions = { icon:stadiumIcon };
					
					var marker = new GMarker(point, markerOptions);
					map.addOverlay(marker);
					//marker.openInfoWindowHtml(address);
				}
			}
		);
	}
	
	
	function formatDate(date1) {
		return date1.getFullYear() + '-' +
		(date1.getMonth() < 9 ? '0' : '') + (date1.getMonth()+1) + '-' +
		(date1.getDate() < 10 ? '0' : '') + date1.getDate();
	}
	
	
	/*
		Draw direction polylines
		without markers and in 
		different colors
		
		Handler for: GDirections.load(), GDirections.loadFromWaypoints()
	*/
	function onGDirectionsLoad() {
		lineIndex++;
	
		if (arrDirections[lineIndex].getPolyline()) {
			arrPolylines[lineIndex] = arrDirections[lineIndex].getPolyline();
			
			if (lineIndex == currentPolylineId) {
				arrPolylines[currentPolylineId].setStrokeStyle({color:'#00f', weight:5, opacity:1});
			}
			else
				arrPolylines[lineIndex].setStrokeStyle({color:'#E45E9C', weight:3, opacity:1});
	
			map.addOverlay(arrPolylines[lineIndex]);

			if (lineIndex < arrTrips.length)
				setDirection(lineIndex, arrTrips, internKevin);
		}
	}
	
	
	function setDirection(i, arrTrips, internKevin) {
	
		// Create Instance of GDirection WITHOUT optional
		// map parameter.  Not passing the map parameter keeps
		// the map from drawing the endpoint markers.
		var keyId = Math.floor(i) + 1;
		
		arrDirections[keyId] = new GDirections();
		
		GEvent.addListener(arrDirections[keyId], "load", onGDirectionsLoad); 
		
		var arrLatLngs = new Array();
	
		if (arrTrips[i].travel_date == formatDate(todaysDate)) {
		// Trips scheduled for today.
			currentPolylineId = keyId
		
			var arrTripStops = arrTrips[i].trip_stops;
			for (var j = 0; j < arrTripStops.length; j++) {
				// If it is a two stop trip direct the
				// path through Kevin's current position.
				if (arrTripStops.length == 2 && j == 1 && internKevin.lat != 0 && internKevin.lng != 0)
					arrLatLngs.push(internKevin.lat+','+internKevin.lng);
				
				arrLatLngs.push(arrTripStops[j].lat+','+arrTripStops[j].lng);
			}
		}
	
		else {
		// Trips scheduled for days other than today.
	
			var arrTripStops = arrTrips[i].trip_stops;
			for (var j = 0; j < arrTripStops.length; j++) {
				arrLatLngs.push(arrTripStops[j].lat+','+arrTripStops[j].lng);
			}
		}
	
		arrDirections[keyId].loadFromWaypoints(arrLatLngs, {getSteps:false, getPolyline:true, preserveViewport:true});
	}
	
	

	function initialize() {

		var mapType = 

		// Create Map
		map = new google.maps.Map2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());


		// Set center location of the map.
		setMapCenter('Pennsylvania'); 

		// Place Stadium Markers
		for (var i = 0; i < arrStadiums.length; i++) {
			var logoName = arrStadiums[i].team_name.toLowerCase().replace(/ /g, '_').replace(/\//g, '_');
			
			if (arrStadiums[i].derby_date < formatDate(todaysDate)) {
				var markerSrc = 'images/intern_kevin/logos/past/'+logoName+'.png';
			}
			else {
				var markerSrc = 'images/intern_kevin/logos/'+logoName+'.png';
			}
							
			var markerWidth = 45;
			var markerHeight = 45;

			var stadiumIcon = new GIcon(G_DEFAULT_ICON);
			stadiumIcon.image = markerSrc;
			stadiumIcon.iconSize = new GSize(markerWidth, markerHeight);
			stadiumIcon.iconAnchor = new GPoint(18, 18);  
			stadiumIcon.infoWindowAnchor = new GPoint(25, 14);
			stadiumIcon.imageMap = [0,0, 0,100, 100,100, 100,0];

	
			var markerOptions = { icon:stadiumIcon, title:'title', clickable:true };
			var point = new GLatLng(arrStadiums[i].lat, arrStadiums[i].lng);
	
			var infoWindowText = '<div class="stadiumDetails"<h1>'+arrStadiums[i].stadium_name+'</h1><p>'+arrStadiums[i].address+' '+arrStadiums[i].address2+'<span>'+arrStadiums[i].city+' '+arrStadiums[i].state+' '+arrStadiums[i].zip+'</span></p><p><strong>Derby Date:</strong> '+arrStadiums[i].derby_date_readable+'</p></div>';
			var marker = createMarker(point, markerOptions, infoWindowText, arrStadiums[i].derby_date, todaysDate)

			arrMarkers[i] = marker
			
			map.addOverlay(arrMarkers[i]);	


			// Show current derby.
			//if (derbyDate == formatDate(todaysDate)) {
				//arrMarkers[i].showDetailWin();
			//}
		}


		function createMarker(point, markerOptions, infoWindowText, derbyDate, todaysDate) {
/*
			var marker = new GMarker(point, markerOptions);
//			if (derbyDate == formatDate(todaysDate)) {
			if (derbyDate == '2009-07-20 00:00:00') {
				marker.openInfoWindowHtml(infoWindowText);
			}
			else {
				GEvent.addListener(
					marker,
					'click',
					function() { marker.openInfoWindowHtml(infoWindowText); }
				)
			}
*/		
			
			var marker = new PdMarker(point, markerOptions);
			var html = infoWindowText;
			marker.setDetailWinHTML(html);
	
			return marker;
		}


		setDirection(0, arrTrips, internKevin);


		// Place Intern Kevin Icon
		var internKevinLoc = new GLatLng(internKevin.lat, internKevin.lng);
		var internIcon = new GIcon(G_DEFAULT_ICON);
		internIcon.image = 'images/intern_kevin/logos/intern_kevin_marker.png';
		internIcon.iconSize = new GSize(60, 60);
		internIcon.imageMap = [0,0, 0,100, 100,100, 100,0];
		markerOptions = { icon:internIcon };
		//var kevinMarker = new GMarker(internKevinLoc, markerOptions);
		
		var kevinMarker = new PdMarker(internKevinLoc, markerOptions);
		var html = '<div class="stadiumDetails"><h1>Intern Kevin</h1><p><strong style="display:block;">Current Location: </strong>'+internKevin.lat+', '+internKevin.lng+'</p></div>';
		kevinMarker.setDetailWinHTML(html);
		
		map.addOverlay(kevinMarker);

	}

	google.setOnLoadCallback(initialize);