

// Map variables

var map;								// to hold the Google map object

var latitude = 51.4695;					// centre of map
var longitude = -0.6155;
var zoom = 15;							// initial zoom level

// Path constants

var cyclePaths = [];					// to hold the paths
var cyclePathColor = "#0000cc";			// colour to draw them in
var cyclePathWeight = 3;				// line width
var cyclePathOpacity = 0.6;				// line opacity

// Premises constants

var premises = [];						// to hold the premises
var premisesColor = "#cc0000";			// line colour
var premisesWeight = 1;					// width of boundary
var premisesOpacity = 0.5;				// opacity of outline
var premisesFill = "#999966";			// fill colour
var premisesShade = 0.2;					// fill opacity

// Map symbols

var symbols = [];						// to hold the symbols

// create the symbol objects (lowest zindex first)

symbols['parkingp'] = new Symbol(latitude+0.0013,longitude-0.0018,"/images/markers/parking.png",14,16,16,8,10,"Parent parking. Staff and visitors use Wood Close.");
symbols['parkings'] = new Symbol(latitude-0.0001,longitude+0.0012,"/images/markers/parking.png",14,16,16,8,10,"Staff and visitor parking. Parents use St Leonard's Road.");
symbols['premises'] = new Symbol(latitude,longitude,"/images/markers/trevelyan.png",0,16,20,8,10,"Trevelyan School, Wood Close, Windsor, SL4 3LL");

/* -------------------------------------------------------------

Define the Symbol object:
1. latitude
2. longitude
3. image to use
4. minimum zoom level at which to display marker
5. width in pixels
6. height in pixels
7. marker's anchor point X in pixels
8. marker's anchor point Y in pixels
9. title text

*/

function Symbol(lat,lng,image,minzoom,width,height,anchorx,anchory,title) {
	this.lat = lat;
	this.lng = lng;
	this.image = image;
	this.minzoom = minzoom;
	this.width = width;
	this.height = height;
	this.anchorx = anchorx;
	this.anchory = anchory;
	this.title = title;
	this.marker = null;
	
	// hide or show the marker according to the provided zoom level
	this.zoom = zoom;	
	function zoom(newzoom) {
		if ( this.minzoom < 1 ) return;
		if ( zoom < this.minzoom ) {
			if ( !this.marker.isHidden() ) this.marker.hide();
		} else {
			if ( this.marker.isHidden() ) this.marker.show();
		}
	}
}

/* -------------------------------------------------------------

Cycle paths

*/

