<?php

function googlemap_shortcode( $atts, $content = null ) {

	$defaults = array(
			'width' => '100%',
			'height' => '400px',
			'latitude' => '0',
			'longitude' => '0',
			'maptype' => 'ROADMAP',
			'zoom' => '14',
			'marker_latitude' => '0',
			'marker_longitude' => '0',
			'marker_address' => '',
			'marker_popup' => 'true',
			'marker_html' => '',
			'pan_control' => 'true',
			'zoom_control' => 'true',
			'map_type_control' => 'true',
			'scale_control' => 'true',
			'street_view_control' => 'false',
			'overview_map_control' => 'false',
		);

	extract(shortcode_atts($defaults, $atts));

	ob_start();
	?>
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery.gmap.min.js"></script>
<script>
if (typeof map_num == 'undefined') {
	var map_num = 0;
}
map_num ++;
(function($){
	document.write('<div class="google-map" id="google-map-'+map_num+'" style="width: <?php echo $width; ?>; height: <?php echo $height; ?>;"></div>');
	$('#google-map-'+map_num).gMap({
		latitude: <?php echo $latitude; ?>,
		longitude: <?php echo $longitude; ?>,
		maptype: '<?php echo $maptype; ?>',
		zoom: <?php echo $zoom; ?>,
		markers: [{
			latitude: <?php echo $marker_latitude; ?>,
			longitude: <?php echo $marker_longitude; ?>,
			address: '<?php echo $marker_address; ?>',
			popup: <?php echo $marker_popup; ?>,
			html: '<?php echo $marker_html; ?>'
		}],
		controls: {
			panControl: <?php echo $pan_control; ?>,
			zoomControl: <?php echo $zoom_control; ?>,
			mapTypeControl: <?php echo $map_type_control; ?>,
			scaleControl: <?php echo $scale_control; ?>,
			streetViewControl: <?php echo $street_view_control; ?>,
			overviewMapControl: <?php echo $overview_map_control; ?>
		}
	});
})(jQuery);
</script>
	<?php
	return ob_get_clean();
}

add_shortcode( 'googlemap', 'googlemap_shortcode' );

?>