function MapService(mapEmtId){
	this.mapEmtId = mapEmtId;
	this.mapEmt = null;
	this.mapObject = null;
	this.mapCenter = null;
	this.geocoder = null;
	this.centerInit = false;
	this.locale = "fi_FI";
	this.directionsObj = null;
	this.markers = new Array();
	
	this.init = function(){
		this.mapEmt = document.getElementById(this.mapEmtId);
		this.mapObject = new GMap2(this.mapEmt);
		this.geocoder = new GClientGeocoder();
	}
	
	this.addMarker = function(latLng){
		var marker = new GMarker(latLng);
		this.mapObject.addOverlay(marker);
		this.markers.push(marker);
		return marker;
	}
	
	this.gotoPos = function(latLng, setMarker, clickListener){
		if(this.centerInit == false){
			this.mapObject.setCenter(latLng, 14);
			this.centerInit = true;
		}
		else{
			this.mapObject.panTo(latLng);
		}
		this.mapCenter = latLng;
		if(setMarker == true){
			var marker = this.addMarker(latLng);
			if(clickListener != 'undefined' && clickListener != null){
				GEvent.addListener(marker, "click", clickListener);
			}
		}
	}
	
	this.gotoAddress = function(address, setMarker, clickListener){
		var mapObj = this;
		if (this.geocoder) {
			this.geocoder.getLatLng(
				address,
				function(point){
					mapObj.gotoPos(point, setMarker, clickListener);
				}
			);
		}
	}
	
	this.getDirections = function(address_1, address_2, emtId){
		this.directionsObj = new GDirections(this.mapObject, document.getElementById(emtId));
		var that = this;
        GEvent.bind(this.directionsObj, "error", this.directionsObj, function(obj){alert("GMaps error: " + obj.getStatus().code);});
		this.directionsObj.load("from: " + address_1 + " to: " + address_2, { "locale": this.locale, "getSteps": true });
	}
	
	this.showControls = function(){
		this.mapObject.addControl(new GLargeMapControl());
	}
	
	this.hideControls = function(){
		this.mapObject.removeControl(new GLargeMapControl());
	}
	
	this.setLocale = function(locale){
		this.locale = locale;
	}
	
	this.getCenter = function(){
		return this.mapObject.getCenter();
	}
}
