

// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];

// This function picks up the click and opens the corresponding info window
function myclick(i) {
	GEvent.trigger(gmarkers[i], "click");
}

function initialize() 
{

if (GBrowserIsCompatible()) {

	// this variable will collect the html which will eventually be placed in the side_bar
	var side_bar_html = "";
	var side_bar_html2 = "";

		// A function to create the marker and set up the event window
	function createMarker(point,name,html,flag) {
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
		});
		// save the info we need to use later for the side_bar
		gmarkers.push(marker);
		// add a line to the side_bar html
		if (flag)
			side_bar_html += '<li><a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><\/li>';
		else
			side_bar_html2 += '<li><a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><\/li>';
		return marker;
	}

	// create the map
	var map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng( 52.898962,-8.21228), 7);

	// add the points in dublin
	var point = new GLatLng( 53.357826,-6.28418 );
	var marker = createMarker(point,"Ashgrove Interparts Ltd.","<strong>Ashgrove Interparts Ltd.</strong><br>Kill Avenue.<br>Dunlaoire.<br>Co Dublin.<br>Tel; 01-2805063.<br>Contact; Mr Dermot Kelly.<br>Dublin Area", 1);
	map.addOverlay(marker);

	point = new GLatLng( 53.285845,-6.158266 );
	marker = createMarker(point,"Abbey Service Station.","<strong>Abbey Service Station.</strong><br>Abbey Road.<br>Monkstown.<br>Co. Dublin.<br>Tel; 01-2809626.<br>Contact; George/Kay.",1);
	map.addOverlay(marker);

	point = new GLatLng( 53.340508,-6.228905 );
	marker = createMarker(point,"A & D Motorfactors.","<strong>A & D Motorfactors.</strong><br>Cromwellsfort Rd,<br>Dublin 12.<br>Tel; 01-460-1808.<br>Contact; Aiden/Ed.",1);
	map.addOverlay(marker);

	point = new GLatLng( 53.440508,-6.238905 );
	marker = createMarker(point,"test","<strong>A & D Motorfactors.</strong><br>Cromwellsfort Rd,<br>Dublin 12.<br>Tel; 01-460-1808.<br>Contact; Aiden/Ed.",1);
	map.addOverlay(marker);

	// add the point in belfast
	point = new GLatLng( 54.597,-5.93 );
	marker = createMarker(point,"test in belfast","<strong>belfast test</strong>",0);
	map.addOverlay(marker);

	// put the assembled side_bar_html contents into the side_bar div
  	document.getElementById("side_bar").innerHTML = "<h3>dublin</h3><ul>" + side_bar_html + "</ul>";
  	document.getElementById("side_bar").innerHTML += "<h3>belfast</h3><ul>" + side_bar_html2 + "</ul>";
}
else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
}

