function Map (div_id) {
	this.div_id = div_id;
	this.json	= { "businesses": [] };
	this.zoom	= null;
	
	this.postcodes 	= new Array();
	this.lat		= new Array();
	this.lng		= new Array();
	this.points 	= new Array();
	this.markers 	= new Array();
	this.bounds 	= new GLatLngBounds();
	
	this.map = new GMap2(document.getElementById(this.div_id));
	
	this.map.addControl(new GSmallMapControl());
	this.map.setCenter(new GLatLng(51.5,-0.126), 10);
}
Map.prototype.addGeo = function (lat, lng, marker) {
	marker = (typeof marker == "undefined") ? "" : "mini_" + marker;
	this.json.businesses.push({ "geo_lat" : lat, "geo_long": lng, "marker": marker });
	this.bounds.extend(new GLatLng(lat, lng));
};
Map.prototype.addPostcode = function (postcode, marker) {
	marker = (typeof marker == "undefined") ? "mini" : "mini_" + marker;
	this.postcodes.push(postcode);
	this.markers.push(marker);
};
Map.prototype.go = function () {
	for(var i = 0; i < this.json.businesses.length; i++) {
		var e = this;
		var lat = this.json.businesses[i].geo_lat;
		var lng = this.json.businesses[i].geo_long;
		var mark = this.json.businesses[i].marker;
		if (mark != "") { this.placeMarker(i, lat, lng, mark); }
		this.bounds.extend(new GLatLng(lat, lng));
	}
	this.setCtr();
};
Map.prototype.placeMarker = function (i, lat, lng, mark) {
	var e = this;
	var marker = new GMarker(new GLatLng(lat, lng), this.makeMarker(mark) );
	this.map.addOverlay(marker);
	GEvent.addListener(marker, 'click', function() {
		e.map.setZoom(16);
		e.map.panTo(new GLatLng(lat, lng));
	});
	this.markers[i] = marker;
};
Map.prototype.loadPostcodes = function () {
	var se = '/xhr/geo/';
	for (var i = 0; i < this.postcodes.length; i++) {
		se += this.postcodes[i] + "-" + this.markers[i] + "--";
	}
	var e = this;
	$.ajax({
		type: "GET",
// 		url: se,
		url: 'W1T5EN-mini--.js',
	  	dataType: "json",
		success: function (msg) {
			e.json = msg;
			e.go();
		}
	});
};
Map.prototype.makeMarker = function (marker) {
	var icon = new GIcon();
	icon.image = 'images/maps/'+marker+'.png';
	icon.iconSize = new GSize(25, 41);//12,23
	icon.iconAnchor = new GPoint(2, 50);//6,23
	icon.infoShadowAnchor = new GPoint(0, 0);
	icon.infoWindowAnchor = new GPoint(11, 2);	
	icon.printImage = 'images/maps/'+marker+'.gif';
	icon.mozPrintImage = 'images/maps/'+marker+'.gif';
	return icon;
};
Map.prototype.setCtr = function () {
	var clat = (this.bounds.getNorthEast().lat() + this.bounds.getSouthWest().lat()) /2;
	var clng = (this.bounds.getNorthEast().lng() + this.bounds.getSouthWest().lng()) /2;
	var minzoom = this.map.getBoundsZoomLevel(this.bounds);
	var mymin	= 15;
	var zn = (minzoom >= mymin) ? mymin: minzoom;
	if(this.zoom != undefined && this.zoom != null) { zn = this.zoom; }
	this.map.setCenter(new GLatLng(clat+0.0005, clng), zn);
};
