var Location = new Class({
	Implements: [Options],

	options: {	
		element:		null
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.options.element = $(this.options.element);
		
		this.map = new GMap2(this.options.element);
		this.geocoder = new GClientGeocoder();
		
		this.setMapOptions();
		this.build();
	},
	
	build:	function(){
		this.map.clearOverlays();
		
		this.geocoder.getLatLng(
			this.options.object.address.street + ',' + this.options.object.address.city,
			function(point) {
				if (!point) {
					alert(address + " not found");
				} else {
					this.position = point;
					this.marker = new GMarker(point);
					this.map.addOverlay(this.marker);
					this.showMarker();
					this.resize();
				}
			}.bind(this)
		);
	},
	
	resize:	function(){
		this.map.checkResize();
		this.map.setCenter(this.position, 13);
	},

	setMapOptions:	function(){
		this.map.enableScrollWheelZoom();
		this.map.addControl(new GLargeMapControl());
		this.map.addControl(new GMapTypeControl());		
	},
	
	
	showMarker:	function(){
		this.marker.openInfoWindowHtml(
			'<div class=\'marker\' style=\'width: 300px; height: 50px\'>' +
				'<img src=\'/img/googlemaps/' + this.options.object.media[0] + '\' />' + 
				'<div>' +
					'<h2>'+this.options.object.name+'</h2>' + 
					this.options.object.address.street + ' in ' + this.options.object.address.city + '<br />' +
				'</div>' +
			'</div>'
		);
	}
});
