var map;
var markers = new Array(
	// [GMarker, coordinates, small icon?, show info on startup?, info text, path]

	// Inventage, Technopark
	new Array(null, new GLatLng(47.389679,8.51545), false, false, '<p><strong>Inventage AG</strong></p><p><small>Technopark, Trakt Edison, 3. Etage</small></p>', null),
	// Foerlibuckstrasse
	new Array(null, new GLatLng(47.392248,8.517301), true, false, '<p><strong>F&ouml;rlibuckstrasse</strong></p><p><small>Tram Nr. 4</small></p>', new GPolyline(
		[new GLatLng(47.392248,8.517301), new GLatLng(47.391969,8.517913), new GLatLng(47.390273,8.516808), new GLatLng(47.389721,8.516378), new GLatLng(47.389961,8.515681), new GLatLng(47.389679,8.51545)], "#3333cc", 8)),
	// Bahnhof Hardbruecke
	new Array(null, new GLatLng(47.385217,8.517162), true, false, '<p><strong>Z&uuml;rich-Hardbr&uuml;cke</strong></p><p><small>S-Bahn Linien S5, S6, S7, S9, S12</small></p>', new GPolyline(
		[new GLatLng(47.385217,8.517162), new GLatLng(47.388323,8.519892), new GLatLng(47.389488,8.516228), new GLatLng(47.389721,8.516378), new GLatLng(47.389961,8.515681), new GLatLng(47.389679,8.51545)], "#3333cc", 8)),
	// Escher-Wyss-Platz
	new Array(null, new GLatLng(47.390818,8.522531), true, false, '<p><strong>Escher-Wyss-Platz</strong></p><p><small>Tram Nr. 4, 13</small></p>', new GPolyline(
		[new GLatLng(47.390818,8.522531), new GLatLng(47.388323,8.519892), new GLatLng(47.38951,8.516298), new GLatLng(47.389721,8.516378), new GLatLng(47.389961,8.515681), new GLatLng(47.389679,8.51545)], "#3333cc", 8))
);
function createMarker(index) {
	var icon = new GIcon();
	icon.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
	icon.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(3, 1);

	if(markers[index][2]) { markers[index][0] = new GMarker(markers[index][1], icon); }
	else { markers[index][0] = new GMarker(markers[index][1]); }

	GEvent.addListener(markers[index][0], 'click', function() {
		showMarkerInfo(index);
	});

	if(markers[index][5]) {
		GEvent.addListener(markers[index][0], 'mouseover', function() {
			map.addOverlay(markers[index][5]);
		});
		GEvent.addListener(markers[index][0], 'mouseout', function() {
			if (map.getInfoWindow().isHidden()) {
				map.removeOverlay(markers[index][5]);
			}
		});
		GEvent.addListener(markers[index][0], 'infowindowclose', function() {
			map.removeOverlay(markers[index][5]);
		});
	}
	map.addOverlay(markers[index][0]);

	if(markers[index][3]) { showMarkerInfo(index); }
}
function showMarkerInfo(index) {
	markers[index][0].openInfoWindowHtml(markers[index][4]);
	if(markers[index][5]) {
		map.addOverlay(markers[index][5]);
	}
}
window.onload = function() {
	if (GBrowserIsCompatible()) {
		var mapelement = document.getElementById('map');
		if (mapelement) {
			map = new GMap2(mapelement);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(47.388595,8.520895), 15);

			for(i=0; i < markers.length; i++) {
				createMarker(i);
			}
		}
	}
};
