var Goaze = window.Goaze || {};

Goaze.Map = function(){
	
	this.gmap = null;
	this.geocoder = geocoder = new GClientGeocoder();
}

Goaze.Map.prototype.init = function(){
	
	if (GBrowserIsCompatible()) {
		this.gmap = new GMap2(document.getElementById("map"));
		//this.gmap.setCenter(new GLatLng(37.4419, -122.1419), 16);
		var mapControl = new GMapTypeControl();
		this.gmap.addControl(mapControl);
		this.gmap.addControl(new GLargeMapControl());
	}
}

Goaze.Map.prototype.gotoAddress = function(address){

	var me = this;
	this.geocoder.getLatLng(
		address,
		function(point) {
		if (!point) {	
			alert(address + " not found");
		} else {
			me.gmap.setCenter(point, 16);
			
			var hotelIcon = new GIcon();
			hotelIcon.image = "http://www.goaze.nl/demos/maps/icons/icon_hotel_2.png";
			hotelIcon.shadow = "http://www.goaze.nl/demos/maps/icons/icon_hotel_2_shadow.png";
			hotelIcon.iconSize = new GSize(32, 32);
			hotelIcon.shadowSize = new GSize(37, 34);
			hotelIcon.iconAnchor = new GPoint(32, 32);
			hotelIcon.infoWindowAnchor = new GPoint(30, 1);
			
			var marker = new GMarker(point, { icon: hotelIcon } );
			me.gmap.addOverlay(marker);
			marker.openInfoWindowHtml(address);
			me.gmap.setMapType(G_SATELLITE_MAP);
			
			me.onDone(point);
			}
		}
	);
}

Goaze.Map.prototype.onDone = function(point){
	// do nothing
}

Goaze.Map.prototype.showCountry = function(country){

	// get center & bounding box
	
	var sw = new GLatLng(36.649162, 6.61976);
	var ne = new GLatLng(47.094719, 18.514999);
	var center = new GLatLng((sw.lat() + ne.lat())/2, (sw.lng() + ne.lng())/2);
	var zoom = this.gmap.getBoundsZoomLevel(new GLatLngBounds(sw, ne));
	this.gmap.setCenter(center, zoom);
}

Goaze.Map.prototype.showBounds = function(n, e, s, w){

	var sw = new GLatLng(s, w);
	var ne = new GLatLng(n, e);
	var center = new GLatLng((sw.lat() + ne.lat())/2, (sw.lng() + ne.lng())/2);
	var zoom = this.gmap.getBoundsZoomLevel(new GLatLngBounds(sw, ne));
	this.gmap.setCenter(center, zoom);	
}