var cyclePaths = [

	// National Route 4

	// Stovell Road - Eton Wick
	[
		[51.48555, -0.62378],
		[51.48627, -0.62329],
		[51.48748, -0.62299],
		[51.48819, -0.62294],
		[51.48712, -0.62320],
		[51.48704, -0.62245],
		[51.48727, -0.62097],
		[51.48754, -0.61985],
		[51.48750, -0.61887],
		[51.48782, -0.61807],
		[51.48846, -0.61796],
		[51.48838, -0.61764],
		[51.49089, -0.61786],
		[51.49195, -0.61773],
		[51.49219, -0.61726],
		[51.49347, -0.61653],
		[51.49378, -0.61942],
		[51.49404, -0.62123],
		[51.49437, -0.62290],
		[51.49486, -0.62605],
		[51.49579, -0.63116],
		[51.49652, -0.63316]
	],

	// St Leonard's Road - Stovell Road
	[
		[51.47042, -0.62258],
		[51.47078, -0.62187],
		[51.47097, -0.62174],
		[51.47094, -0.62088],
		[51.47205, -0.62101],
		[51.47249, -0.62120],
		[51.47282, -0.62151],
		[51.47340, -0.62241],
		[51.47369, -0.62262],
		[51.47401, -0.62264],
		[51.47552, -0.62196],
		[51.47530, -0.62103],
		[51.47722, -0.61992],
		[51.47721, -0.61949],
		[51.47842, -0.61932],
		[51.47924, -0.61904],
		[51.48318, -0.61979],
		[51.48516, -0.61934],
		[51.48552, -0.62382]
	],

	// Bishop's Gate - St Leonard's Road
	[
		[51.44052, -0.59408],
		[51.44043, -0.59717],
		[51.44127, -0.59792],
		[51.44157, -0.59842],
		[51.44194, -0.59962],
		[51.44326, -0.60179],
		[51.44380, -0.60221],
		[51.44451, -0.60262],
		[51.44465, -0.60279],
		[51.44488, -0.60333],
		[51.44499, -0.60385],
		[51.44508, -0.60464],
		[51.44506, -0.60580],
		[51.44518, -0.60640],
		[51.44530, -0.60663],
		[51.44598, -0.60754],
		[51.44630, -0.60803],
		[51.44669, -0.60895],
		[51.44686, -0.61058],
		[51.44678, -0.61251],
		[51.44666, -0.61346],
		[51.44635, -0.61479],
		[51.44530, -0.61769],
		[51.44503, -0.61835],
		[51.44471, -0.61979],
		[51.44435, -0.62279],
		[51.44427, -0.62472],
		[51.44435, -0.62575],
		[51.44488, -0.62934],
		[51.44516, -0.63080],
		[51.44699, -0.63082],
		[51.44784, -0.63058],
		[51.44852, -0.63015],
		[51.44990, -0.62884],
		[51.45023, -0.62871],
		[51.45130, -0.62867],
		[51.45170, -0.62925],
		[51.45204, -0.62878],
		[51.45355, -0.62580],
		[51.45414, -0.62455],
		[51.45591, -0.62380],
		[51.45676, -0.62367],
		[51.45824, -0.62292],
		[51.45979, -0.62234],
		[51.46062, -0.62258],
		[51.46078, -0.62249],
		[51.46107, -0.62264],
		[51.46222, -0.62275],
		[51.46505, -0.62341],
		[51.46549, -0.62286],
		[51.46582, -0.62271],
		[51.46623, -0.62223],
		[51.46673, -0.62174],
		[51.46729, -0.62095],
		[51.46801, -0.61927],
		[51.46821, -0.61861],
		[51.46855, -0.61932],
		[51.46877, -0.62013],
		[51.46974, -0.62135],
		[51.47023, -0.62266],
		[51.47049, -0.62260]
	],

	// Route 4 link
	[
		[51.46825, -0.61863],
		[51.46799, -0.61814],
		[51.46769, -0.61717],
		[51.46714, -0.61618],
		[51.46640, -0.61445],
		[51.46619, -0.61408],
		[51.46599, -0.61344],
		[51.46573, -0.61290]
	],

	// Barry Avenue
	[
		[51.48516, -0.61934],
		[51.48492, -0.61799],
		[51.48519, -0.61663],
		[51.48519, -0.61558],
		[51.48492, -0.61333],
		[51.48499, -0.61090],
		[51.48512, -0.60945],
		[51.48508, -0.60915]
	],

	// Windsor to Old Windsor
	[
		[51.47130, -0.60749],
		[51.47119, -0.60706],
		[51.47123, -0.60679],
		[51.47109, -0.60642],
		[51.47066, -0.60625],
		[51.47077, -0.60582],
		[51.47054, -0.60569],
		[51.46963, -0.60442],
		[51.46942, -0.60410],
		[51.46912, -0.60342],
		[51.46875, -0.60219],
		[51.46764, -0.59814],
		[51.46518, -0.58893],
		[51.46494, -0.58908],
		[51.46463, -0.58786]
	],

	// Maidenhead Road North
	[
		[51.48552, -0.62380],
		[51.48513, -0.62395],
		[51.48509, -0.62444],
		[51.48513, -0.62485],
		[51.48529, -0.62603],
		[51.48485, -0.62629],
		[51.48397, -0.62661],
		[51.48394, -0.62683],
		[51.48405, -0.62741],
		[51.48436, -0.62848],
		[51.48507, -0.63457],
		[51.48531, -0.63725],
		[51.48531, -0.63844],
		[51.48523, -0.64163],
		[51.48525, -0.64384],
		[51.48535, -0.64464],
		[51.48533, -0.64569],
		[51.48513, -0.64713],
		[51.48472, -0.65197],
		[51.48464, -0.65371],
		[51.48465, -0.65442],
		[51.48484, -0.65474],
		[51.48525, -0.65685],
		[51.48537, -0.65785],
		[51.48576, -0.66013],
		[51.48585, -0.66079],
		[51.48580, -0.66109],
		[51.48516, -0.66264],
		[51.48525, -0.66442],
		[51.48607, -0.66607],
		[51.48664, -0.66749],
		[51.48707, -0.66882],
		[51.48874, -0.67549],
		[51.48940, -0.67764],
		[51.49029, -0.67996],
		[51.49275, -0.68558],
		[51.49497, -0.69135],
		[51.49843, -0.70058],
		[51.49948, -0.70315],
		[51.49960, -0.70324],
		[51.49963, -0.70345],
		[51.50010, -0.70433],
		[51.50090, -0.70592],
		[51.50241, -0.70826],
		[51.50306, -0.70948],
		[51.50405, -0.71079]
	],

	// Maidenhead Road - Green Lane
	[
		[51.48396, -0.62698],
		[51.48370, -0.62706],
		[51.48360, -0.62668],
		[51.48151, -0.62736],
		[51.48131, -0.62753],
		[51.48087, -0.62867],
		[51.48015, -0.62921],
		[51.47955, -0.62942],
		[51.47957, -0.62923],
		[51.47929, -0.62919],
		[51.47951, -0.62693],
		[51.47895, -0.62713],
		[51.47854, -0.62498]
	],

	// Winkfield Road & Imperial Road
	[
		[51.46335, -0.64530],
		[51.46356, -0.64481],
		[51.46550, -0.64195],
		[51.46648, -0.64069],
		[51.46812, -0.63792],
		[51.46967, -0.63492],
		[51.47004, -0.63397],
		[51.47051, -0.63215],
		[51.47087, -0.63024],
		[51.47107, -0.63007],
		[51.47097, -0.62983],
		[51.47121, -0.62856],
		[51.47138, -0.62859],
		[51.47523, -0.62655],
		[51.47728, -0.62573],
		[51.47868, -0.62492],
		[51.47923, -0.62479],
		[51.47959, -0.62483],
		[51.47969, -0.62522],
		[51.47997, -0.62532],
		[51.48020, -0.62490],
		[51.48035, -0.62395],
		[51.48015, -0.62344],
		[51.47989, -0.62320],
		[51.47965, -0.62335],
		[51.47932, -0.62395],
		[51.47932, -0.62479]
	],

	// Imperial Road - Bulkeley Avenue
	[
		[51.47808, -0.62522],
		[51.47801, -0.62483],
		[51.47766, -0.62505],
		[51.47748, -0.62438],
		[51.47732, -0.62412],
		[51.47594, -0.62275],
		[51.47562, -0.62219],
		[51.47552, -0.62196]
	]
];

