/* ----- Google Maps, mostly used on Hotel Sites ------- */
var GoogleMap = new Class({
/*
	getOptions: function(){
		return {
			locationname: 'World',
			address: 'Projensdorfer Str. 324, 24106 Kiel',
			maptype: G_HYBRID_MAP,
			pictureURL: '../../../shared/nps/googlemaps/logo.gif',
			iconImage: '../../../shared/nps/googlemaps/marker.png',
			iconShadow: '../../../shared/nps/googlemaps/marker-shadow.png',
			iconSize: new GSize(30, 46),
			iconShadowSize: new GSize(66, 46),
			iconAnchor: new GPoint(15, 46)
		};
	},
*/

	initialize: function(element, options){
//		this.setOptions(this.getOptions(), options);
		this.element = element;

/*
		if(this.options.address){
			this.location = this.options.address;
		}
*/
		this.map = new GMap2(document.getElementById("googlemap"));
		this.options = options;
		this.map.setCenter(new GLatLng(this.options.markers[0].geoCoordinates.lat, this.options.markers[0].geoCoordinates.long), this.options.mapZoom, this.options.mapType);
		var geocoder = new GClientGeocoder();

		/* --- Basic configuration --- */
		this.map.addControl(new GLargeMapControl());
		this.map.addControl(new GMapTypeControl());
		this.map.enableScrollWheelZoom();
		this.map.enableContinuousZoom();

		/* --- Create new icon --- */
		this.icons = new Array(this.options.markers.length);

		for (var i = 0; i < this.options.markers.length; i++) {
			this.icons[i] = new GIcon();
			this.icons[i].image =  this.options.markers[i].iconImage;
			this.icons[i].iconSize = this.options.markers[i].iconSize;
			this.icons[i].iconAnchor = this.options.markers[i].iconAnchor;
			this.icons[i].shadow = this.options.markers[i].iconShadow;
			this.icons[i].shadowSize = this.options.markers[i].shadowSize;
			this.icons[i].infoWindowAnchor = this.options.markers[i].iconAnchor;

			/* --- On Click Information --- */
			this.icons[i].onclickInfo =
					'<img src=\"'+this.options.markers[i].pictureUrl +'\" style=\"float: left; margin-right: 6px;\">'+
					'<strong>'+this.options.markers[i].locationName+'</strong>'+
					'<br />'+this.options.markers[i].address+'<br />';

			/* Call geocoder */
			if (!this.options.markers[i].geoCoordinates && this.options.markers[i].address) {
				geocoder.getLocations(this.options.markers[i].address, this.setMap(i));
			} else {
				point = new GLatLng(
					this.options.markers[i].geoCoordinates.lat,
					this.options.markers[i].geoCoordinates.long
				);
				marker = new GMarker(point, this.icons[i]);
				this.map.addOverlay(marker);
				marker.bindInfoWindow(this.icons[i].onclickInfo);
			}
		}
	},

	/* --- Is called when geocoder responds --- */
	setMap:	function (i) {
		return function (response) {
			if (!response || response.Status.code != 200) {
				/* use geocoding from options */
				point = new GLatLng(
					this.options.markers[i].geoCoordinates.lat,
					this.options.markers[i].geoCoordinates.long
				);
			} else {
				/* when using google geocoder */
				place = response.Placemark[0];
				point = new GLatLng(
					place.Point.coordinates[1],
					place.Point.coordinates[0]
				);
			}

			var marker = new GMarker(point, this.icons[i]);
			this.map.setCenter(point, this.options.mapZoom, this.options.mapType);
			this.map.addOverlay(marker);
			marker.bindInfoWindow(this.icons[i].onclickInfo);
		}
	}
});
GoogleMap.implement(new Options);

function sprintf() {
	if( sprintf.arguments.length < 2 ) {
		return;
	}
	if (sprintf.arguments[0]) {
		var data = sprintf.arguments[0];
	} else {
		return;
	}
	for( var k=1; k<sprintf.arguments.length; ++k ) {
		switch(typeof(sprintf.arguments[k])) {
			case 'string':
				data = data.replace( /%s/, sprintf.arguments[k] );
				break;
			case 'number':
				data = data.replace( /%d/, sprintf.arguments[k] );
				break;
			case 'boolean':
				data = data.replace( /%b/, sprintf.arguments[k] ? 'true' : 'false' );
				break;
			default:
				/* function | object | undefined */
				break;
		}
	}
	return(data);
}
