
function mapOptions(zoom, center, type)
{
	var mapOptions = {
		scrollwheel: false,
		zoom: zoom,
		center: center,
		mapTypeId: type,
		mapTypeControl: true,
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		navigationControl: true,
		navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}
	};

	return mapOptions;
}

function link(url) {
	return function () {
		window.location = url;
	}
}

function addMarker(map, position, url)
{
	var image = new google.maps.MarkerImage(
		webroot+'media/images/map/image.png',
		new google.maps.Size(57,50),
		new google.maps.Point(0,0),
		new google.maps.Point(29,50)
	);

	var shadow = new google.maps.MarkerImage(
		webroot+'media/images/map/shadow.png',
		new google.maps.Size(85,50),
		new google.maps.Point(0,0),
		new google.maps.Point(29,50)
	);

	var shape = {
		coord: [36,0,37,1,39,2,39,3,40,4,41,5,42,6,43,7,44,8,45,9,46,10,47,11,48,12,49,13,50,14,51,15,52,16,53,17,54,18,55,19,56,20,56,21,56,22,56,23,55,24,54,25,53,26,52,27,52,28,51,29,50,30,49,31,48,32,47,33,47,34,47,35,47,36,46,37,46,38,46,39,45,40,44,41,44,42,43,43,42,44,41,45,40,46,39,47,39,48,38,49,32,49,28,48,24,47,19,46,15,45,11,44,8,43,8,42,8,41,7,40,7,39,7,38,7,37,6,36,6,35,6,34,6,33,6,32,5,31,5,30,5,29,1,28,0,27,0,26,0,25,1,24,2,23,3,22,4,21,4,20,5,19,6,18,7,17,8,16,9,15,10,14,10,13,11,12,12,11,13,10,14,9,15,8,15,7,16,6,17,5,18,4,19,3,20,2,25,1,30,0,36,0],
		type: 'poly'
	};

	var marker = new google.maps.Marker({
		draggable: false,
		icon: image,
		shadow: shadow,
		shape: shape,
		map: map,
		position: position
	});

	if (url !== null)
		google.maps.event.addListener(marker, 'click', link(url));
}

function initialize() {

	var map;
	var centerPoint = new google.maps.LatLng(53.4335716, -2.2545576);
	var chorltonPoint = new google.maps.LatLng(53.4419542, -2.2766674);
	var didsburyPoint = new google.maps.LatLng(53.4165373, -2.2316944);
	var withingtonPoint = new google.maps.LatLng(53.4351315, -2.2273850);

	if (document.getElementById("allmap")) {

		map = new google.maps.Map(document.getElementById("allmap"), mapOptions(13, centerPoint, google.maps.MapTypeId.ROADMAP));
		addMarker(map, chorltonPoint, webroot+"contact/chorlton");
		addMarker(map, didsburyPoint, webroot+"contact/didsbury");
		addMarker(map, withingtonPoint, webroot+"contact/withington");

	}

	if (document.getElementById("chorlton-map")) {

		map = new google.maps.Map(document.getElementById("chorlton-map"), mapOptions(13, chorltonPoint, google.maps.MapTypeId.ROADMAP));
		addMarker(map, chorltonPoint, webroot+"contact/chorlton");

	} else if (document.getElementById("didsbury-map")) {

		map = new google.maps.Map(document.getElementById("didsbury-map"), mapOptions(13, didsburyPoint, google.maps.MapTypeId.ROADMAP));
		addMarker(map, didsburyPoint, webroot+"contact/didsbury");

	} else if (document.getElementById("withington-map")) {

		map = new google.maps.Map(document.getElementById("withington-map"), mapOptions(13, withingtonPoint, google.maps.MapTypeId.ROADMAP));
		addMarker(map, withingtonPoint, webroot+"contact/withington");

	} else if (document.getElementById("propertymap")) {

		var propertyPoint = new google.maps.LatLng(propertyLat, propertyLng);

		map = new google.maps.Map(document.getElementById("propertymap"), mapOptions(13, propertyPoint, google.maps.MapTypeId.ROADMAP));
		addMarker(map, propertyPoint, null);

	}
}

google.maps.event.addDomListener(window, 'load', initialize);

