var map;
var bounds;

function initialize(url) {

	if (typeof(url) == 'undefined') {
		url='';
	}
	var latlng = new google.maps.LatLng(51.461826,-2.510674);
	var myOptions = { zoom: 13, disableDefaultUI: true, center: latlng,mapTypeId: google.maps.MapTypeId.ROADMAP };
	map = new google.maps.Map(document.getElementById("map"), myOptions);
	//Create a new viewpoint bound
	bounds = new google.maps.LatLngBounds();
	var image = url + '/img/icon-pin.png';
	//frenchay
	var myLatLng = new google.maps.LatLng(51.4966124,-2.5130164);
	new gymOverlay(myLatLng,image,map,'Frenchay/Downend',url + '/clinics/frenchay-amp-downend.html',128);					
	bounds.extend(myLatLng);
	map.fitBounds(bounds);
	//kingswood
	var myLatLng = new google.maps.LatLng(51.461826,-2.510674);
	new gymOverlay(myLatLng,image,map,'Kingswood',url + '/clinics/kingswood.html',70);
	bounds.extend(myLatLng);
	map.fitBounds(bounds);	

	var myLatLng = new google.maps.LatLng(51.4144961,-2.4980325);
	new gymOverlay(myLatLng,image,map,'Keynsham',url + '/clinics/keynsham.html',67);
	bounds.extend(myLatLng);
	map.fitBounds(bounds);	
	
	//Bath
	var myLatLng = new google.maps.LatLng(51.376364,-2.373933);
	new gymOverlay(myLatLng,image,map,'Bath',url + '/clinics/bath.html',30);					
	bounds.extend(myLatLng);
	map.fitBounds(bounds);
	//midsomer
	var myLatLng = new google.maps.LatLng(51.289576,-2.4769211);
	new gymOverlay(myLatLng,image,map,'Midsomer Norton',url + '/clinics/midsomer-norton.html',111);					
	bounds.extend(myLatLng);
	map.fitBounds(bounds);
	

	
}

function gymOverlay(pos, image, map, num, link,width) {
	
	 // Now initialize all properties.
	this.pos_ = pos;
	this.image_ = image;
	this.map_ = map;
	this.num_ = num;
	this.div_ = null;
	this.setMap(map);
	this.link_ = link;
	this.width_ = width;
 
}

gymOverlay.prototype = new google.maps.OverlayView();
			
gymOverlay.prototype.onAdd = function() {

	var div = document.createElement('DIV');
	div.setAttribute('class','point');
	div.style.border = "none";
	div.style.borderWidth = "0px";
	div.style.position = "absolute";

	var p = document.createElement('p');
	p.innerHTML = '<a href="'+this.link_+ '">'+ this.num_ +'<\/a>';
	p.setAttribute('class','number');
	div.appendChild(p);
	this.div_ = div;

	p.style.width = this.width_ +'px' ;
	
	var panes = this.getPanes();
	panes.overlayLayer.appendChild(div);
	  
}

gymOverlay.prototype.draw = function() {

	var overlayProjection = this.getProjection();
	
	var bounds = new google.maps.LatLngBounds(this.pos_,this.pos_);
	
	var sw = overlayProjection.fromLatLngToDivPixel(bounds.getSouthWest());
	var ne = overlayProjection.fromLatLngToDivPixel(bounds.getNorthEast());
	
	var div = this.div_;
	
	div.style.left = (sw.x - Math.round(this.width_/2))+ 'px';
	div.style.top = (ne.y - 19) + 'px';

}
