// Add course marker flag and info box...
$.jmap.addCourse = function(options, callback) {
	var latlng = new GLatLng(options.pointLatLng[0],options.pointLatLng[1]); // Map lat/long#
	//alert(options.idx);
	var _icon = new GIcon(); // create 
	_icon.iconSize = new GSize(32, 32); // set icon dimensions
	_icon.iconAnchor = new GPoint(16, 30); // set icon anchor point
	_icon.infoWindowAnchor = new GPoint(16, 30); // set anchor point of info window
	_icon.image = "/images/map_flag.png"; // set icon source
	var markerOptions = {icon:_icon}; // add icon to marker options
	var marker = new GMarker(latlng, markerOptions); // create new marker object using marker options
	GEvent.addListener(marker, "click", function() { // add event listener to marker to detect clicking
		var info = '<div style="width:200px;"><div style="padding:10px;"><br />';
		info += '<a href="' + options.info.link + '">' + options.info.title + '</a><br /><br />';
		info += 'Tel: ' + options.info.telephone + '<br /></div></div>';
		$.jmap.GMap2.openInfoWindowHtml(latlng, info); // open info window using innerhtml of div
	});
	$.jmap.GMap2.addOverlay(marker); // Add marker to map
	//cluster.push(marker);
	if (typeof callback == 'function') return callback();
	
	return marker;
}

$.jmap.addCluster = function(options, callback){
	cluster=new ClusterMarker($.jmap.GMap2, {clusterMarkerTitle:'Click to see info about locations' , clusterMarkerClick:function(args){
			cluster.defaultClickAction=function(){
				$.jmap.GMap2.setCenter(args.clusterMarker.getLatLng(), $.jmap.GMap2.getBoundsZoomLevel(args.clusterMarker.clusterGroupBounds))
				delete cluster.defaultClickAction;
			}
			var html='<div style="overflow:auto; width:24em"><h4>'+args.clusteredMarkers.length+' golf courses:</h4>';
			for (i=0; i<args.clusteredMarkers.length; i++) {
				html+='<a href="javascript:cluster.triggerClick('+args.clusteredMarkers[i].index+')">'+args.clusteredMarkers[i].getTitle()+'</a><br />';
			}
			html+='<br /><a href="javascript:void(0)" onclick="cluster.defaultClickAction()">Zoom</a> in to show these locations</div>';
			//	args.clusterMarker.openInfoWindowHtml(html);
			$.jmap.GMap2.openInfoWindowHtml(args.clusterMarker.getLatLng(), html);
		}
	});
	cluster.addMarkers(options.markers);
	//cluster.fitMapToMarkers();
	cluster.refresh();
	$.jmap.GMap2.savePosition();

	if (typeof callback == 'function') return callback();
}