/* -------------------------------------------------------------

Generate the premises

*/

var premisesPath = [
	[51.469062,-0.613119],
	[51.469333,-0.613752],
	[51.469358,-0.613874],
	[51.469135,-0.614070],
	[51.469314,-0.614522],
	[51.468821,-0.615032],
	[51.469113,-0.615653],
	[51.467937,-0.616972],
	[51.468799,-0.619306],
	[51.469714,-0.618029],
	[51.469577,-0.617203],
	[51.469614,-0.617144],
	[51.469691,-0.617133],
	[51.469932,-0.616801],
	[51.470049,-0.616575],
	[51.470182,-0.616516],
	[51.470420,-0.617058],
	[51.470587,-0.617310],
	[51.470714,-0.617412],
	[51.470921,-0.617729],
	[51.471048,-0.617795],
	[51.471121,-0.617407],
	[51.471041,-0.617353],
	[51.470814,-0.617048],
	[51.470440,-0.616597],
	[51.470319,-0.616738],
	[51.470173,-0.616329],
	[51.470122,-0.616110],
	[51.469930,-0.615658],
	[51.469721,-0.615293],
	[51.469642,-0.615053],
	[51.469622,-0.614906],
	[51.469585,-0.614926],
	[51.469478,-0.614384],
	[51.469629,-0.614304],
	[51.469422,-0.613811],
	[51.469392,-0.613683],
	[51.469124,-0.613054]
]


/* -------------------------------------------------------------

Display the map

*/

function googleStart() {

	var mapsymbols = [];			// to hold the map symbols
	var myLatlng = new google.maps.LatLng(latitude, longitude);
	var myOptions = {
		zoom: zoom,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};	
	
	// instantiate a new map object
	
	var map = new google.maps.Map(document.getElementById("googlemap"),myOptions);

	// create a Marker object for every symbol and let the marker-manager know about it
	
	var z = 0;
	for ( s in symbols ) {
		
		// create a Marker object for the symbol
		
		symbols[s].marker = new google.maps.Marker({
			position:new google.maps.LatLng(symbols[s].lat,symbols[s].lng),
			icon:symbols[s].image,
			title:symbols[s].title,
			zIndex: z++,
			map: map
		});
		
	}
	
	// centre the map on the premises marker and zoom as required
	
	map.setCenter(symbols['premises'].marker.getPosition(), zoom);
	
	// add the premises overlay
	
	var premises = [];
	for ( p in premisesPath ) {
		premises.push(new google.maps.LatLng(premisesPath[p][0],premisesPath[p][1]));
	}
	
	premisesPath = new google.maps.Polygon({
		path: premises,
		strokeColor: premisesColor,
		strokeOpacity: premisesOpacity,
		strokeWeight: premisesWeight,
		fillColor: premisesFill,
		fillOpacity: premisesShade,
		clickable: false,
		map: map
	});

	// add the path overlays
	
	for ( c in cyclePaths ) {
		var path = [];
		for ( p in cyclePaths[c] ) {
			path.push(new google.maps.LatLng(cyclePaths[c][p][0],cyclePaths[c][p][1]));
		}
		cyclePaths[c] = new google.maps.Polyline({
			path: path,
			strokeColor: cyclePathColor,
			strokeOpacity: 0,
			strokeWeight: cyclePathWeight,
			clickable: false,
			map: map
		});
	}
	
}

/* -------------------------------------------------------------

Display or hide the cycle paths

*/

function viewCyclePaths(show) {
	if ( show ) var o = cyclePathOpacity; else var o = 0;
	for ( c in cyclePaths ) {
		cyclePaths[c].setOptions({strokeOpacity: o})
	}
}

// Go!

window.onload = googleStart;




