var staticmap_not_found = '/wp-content/themes/bier/images/map-dummy.png';
var staticmap_key = 'ABQIAAAAdUFdCL0v3nM0XRoejMfhEhRtZcz21joc7crYyNWUOwcMF7ec6hS6zK9zDfYxGFqdJwTO1jEgC4L2JA';
var staticmap_title = 'Auf Google Maps zeigen!';
var staticmap_geoc = {};

	jQuery.fn.extend({
		staticmap_build: function(address,id) {
			staticmap_geoc[id] = new GClientGeocoder();
			staticmap_geoc[id].getLatLng(address.replace(/\(.*\)/g, ''), function(point) {
				if (point) {
					jQuery().staticmap_imagelink(id,point,address);
				} else {
					jQuery().staticmap_dummylink(id,address);
				}
			});
		},
		staticmap_imagelink: function(id,point,address){
			staticmap_image_src = 'http://maps.google.com/staticmap?';
			staticmap_image_src += 'size=' + staticmap_size_w + 'x' + staticmap_size_h;
			staticmap_image_src += '&maptype=mobile';
			staticmap_image_src += '&format=mobile';
			staticmap_image_src += '&zoom='+staticmap_zoom;
			staticmap_image_src += '&center=' + point.lat() + ',' + point.lng();
			staticmap_image_src += '&markers=' + point.lat() + ',' + point.lng() + ',';
			staticmap_image_src += '&key='+staticmap_key;
			staticmap_link = 'http://maps.google.de/maps?f=q&hl=de&geocode&q='+escape(address)+'&g='+escape(address)+'&iwloc=cent';
			jQuery('#'+id).html('<a href="'+staticmap_link+'" target="_blank"><img src="'+staticmap_image_src+'" alt="+address+" title="'+staticmap_title+'" border="0"></a>');
		},
		staticmap_dummylink: function(id,address){
			staticmap_link = 'http://maps.google.de/maps?f=q&hl=de&geocode&q='+escape(address)+'&g='+escape(address)+'&iwloc=cent';
			jQuery('#'+id).html('<a href="'+staticmap_link+'" target="_blank"><img src="'+staticmap_not_found+'" alt="+address+" title="'+staticmap_title+'" border="0"></a>');
				

		}
	});

jQuery(document).ready(function() {
	// is the browser gmaps compatible
	if (GBrowserIsCompatible()) {
	

	
	
		// find elements with class staticmap
		jQuery(".staticmap").each(function (i) {
			// check for the rel attibute
			if(address = jQuery(this).attr('rel')){
				// give it an unique id
				jQuery(this).attr("id",id = "staticmap"+(staticmap_counter++));
				// find the gps coords and draw map
				jQuery().staticmap_build(address,id)
			
			}
		});
	}

});

