var KAddress = Class.create();
KAddress.prototype = {
    initialize : function(gMap, gGeocoder, sName, sAddress, fGeocodeCallback) {
		this.map = gMap;
		this.gc = gGeocoder
		this.name = sName;
		this.address = sAddress;
		this.markerHtml = this._defaultMarkerHtml();
		this.geocode(fGeocodeCallback);
	}
	, _defaultMarkerHtml : function() {
		var sMarkerText = this.address;
		if(this.name && this.name.length > 0) {
			sMarkerText = "<b>"+this.name+"</b><br>"+sMarkerText;
		}
		return sMarkerText;				
	}
	, geocode : function(fGeocodeCallback) {
    	this.gc.getLatLng(this.address,function(gllPoint) {
    	   if(!gllPoint) {
    	       //Failed to retrieve lat/lng pt from Google for address
    	       return;
    	   }
    	   this.point = gllPoint;
    	   this.marker = this._newMarker(this.point);
    	   this.mark();
    	   if(fGeocodeCallback) {
    	       fGeocodeCallback();						
    	   }
    	}.bind(this));
	}
	, _newMarker : function(gllPoint) {
		var mk = new GMarker(gllPoint);
		GEvent.addListener(mk,"click",function(){
			this.openInfoWindow(false);
		}.bind(this));
		return mk;
	}
	, mark : function() {
		this.map.addOverlay(this.marker);
		this._marked = true;
	}
	, openInfoWindow : function(bCenter) {
		if(!this._marked) {
			this.mark();				
		}
		if(bCenter) {
			this.centerOn();
		}
		this.marker.openInfoWindowHtml(this.markerHtml);
		$("gMapsLink").href = "http://maps.google.com?q="+escape(this.address);
	}
	, centerOn : function() {
		this.map.setCenter(this.point);
	}
	, getOpenInfoWindowEventListener : function() {
		return function() {
			this.openInfoWindow(true);
		}.bindAsEventListener(this);
	}
};