// Initialize the arrays.
/* Time: ID, time. */
var time = [
	[1, '12:00&ndash;1:00 p.m.'],
	[2, '2:00&ndash;3:00 p.m.'],
	[3, '3:00&ndash;4:00 p.m.'],
	[4, '4:00&ndash;5:00 p.m.'],
	[5, '5:00&ndash;6:00 p.m.'],
	[6, '6:00&ndash;7:00 p.m.'],
	[7, '7:00&ndash;8:00 p.m.'],
	[8, '8:00&ndash;9:00 p.m.'],
];
/* Locations: ID, location, latitude, longitude. */
var locs = [
	[1, 'Naito and Salmon', '45.51576', '-122.673576'],
	[2, '3rd and Ash', '45.522571', '-122.673383'],
	[3, '3rd and Morrison', '45.518271', '-122.675529'],
	[4, '3rd and Yamhill', '45.517571', '-122.675912'],
	[5, '4th and Morrison', '45.518527', '-122.676558'],
	[6, '4th and Yamhill', '45.517816', '-122.676923'],
	[7, '5th and Morrison', '45.5188', '-122.67759'],
	[8, 'Broadway and Morrison', '45.519351', '-122.679621'],
	[9, 'Park and Yamhill', '45.518963', '-122.680957'],
	[10, '9th and Morrison', '45.51979', '-122.681129'],
	[11, '10th and Morrison', '45.520025', '-122.682139'],
	[12, '10th and Yamhill', '45.519334', '-122.682441'],
	[13, '10th and Stark', '45.522024', '-122.681059'],
	[14, '6th and Yamhill', '45.518422', '-122.678962'],
	[15, '2nd and Morrison', '45.518016', '-122.674541'],
	[16, '5th and Yamhill', '45.5181', '-122.67786']
];
/* Acts: ID, name. */
var acts = [
	[1, "All The Apparatus"],
	[2, "Allegro Elite Duo"],
	[3, "Blood Beach"],
	[4, "Boy and Bean"],
	[5, "Craig Irby"],
	[6, "DaiN"],
	[7, "Gone Fishin'"],
	[8, "Half Way There"],
	[9, "Halley the Harper"],
	[10, "Jason's Caravan"],
	[11, "Jonah Luke"],
	[12, "Julia Lucille and Barra Brown"],
	[13, "Kory Quinn and the Comrades"],
	[14, "Lindsay Goldsmith"],
	[15, "Lord's Own Choir"],
	[16, "Mark Hamre"],
	[17, "Mark Perry aka Slim Bacon"],
	[18, "Nancy Memovich"],
	[19, "Oxbow Drive"],
	[20, "Sage Yannam"],
	[21, "Sam Tongue"],
	[22, "Target for Tomorrow"],
	[23, "The Goodwill River"],
	[24, "The Martyrs"],
	[25, "The Miss Me's"],
	[26, "The Non"],
	[27, "The Symphonic Rebellion"],
	[28, "Turtle da Bass"],
	[29, "Wayward Vessel"],
	[30, "Will Roth"],
	[31, "Wizard Boots"],
	[32, "Your Rival"],
	[33, "The Basement Project"],
	[34, "Annah Sidigu"],
	[35, "Negara"],
	[36, "PIECOST"]
];
/* Show: location ID, array of time IDs, array of band IDs. */
var show = [
	[1, [5], [16]],
	[2, [2], [22]],
	[3, [3], [8]],
	[4, [4, 5], [10, 27]],
	[5, [4, 5, 8], [6, 26, 36]],
	[6, [2, 3, 6, 7], [12, 20, 2, 24]],
	[7, [2, 3, 4, 6], [19, 22, 5, 1]],
	[8, [1, 2, 3, 4, 5, 6, 7, 8], [28, 28, 5, 13, 22, 29, 15, 4]],
	[9, [1, 2, 3, 5, 6, 7, 8], [11, 20, 9, 25, 31, 4, 3]],
	[10, [4], [23]],
	[11, [2, 3, 5, 6, 7], [7, 30, 17, 34, 21]],
	[12, [4], [32]],
	[13, [2, 3, 4, 6], [11, 14, 18, 10]],
	[14, [7, 8], [2, 1]],
	[15, [6], [33]],
	[16, [5], [35]]
];


function initializeMap() {
	var myLatLang = new google.maps.LatLng(45.519, -122.679);
	var myOptions = {
		zoom: 15,
		center: myLatLang,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map_div"), myOptions);

	// Run through the show arrays.
	for (var n = 0; n < show.length; n++) {
		// Grab the array.
		var nf = show[n];
		// The first element is the location ID.
		// The second element is the array of time IDs.
		// The third element is the array of band IDs.
		var l = nf[0]; var t = nf[1]; var b = nf[2];
		// Grab the location array.
		var ul = locs[(l - 1)];
		// Initialize the text to use in the info window.
		var inwin = '<strong>'+ul[1]+'</strong><br /><br />';
		// Run through the row's time and band IDs.
		for (m = 0; m < t.length; m++) { // t and b should be equal.
			// Get the time and band IDs.
			var gt = t[m]; var gb = b[m];
			// Get the time and band values.
			var ut = time[(gt - 1)]; var ub = acts[(gb - 1)];
			//alert(ut[1] + ' and ' + ub[1]);
			inwin += ut[1]+'<br />'+ub[1];
			if (m < (t.length - 1)) {inwin += '<br /><br />';}
		}
		// Make the info window.
		var nw = mkwin(inwin);
		// Make the marker.
		var nm = mkmrk(map, ul[2], ul[3], ul[1]);
		// Set it.
		mklst(map, nm, nw);
	}
}


function mkwin(cont) {
	var inwin = new google.maps.InfoWindow(
		{ content: cont,
		  size: new google.maps.Size(250,55)
		});
	return inwin;
}


function mkmrk(map, lat, lng, ttl) {
	var nwmrk = new google.maps.Marker({
		position: new google.maps.LatLng(lat, lng), 
		map: map, 
		title: ttl
	});
	return nwmrk;
}


function mklst(map, mrk, win) {
	google.maps.event.addListener(mrk, 'click', function() {win.open(map,mrk);});
	//google.maps.event.addListener(mrk, 'mouseover', function() {win.open(map,mrk);});
	//google.maps.event.addListener(mrk, 'mouseout', function() {win.close(map,mrk);});
	return true;
}
