/*Display loading images before loading the maps*/
var ShowMapLoading = new Class({
	initialize: function(containers){
		containers = $A(containers);
		containers.each(function(e){
			if (e) {
				e.setStyles({'display':'block', 'text-align':'center', 'background':'#ffffff'});
				e.innerHTML = "<p>Map Loading..</p><img src='" + MEDIA_URL + "img/core/map_loader.gif' alt='Map Loading...' style='border: none; margin: 15px auto' />";
			}
		});
	}
});

/*The most basic GoogleMapConfiguration */
var BaseGoogleMap = new Class({
	elem: null,
	map: null,
	initialize: function(container, height, opts) {
		if(typeof(opts) == 'undefined') opts = {};
		$extend(this, opts);
		this.elem = container;
		if (this.elem) {
			this.elem.empty();
			this.elem.setStyles({'height': height});
			this.init_map();
		}
	},

	init_map: function(){
		if (GBrowserIsCompatible()) {
			this.map = new GMap2(this.elem);
			this.map.addControl(new GLargeMapControl3D());
			this.map.addControl(new GMapTypeControl());
			this.map.addControl(new GScaleControl());
			this.map.setCenter(new GLatLng(56.2752, -3.1244), 11);
		}
	},

	plot_points: function(marker_list) {
		if (this.map) {
			var bounds = new GLatLngBounds();
			marker_list.each(function(e, i){
				var point = new GLatLng(e['latitude'], e['longitude']);
				bounds.extend(point);
				var marker = new GMarker(point);
				this.map.addOverlay(marker)
			}.bind(this));
	
			if (!bounds.isEmpty()) {
				this.map.setCenter(bounds.getCenter(), Math.min(15, this.map.getBoundsZoomLevel(bounds)));
			}
		}
	}
});