
/**
 * @package Galen_Therapy_WordPress
 * @subpackage Theme
 * @author Alex Southan
 * @link http://code.google.com/apis/maps/documentation/v3/
 */

jQuery(document).ready(function($) {
	$('#map').addClass('enabled');
	
	var map = new google.maps.Map(document.getElementById('map'), {
		zoom: 5,
		center: new google.maps.LatLng(54.5, -3.5),
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		mapTypeControl: false,
		scrollwheel	: false		
	});	
	
	var popUp  = new google.maps.InfoWindow();
	var bounds = new google.maps.LatLngBounds();
	
	$('#map-users li').each(function() {
		var jqThis   = $(this);
		var latLng   = $('address', this).attr('title').split(',');
		var position = new google.maps.LatLng(latLng[0], latLng[1]);
		
		bounds.extend(position);

		var marker = new google.maps.Marker({
			clickable: true,
			position: position,
			map: map
		});	
		
		google.maps.event.addListener(marker, 'click', function() {
			popUp.setContent(getPopUpHtml(jqThis));
			popUp.open(map, marker);
		});
	});
	
	map.fitBounds(bounds);
	
	function getPopUpHtml(e) {
		var c = e.html();
		// fix problems with Google computing dimensions
		c = '<div style="height:' + e.height() + 'px; width:' + e.width() + 'px; overflow:hidden">' + c + '</div>';
		return c;	
	}		
});