/*
Copyright: © 2009 http://www.anymotion.de/
Author: anyMOTION GRAPHICS GmbH - Josef Fazekas
*/

var AnyGMap = function(elementID, options) {
	this.element = $('gmap_container_' + elementID);
	this.content = $('gmap_content_' + elementID).innerHTML;
	this.width   = options.width;
	this.height  = options.height;
	this.map     = null;
	this.element.setStyle({
		width: this.width + 'px',
		height: this.height + 'px',
		backgroundColor: '#fafafa'
	});
	this.anyMOTION = new GLatLng(51.230994629839934, 6.788821220397949);
	this.buildMap();
}

AnyGMap.prototype = {
	buildMap: function() {
		var that = this;
		this.map = new GMap2(this.element);
		this.map.addControl(new GMapTypeControl());
		this.map.addControl(new GSmallMapControl());
		this.map.setCenter(this.anyMOTION, 16);
		
		var marker = new GMarker(this.anyMOTION);
		GEvent.addListener(marker, "click", function() {
			that.map.openInfoWindowHtml(that.anyMOTION, that.content, {
				onCloseFn: function() {
					that.backToAny();
				}
			});
		});
		this.map.addOverlay(marker);
	},
	backToAny: function() {
		this.map.panTo(this.anyMOTION);
	}
}
