// main_map.js

var baselat  =  35.9127;
var baselong = -79.0533;

var map;
var wkshop_icon;
var workshop_locations = new Array();

function load(setname) {

	if (!GBrowserIsCompatible()) {
		return;
	}

	map = new GMap2(document.getElementById("map"));

	if (setname == 'travel') {
		map.setCenter(new GLatLng(35.843421, -78.8708496), 10);
	} else if (setname == 'restaurants') {
		map.setCenter(new GLatLng(35.91008, -79.05761), 15);
		map.setMapType(G_HYBRID_TYPE);
	} else {
		map.setCenter(new GLatLng(baselat, baselong), 16);
		map.setMapType(G_HYBRID_TYPE);
	}
	map.addControl(new GLargeMapControl());
	map.addControl(new GScaleControl());
	map.addControl(new GMapTypeControl());

	// below line adds lower-right inset map way zoomed out
	// map.addControl(new GOverviewMapControl());

	wkshop_icon = new GIcon();
	wkshop_icon.shadow = "http://chapelhillchambermusic.com/working/images/map_images/shadow50.png";
	wkshop_icon.iconSize = new GSize(20, 34);
	wkshop_icon.shadowSize = new GSize(37, 34);
	wkshop_icon.iconAnchor = new GPoint(9, 34);
	wkshop_icon.infoWindowAnchor = new GPoint(9, 2);
	wkshop_icon.infoShadowAnchor = new GPoint(18, 25);


	if (setname == 'travel') {
		load_travel_locations();
	}
	else if (setname == 'restaurants') {
		load_restaurants();
	} else {
		load_workshop_locations();
	}

	for (var i=0; i < workshop_locations.length; i++) {
		setup_marker (workshop_locations[i]);
	}
}


// ----------------------------------------------------------------
function load_travel_locations () {

	workshop_locations[0] = new Object();
	workshop_locations[0].latitude = 35.9126;
	workshop_locations[0].longitude = -79.0532;
	workshop_locations[0].desc = "Hill Hall, home of the UNC Music Department";

	workshop_locations[1] = new Object();
	workshop_locations[1].latitude = 35.9111;
	workshop_locations[1].longitude = -79.0566;
	workshop_locations[1].desc = "Granville Towers";

	workshop_locations[2] = new Object();
	workshop_locations[2].latitude = 35.87375;
	workshop_locations[2].longitude = -78.79240;
	workshop_locations[2].desc = "Raleigh-Durham International Airport";

	for (var i=0; i < workshop_locations.length; i++) {
		setup_marker (workshop_locations[i]);
	}

}

// ----------------------------------------------------------------
function load_workshop_locations () {
	workshop_locations[0] = new Object();
	workshop_locations[0].latitude = 35.9126;
	workshop_locations[0].longitude = -79.0532;
	workshop_locations[0].desc = "Hill Hall, home of the UNC Music Department";

	workshop_locations[1] = new Object();
	workshop_locations[1].latitude = 35.9125;
	workshop_locations[1].longitude = -79.0524;
	workshop_locations[1].desc = "Person Hall, one of the workshop locations; The building was once a church.";

	workshop_locations[2] = new Object();
	workshop_locations[2].latitude = 35.9134;
	workshop_locations[2].longitude = -79.05370;
	workshop_locations[2].desc = "University United Methodist Church";

	workshop_locations[3] = new Object();
	workshop_locations[3].latitude = 35.9125;
	workshop_locations[3].longitude = -79.0540;
	workshop_locations[3].desc = "Hanes Art Building";

	workshop_locations[4] = new Object();
	workshop_locations[4].latitude = 35.91414;
	workshop_locations[4].longitude = -79.05166;
	workshop_locations[4].desc = "Graham Memorial Hall";

	workshop_locations[5] = new Object();
	workshop_locations[5].latitude = 35.9111;
	workshop_locations[5].longitude = -79.0566;
	workshop_locations[5].desc = "Granville Towers";


	for (var i=0; i < workshop_locations.length; i++) {
		setup_marker (workshop_locations[i], i);
	}

}


// ----------------------------------------------------------------

function setup_marker (marker_obj, index) {

	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var filename = "http://chapelhillchambermusic.com/working/images/map_images/marker" + letter + ".png";
	var this_icon = new GIcon(wkshop_icon);
	this_icon.image = filename;


	var marker = new GMarker(new GLatLng(marker_obj.latitude, marker_obj.longitude), {icon:this_icon, title:marker_obj.desc});

	map.addOverlay(marker);

	// can use "click" or "mouseover"
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(marker_obj.desc);	
	});

} // end setup_marker


// ----------------------------------------------------------------

function load_restaurants () {

	workshop_locations[0] = new Object();
	workshop_locations[0].latitude = 35.9126;
	workshop_locations[0].longitude = -79.0532;
	workshop_locations[0].desc = "Hill Hall, home of the UNC Music Department";

	workshop_locations[1] = new Object();
	workshop_locations[1].latitude = 35.9111;
	workshop_locations[1].longitude = -79.0566;
	workshop_locations[1].desc = "Granville Towers";

	workshop_locations[2] = new Object();
	workshop_locations[2].latitude = 35.9130;
	workshop_locations[2].longitude = -79.0554;
	workshop_locations[2].desc = "Top of the Hill";

	workshop_locations[3] = new Object();
	workshop_locations[3].latitude = 35.9098;
	workshop_locations[3].longitude = -79.0548;
	workshop_locations[3].desc = "Carolina Inn";

	workshop_locations[4] = new Object();
	workshop_locations[4].latitude = 35.9106;
	workshop_locations[4].longitude = -79.0615;
	workshop_locations[4].desc = "411 West";

	workshop_locations[5] = new Object();
	workshop_locations[5].latitude = 35.9107;
	workshop_locations[5].longitude = -79.0665;
	workshop_locations[5].desc = "Carrburritos";

	workshop_locations[6] = new Object();
	workshop_locations[6].latitude = 35.9115;
	workshop_locations[6].longitude = -79.0718;
	workshop_locations[6].desc = "Panzanella";

	workshop_locations[7] = new Object();
	workshop_locations[7].latitude = 35.9628;
	workshop_locations[7].longitude = -79.0529;
	workshop_locations[7].desc = "Sage";

} // end load_restaurants

