var newpoints = new Array();

function loadMap(location, container, zoom) {
	var map = new GMap2(container);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(location, zoom);
	
	return map;
}
 
function addPoints() {
 	var map = loadMap(new GLatLng(55.978313,-3.960164), $('map'), 14);
	
	var icon0 = new GIcon();
	icon0.image = "http://www.google.com/mapfiles/marker.png";
	icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
	icon0.iconSize = new GSize(20, 34);
	icon0.shadowSize = new GSize(37, 34);
	icon0.iconAnchor = new GPoint(9, 34);
	icon0.infoWindowAnchor = new GPoint(9, 2);
	icon0.infoShadowAnchor = new GPoint(18, 25);
		
	newpoints[0] = new Array(55.978313,-3.960164, icon0, 'Xltec Recruitment', '<strong>Xltec Recruitment</strong><br />Xltec House<br />2E Napier Place<br />Wardpark North<br />Cumbernauld<br />G68 0LL<br /><a href=http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=2E+Napier+Place,+Cumbernauld,+Glasgow&sll=53.800651,-4.064941&sspn=19.805845,39.375&ie=UTF8&z=16&iwloc=A" target="_blank">Directions To Here</a>'); 
 
	for(var i = 0; i < newpoints.length; i++) {
		var point = new GPoint(newpoints[i][1],newpoints[i][0]);
		var popuphtml = newpoints[i][4] ;
		var marker = createMarker(point,newpoints[i][2],popuphtml);
		map.addOverlay(marker);
	}
	GEvent.trigger(marker,'click');
}

function findWorkplace(postCode){
	var geocoder = new GClientGeocoder();
	
	geocoder.getLatLng(
		postCode,
		function(point) {
			if (!point) {
				alert(address + " not found");
			} else {
				loadMap(point, $('job-map'), 13);
			}
		}
	);
}
 
function createMarker(point, icon, popuphtml) {
	var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>";
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(popuphtml);
	});
	return marker;
}