/*<script src="http://maps.google.com/maps?file=api&amp;v=2.63&amp;key={$google_maps_key}" type="text/javascript"></script>
<script type="text/javascript" src="{$site_root}assets/js/pdmarker.js"></script>
//*/
var map = null;
var geocoder = null;
var points = new Object();
var pointsObj = new Object()
var icon = null;
var centered = null;
var firstid = null;

function setup() {
	if (GBrowserIsCompatible()) {
		if ($('map')) {
			map = new GMap2($('map'));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			geocoder = new GClientGeocoder();
			icon = new GIcon();
			icon.image = baseUrl + "/assets/images/icons/marker.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(5, 1);
			for (var pointID in pointsObj) {
				//alert("point " + pointID);
				var point = new GLatLng(pointsObj[pointID].lat, pointsObj[pointID].lon);
				points[pointID] = point;
			}
		}
	}
}
function addStore(id, lat, lon) {
	if (firstid == null) {
		firstid = id;
	}
	//alert("ok, " + id + ", " + lat + ", " + lon);
	//if( geocoder )
	//{
		//var point = new GLatLng( lat, lon );
		pointsObj[id] = {'lat':lat, 'lon':lon};
		//point;
		//if( centered == null ) // Only center the first point...
		//{
		//  map.setCenter(point, 13);
		//  centered = 1;
		//}
	//}
}

function onPageLoad() {
	setup();
//  pageloaded(); // call the main tpl onload
	// load tips for classname .showtooltip
	var myTips = new Tips($$('.showtooltip'), {
		maxTitleChars: 25,
		onShow: function(tip) {
					tip.effects({duration: 300, transition: Fx.Transitions.quadIn}).custom({'opacity': [0, 1]});
				},
		onHide: function(tip) {
					tip.effects({duration: 200, transition: Fx.Transitions.quadOut}).custom({'opacity': [1, 0]});
				},
		offsets: {x :10, y:10}
	});
	map.setCenter(points[firstid], 13);
	for (var pointid in points) {
		//alert( pointid );
		var marker = new PdMarker(points[pointid], icon);
		map.addOverlay(marker);
	}
	if (map)
		map.zoomToMarkers(5);
	//alert( 'centered...' );
	
}
function centerOn(id) {
	map.setZoom(15);
	map.panTo(points[id], 1000);
}
