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, 11);
			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));
		this.directionsObj.load("from: " + address_1 + " to: " + address_2, { "locale": this.locale });
	}
	
	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();
	}
}



/*
var mapservice = null;

function load(){
	mapservice = new MapService('map');
	mapservice.init();
	mapservice.showControls();
	var mapserviceMarkerCount = mapservice.markers.length;
	mapservice.gotoAddress("Bulevardi 30 Helsinki", true, 
		function(){
			mapservice.markers[mapserviceMarkerCount].openInfoWindow("<img src=\"images/vj_logo.gif\" /><div style=\"padding: 0 0 20px 72px; color: #949494; margin-top: -10px;\">Bulevardi 30, Helsinki</div>");
		}
	);
}

function getDirections(){
	if(document.getElementById("from").value != ''){
		document.getElementById("directions").innerHTML = '';
		mapservice = new MapService('map')
		mapservice.init();
		mapservice.showControls();
		mapservice.gotoAddress("Bulevardi 30 Helsinki", false);
		mapservice.getDirections(document.getElementById("from").value, "Bulevardi 30 Helsinki", "directions");
	}
	return false;
}
*/
