function initialiseLocation()
{  	
	var key = '';
	
	if(location.href.indexOf("http://dmzapp3/") == 0 ) 
	{
		key = 'ABQIAAAARx9madggnds5eSq8HufVsBSbsX2UramW5cKR52lCLZq57_iYhBQXmJlvYKuqGQHLxsCkBP9C0KYtoA';
		document.write('<script src="http://maps.google.com/maps?file=api&v=2.140&' +
			'key=' + key + '" ' +
			'type="text/javascript">');
		document.write('<\/script>');
	}
	else if(location.href.indexOf("http://81.171.168.250/") == 0 ) 
	{
		key = 'ABQIAAAAsKeW7EsYIm0jj4fJXwu5bxQNy3RIRt7FpGYGQM3sHDqTDIWXMBQPCObnwnaDyDt2fxDwS-yHtpS00A';
		document.write('<script src="http://maps.google.com/maps?file=api&v=2&' +
			'key=' + key + '" ' +
			'type="text/javascript">');
		document.write('<\/script>');
	}
	else if(location.href.indexOf("http://www.cliftoncollegeuk.com/") == 0 ) 
	{ 
		key = 'ABQIAAAAsKeW7EsYIm0jj4fJXwu5bxSnhKm3SxbHMSWQVqgUtUad5ra8AhQbN0yRJUjDo_k4lzq5tgMvl3_mEw';
		document.write('<script src="http://maps.google.com/maps?file=api&v=2&' +
			'key=' + key + '" ' +
			'type="text/javascript">');
		document.write('<\/script>');
	}
	else if(location.href.indexOf("http://cliftoncollegeuk.com/") == 0 ) 
	{
		key = 'ABQIAAAAsKeW7EsYIm0jj4fJXwu5bxT6jKHZkYkKMfrVKgs3tzaYjg4GjBQmlZ_BZZXZ0fTgd-hGt27ZCWoLWg';
		document.write('<script src="http://maps.google.com/maps?file=api&v=2&' +
			'key=' + key + '" ' +
			'type="text/javascript">');
		document.write('<\/script>');
	} 
	return key;
}

function initialiseBasicMap(divID, coords, zoom)
{
	/*creates a new map*/
	map = new GMap2(document.getElementById(divID));

	/*adds navigation and map type controls*/
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());

	/*centres the map on the latitude and longitude of CC*/
	map.setCenter(new GLatLng(coords[0], coords[1]), zoom);

	/*sets the default map type as hybrid*/
	map.setMapType(G_HYBRID_MAP);
	
	return map;
}

function addPoint(coords, title, tabContents)
{
	var icon = new GIcon();
	icon.image = '/images/map/cliftonMarker.png';
	icon.shadow = '/images/map/shadow.png';
	icon.iconSize = new GSize(21, 34);
	icon.shadowSize = new GSize(37, 34);
	icon.iconAnchor = new GPoint(6, 18);    
	icon.infoWindowAnchor = new GPoint(9, 5);
	
	var pointLocation = new GLatLng(coords[0], coords[1]);
	var pointPoint = new GMarker(pointLocation, {title:title, icon:icon});
	map.addOverlay(pointPoint);
	
	var pointTabs = new Array(tabContents.length);
	var counter = 0;
	for(var i in tabContents)
	{
		/*ignores functions that are members of the tabContents array (like indexOf)*/
		if(typeof tabContents[i] == 'string')
		{
			pointTabs[counter] = new GInfoWindowTab(i, tabContents[i]);
			counter++;
		}
	}
	
	addEvents(pointPoint, pointTabs);
}

/*adds the mouseover, mouseout and onclick events for the given marker (onclick showing the given tabs)*/
function addEvents(marker, tabs)
{
	GEvent.addListener(marker, "mouseover", function() 
	{
		marker.setImage('/images/map/cliftonMouseoverMarker.png');
	});	
	GEvent.addListener(marker, "mouseout", function() 
	{
		marker.setImage('/images/map/cliftonMarker.png');
	});
	GEvent.addListener(marker, "click", function() 
	{
		marker.openInfoWindowTabsHtml(tabs);
	});
}

/*functions above here are used by other applications*/


	function initialiseMap()
	{
		/*global variable to store the current view*/
		currentView = "mainBuildings";
	
		/*creates a new map*/
		map = initialiseBasicMap("map_div", new Array(51.462, -2.620), 16)
		
		addMainBuildingPins();
		addRouteToBB();
	
		/*adds a generic event which gets triggered when any info window is closed*/
		GEvent.addListener((map.getInfoWindow()), "closeclick", function() 
		{
			var infoWindowPoint = (map.getInfoWindow()).getPoint();
			var BBPoint = new GLatLng(51.455999, -2.650316);
		
			if(map.getZoom() == 16)
			{
				if((infoWindowPoint.lat() == BBPoint.lat()) && (infoWindowPoint.lng() == BBPoint.lng()))
				{
					map.panTo(BBPoint);
				}
				else
				{
					/*resets the central map location*/
					zoomToLocation("reset");
				}
			}
			else
			{
				map.panTo(new GLatLng(infoWindowPoint.lat(), infoWindowPoint.lng()));
			}
		});
	}	

	function getDirections()
	{
		var origin = document.getElementById("origin").value;
		var destination = map.getCenter().lat() + ", " + map.getCenter().lng();
		window.open("http://maps.google.co.uk/maps?saddr={" + origin + "}&daddr=" + destination + "", "directionsWindow", "width=800, height=700, resizable=yes, scrollbars=yes, toolbar=no, directories=no, location=no, menubar=no");
	}
	
	function changePins()
	{
		var changePins = document.getElementById("changePins");
		var mainBuildings = document.getElementById("mainBuildings");
		var houses = document.getElementById("houses");
		var routeToBB = document.getElementById("RouteToBB");
		
		if(currentView == "mainBuildings")
		{
			mainBuildings.style.display = "none";
			houses.style.display = "block";
			changePins.innerHTML = "show main buildings";
			routeToBB.style.display = "none";
			currentView = "houses";
			
			map.clearOverlays();
			addHousePins();
		}
		else if(currentView == "houses")
		{
			mainBuildings.style.display = "block";
			houses.style.display = "none";
			changePins.innerHTML = "show houses";
			routeToBB.style.display = "inline";
			currentView = "mainBuildings";
			
			map.clearOverlays();
			addMainBuildingPins();
			addRouteToBB();
		}
	}
	
	
	function linkMouseover()
	{
		window.document.body.style.cursor = 'pointer'; 
		event.srcElement.style.color = 'blue'; 			
	}
	
	function linkMouseout()
	{
		window.document.body.style.cursor = 'default'; 
		event.srcElement.style.color = '#06C';
	}


	function addMainBuildingPins()
	{			
		var icon = new GIcon();
		icon.image = '/map/images/cliftonMarker.png';
		icon.shadow = '/map/images/shadow.png';
		icon.iconSize = new GSize(21, 34);
		icon.shadowSize = new GSize(37, 34);
		icon.iconAnchor = new GPoint(6, 18);    
		icon.infoWindowAnchor = new GPoint(9, 5);
				
		/*adds a pointer to locate the upper school*/
		var upperSchoolLocation = new GLatLng(51.462161, -2.620699);
		var upperSchoolPoint = new GMarker(upperSchoolLocation, {title:"Upper School", icon:icon});
		map.addOverlay(upperSchoolPoint);
		
		/*creates tabs in which the details and image of the upper school are added (in HTML code)*/
		var upperSchoolPointTabs = new Array(2);
		upperSchoolPointTabs[0] = new GInfoWindowTab("details", "<p><b>Upper School</b></p><p>Porters' Lodge<br />Guthrie Road<br />Bristol<br />BS8 3LE</p><p><em>0117 315 7686</em></p>");
		upperSchoolPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/UpperSchool.jpg' /></p>");
		
		addEvents(upperSchoolPoint, upperSchoolPointTabs);
		
		/*does the same for the remainder of the points*/
	
		var prepSchoolLocation = new GLatLng(51.464255, -2.620458);
		var prepSchoolPoint = new GMarker(prepSchoolLocation, {title:"Prep School", icon:icon});
		map.addOverlay(prepSchoolPoint);
		
		var prepSchoolPointTabs = new Array(2);
		prepSchoolPointTabs[0] = new GInfoWindowTab("details", "<p><b>Prep School</b></p><p>The Avenue<br />Clifton<br />Bristol<br />BS8 3HE</p><p><em>0117 315 7502</em></p>");
		prepSchoolPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/PreSchool.jpg' /></p>");

		addEvents(prepSchoolPoint, prepSchoolPointTabs);
			
		var butcombeLocation = new GLatLng(51.463575, -2.618523);
		var butcombePoint = new GMarker(butcombeLocation, {title:"Butcombe", icon:icon});
		map.addOverlay(butcombePoint);
		
		var butcombePointTabs = new Array(2);
		butcombePointTabs[0] = new GInfoWindowTab("details", "<p><b>Butcombe (Pre-prep School)</b></p><p>Guthrie Road<br />Clifton<br />Bristol<br />BS8 3EZ</p><p><em>0117 315 7591</em><br /><br /><br /></p>");
		butcombePointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/Butcombe.jpg' /></p>");

		addEvents(butcombePoint, butcombePointTabs);
			
		var receptionLocation = new GLatLng(51.461593, -2.621998);
		var receptionPoint = new GMarker(receptionLocation, {title:"Reception", icon:icon});
		map.addOverlay(receptionPoint);
	
		var receptionPointTabs = new Array(2);
		receptionPointTabs[0] = new GInfoWindowTab("details", "<p><b>Reception</b></p><p>32 College Road<br />Clifton<br />Bristol<br />BS8 3JH</p><p><em>0117 315 7000</em></p>");
		receptionPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/32CollegeRd.jpg' /></p>");

		addEvents(receptionPoint, receptionPointTabs);
			
		var ccslLocation = new GLatLng(51.459963, -2.618185);
		var ccslPoint = new GMarker(ccslLocation, {title:"CCSL", icon:icon});
		map.addOverlay(ccslPoint);
	
		var ccslPointTabs = new Array(2);
		ccslPointTabs[0] = new GInfoWindowTab("details", "<p><b>Clifton College Services Ltd.</b></p><p>3 Worcester Road<br />Clifton<br />Bristol<br />BS8 3JL</p><p><em>0117 315 7666</em></p>");
		ccslPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/WisemansAndCCSL.jpg' /></p>");
		
		addEvents(ccslPoint, ccslPointTabs);
			
		var bbLocation = new GLatLng(51.455999, -2.650316);
		var bbPoint = new GMarker(bbLocation, {title:"Sports Ground", icon:icon});
		map.addOverlay(bbPoint);
	
		var bbPointTabs = new Array(2);
		bbPointTabs[0] = new GInfoWindowTab("details", "<p><b>Clifton College Sports Ground</b></p><p>Abbots Leigh Road<br />Clifton<br />Bristol<br />BS8 3QD</p><p><em>0117 923 7780</em></p>");
		bbPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/BBReception.jpg' /></p>");

		addEvents(bbPoint, bbPointTabs);
			
		var theatreLocation = new GLatLng(51.460160, -2.621996);
		var theatrePoint = new GMarker(theatreLocation, {title:"Redgrave Theatre", icon:icon});
		map.addOverlay(theatrePoint);
	
		var theatrePointTabs = new Array(2);
		theatrePointTabs[0] = new GInfoWindowTab("details", "<p><b>Redgrave Theatre</b></p><p>Percival Road<br />Clifton<br />Bristol<br />BS8 3LE<br /><br /></p>");
		theatrePointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/RedgraveTheatre.jpg' /></p>");
		
		addEvents(theatrePoint, theatrePointTabs);
	}

	function addHousePins()
	{			
		var icon = new GIcon();
		icon.image = '/map/images/cliftonMarker.png';
		icon.shadow = '/map/images/shadow.png';
		icon.iconSize = new GSize(21, 34);
		icon.shadowSize = new GSize(37, 34);
		icon.iconAnchor = new GPoint(6, 18);    
		icon.infoWindowAnchor = new GPoint(9, 5);
				
		/*adds a pointer to locate Moberly's House*/
		var moberlysLocation = new GLatLng(51.461742, -2.622186);
		var moberlysPoint = new GMarker(moberlysLocation, {title:"Moberly's House", icon:icon});
		map.addOverlay(moberlysPoint);
		
		/*creates tabs in which the details and image of Moberly's are added (in HTML code)*/
		var moberlysPointTabs = new Array(2);
		moberlysPointTabs[0] = new GInfoWindowTab("details", "<p><b>Moberly's House</b></p><p>College Road<br />Clifton<br />Bristol<br />BS8 3JJ</p><p><em>0117 315 7310</em></p>");
		moberlysPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/MoberlysHouse.jpg' /></p>");
		
		addEvents(moberlysPoint, moberlysPointTabs);
		
		/*does the same for the remainder of the houses*/		

		var hallwardsLocation = new GLatLng(51.461416, -2.621784);
		var hallwardsPoint = new GMarker(hallwardsLocation, {title:"Hallward's House", icon:icon});
		map.addOverlay(hallwardsPoint);
		
		var hallwardsPointTabs = new Array(2);
		hallwardsPointTabs[0] = new GInfoWindowTab("details", "<p><b>Hallward's House</b></p><p>30 College Road<br />Clifton<br />Bristol<br />BS8 1JQ</p><p><em>0117 315 7410</em></p>");
		hallwardsPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/HallwardsHouse.jpg' /></p>");
		
		addEvents(hallwardsPoint, hallwardsPointTabs);
		
		var northAndEastTownLocation = new GLatLng(51.461267, -2.621615);
		var northAndEastTownPoint = new GMarker(northAndEastTownLocation, {title:"North Town & East Town", icon:icon});
		map.addOverlay(northAndEastTownPoint);
		
		var northAndEastTownPointTabs = new Array(2);
		northAndEastTownPointTabs[0] = new GInfoWindowTab("details", "<p><b>North Town &amp; East Town</b></p><p>28 College Road<br />Clifton<br />Bristol<br />BS8 3JH</p><p><em>0117 315 7351 (North Town)<br />0117 315 7380 (East Town)</em></p>");
		northAndEastTownPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/NorthAndEastTown.jpg' /></p>");
		
		addEvents(northAndEastTownPoint, northAndEastTownPointTabs);
				
		var oakeleysLocation = new GLatLng(51.461011, -2.621525);
		var oakeleysPoint = new GMarker(oakeleysLocation, {title:"Oakeley's House", icon:icon});
		map.addOverlay(oakeleysPoint);
		
		var oakeleysPointTabs = new Array(2);
		oakeleysPointTabs[0] = new GInfoWindowTab("details", "<p><b>Oakeley's House</b></p><p>26 College Road<br />Clifton<br />Bristol<br />BS8 3JF</p><p><em>0117 315 7320</em></p>");
		oakeleysPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/OakeleysHouse.jpg' /></p>");
		
		addEvents(oakeleysPoint, oakeleysPointTabs);
				
		var westTownLocation = new GLatLng(51.460806, -2.621106);
		var westTownPoint = new GMarker(westTownLocation, {title:"West Town", icon:icon});
		map.addOverlay(westTownPoint);
		
		var westTownPointTabs = new Array(2);
		westTownPointTabs[0] = new GInfoWindowTab("details", "<p><b>West Town</b></p><p>24 College Road<br />Clifton<br />Bristol<br />BS8 3HZ</p><p><em>0117 315 7400</em></p>");
		westTownPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/WestTown.jpg' /></p>");

		addEvents(westTownPoint, westTownPointTabs);
		

				
		var schoolHouseLocation = new GLatLng(51.461899, -2.621451);
		var schoolHousePoint = new GMarker(schoolHouseLocation, {title:"School House", icon:icon});
		map.addOverlay(schoolHousePoint);
		
		var schoolHousePointTabs = new Array(2);
		schoolHousePointTabs[0] = new GInfoWindowTab("details", "<p><b>School House</b></p><p>College Road<br />Clifton<br />Bristol<br />BS8 3HY</p><p><em>0117 315 7300</em></p>");
		schoolHousePointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/SchoolHouse.jpg' /></p>");
		
		addEvents(schoolHousePoint, schoolHousePointTabs);
				
		var watsonsLocation = new GLatLng(51.462140, -2.621281);
		var watsonsPoint = new GMarker(watsonsLocation, {title:"Watson's House", icon:icon});
		map.addOverlay(watsonsPoint);
		
		var watsonsPointTabs = new Array(2);
		watsonsPointTabs[0] = new GInfoWindowTab("details", "<p><b>Watson's House</b></p><p>Guthrie Road<br />Clifton<br />Bristol<br />BS8 3ET</p><p><em>0117 315 7340</em></p>");
		watsonsPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/WatsonsHouse.jpg' /></p>");
		
		addEvents(watsonsPoint, watsonsPointTabs);
				
		var southTownLocation = new GLatLng(51.462318, -2.620933);
		var southTownPoint = new GMarker(southTownLocation, {title:"South Town", icon:icon});
		map.addOverlay(southTownPoint);
		
		var southTownPointTabs = new Array(2);
		southTownPointTabs[0] = new GInfoWindowTab("details", "<p><b>South Town</b></p><p>North Quad<br />Guthrie Road<br />Clifton<br />Bristol<br />BS8 3JH</p><p><em>0117 315 7360</em></p>");
		southTownPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/SouthTown.jpg' /></p>");

		addEvents(southTownPoint, southTownPointTabs);
				
		var worcesterLocation = new GLatLng(51.459875, -2.618766);
		var worcesterPoint = new GMarker(worcesterLocation, {title:"Worcester House", icon:icon});
		map.addOverlay(worcesterPoint);
		
		var worcesterPointTabs = new Array(2);
		worcesterPointTabs[0] = new GInfoWindowTab("details", "<p><b>Worcester House</b></p><p>The Coach House<br />College Road<br />Clifton<br />Bristol<br />BS8 3HZ</p><p><em>0117 315 7390</em></p>");
		worcesterPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/WorcesterHouse.jpg' /></p>");
		
		addEvents(worcesterPoint, worcesterPointTabs);
		
		var wisemansLocation = new GLatLng(51.459961, -2.618280);
		var wisemansPoint = new GMarker(wisemansLocation, {title:"Wiseman's House", icon:icon});
		map.addOverlay(wisemansPoint);
		
		var wisemansPointTabs = new Array(2);
		wisemansPointTabs[0] = new GInfoWindowTab("details", "<p><b>Wiseman's House</b></p><p>3 Worcester Road<br />Clifton<br />Bristol<br />BS8 3JL</p><p><em>0117 315 7330</em></p>");
		wisemansPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/WisemansAndCCSL.jpg' /></p>");
		
		addEvents(wisemansPoint, wisemansPointTabs);
				
		var poolesLocation = new GLatLng(51.463162, -2.619671);
		var poolesPoint = new GMarker(poolesLocation, {title:"Poole's House", icon:icon});
		map.addOverlay(poolesPoint);
		
		var poolesPointTabs = new Array(2);
		poolesPointTabs[0] = new GInfoWindowTab("details", "<p><b>Poole's House</b></p><p>Guthrie Road<br />Clifton<br />Bristol<br />BS8 3EZ</p><p><em>0117 315 7550</em></p>");
		poolesPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/PoolesHouse.jpg' /></p>");
		
		addEvents(poolesPoint, poolesPointTabs);
		
		var guthrieLocation = new GLatLng(51.463254, -2.619389);
		var guthriePoint = new GMarker(guthrieLocation, {title:"Guthrie House", icon:icon});
		map.addOverlay(guthriePoint);
		
		var guthriePointTabs = new Array(2);
		guthriePointTabs[0] = new GInfoWindowTab("details", "<p><b>Guthrie House</b></p><p>Guthrie Road<br>Clifton<br />Bristol<br />BS8 3HE</p><p><em>0117 315 7531</em><br /></p>");
		guthriePointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/GuthrieHouse.jpg' /></p>");
		
		addEvents(guthriePoint, guthriePointTabs);
		
		var hartnellsLocation = new GLatLng(51.464266, -2.620069);
		var hartnellsPoint = new GMarker(hartnellsLocation, {title:"Hartnell's House", icon:icon});
		map.addOverlay(hartnellsPoint);
		
		var hartnellsPointTabs = new Array(2);
		hartnellsPointTabs[0] = new GInfoWindowTab("details", "<p><b>Hartnell's House</b></p><p>12 The Avenue<br />Clifton<br />Bristol<br />BS8 3HF</p><p><em>0117 315 7520 / 527</em><br /><br /><br /></p>");
		hartnellsPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/HartnellsHouse.jpg' /></p>");
		
		addEvents(hartnellsPoint, hartnellsPointTabs);
				
		var wollastonsAndTaitsLocation = new GLatLng(51.464742, -2.621264);
		var wollastonsAndTaitsPoint = new GMarker(wollastonsAndTaitsLocation, {title:"Wollaston's and Tait's", icon:icon});
		map.addOverlay(wollastonsAndTaitsPoint);
		
		var wollastonsAndTaitsPointTabs = new Array(2);
		wollastonsAndTaitsPointTabs[0] = new GInfoWindowTab("details", "<p><b>Wollaston's and Tait's</b></p><p>The Avenue<br />Clifton<br />Bristol<br />BS8 3HE</p><p><em>0117 315 7583</em></p>");
		wollastonsAndTaitsPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/WoolastonsAndTaits.jpg' /></p>");
		
		addEvents(wollastonsAndTaitsPoint, wollastonsAndTaitsPointTabs);
				
		var hankeysLocation = new GLatLng(51.463617, -2.618437);
		var hankeysPoint = new GMarker(hankeysLocation, {title:"Hankey's House", icon:icon});
		map.addOverlay(hankeysPoint);
		
		var hankeysPointTabs = new Array(2);
		hankeysPointTabs[0] = new GInfoWindowTab("details", "<p><b>Hankey's House</b></p><p>4 Guthrie Road<br />Clifton<br />Bristol<br />BS8 3EZ</p><p><em>0117 970 6697</em></p>");
		hankeysPointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/HankeysHouse.jpg' /></p>");
		
		addEvents(hankeysPoint, hankeysPointTabs);
		
		var northTownPreLocation = new GLatLng(51.464655, -2.619492);
		var northTownPrePoint = new GMarker(northTownPreLocation, {title:"North Town (Pre)", icon:icon});
		map.addOverlay(northTownPrePoint);
		
		var northTownPrePointTabs = new Array(2);
		northTownPrePointTabs[0] = new GInfoWindowTab("details", "<p><b>North Town (Pre)</b></p><p>The Avenue<br />Clifton<br />Bristol<br />BS8 3HE</p><p><em>0117 315 7540</em></p>");
		northTownPrePointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/NorthTownPre.jpg' /></p>");
		
		addEvents(northTownPrePoint, northTownPrePointTabs);
		
		var southTownPreLocation = new GLatLng(51.464777, -2.619614);
		var southTownPrePoint = new GMarker(southTownPreLocation, {title:"South Town (Pre)", icon:icon});
		map.addOverlay(southTownPrePoint);
		
		var southTownPrePointTabs = new Array(2);
		southTownPrePointTabs[0] = new GInfoWindowTab("details", "<p><b>South Town (Pre)</b></p><p>The Avenue<br />Clifton<br />Bristol<br />BS8 3HE</p><p><em>0117 315 7560</em></p>");
		southTownPrePointTabs[1] = new GInfoWindowTab("image", "<p><img src='/map/images/SouthTownPre.jpg' /></p>");
		
		addEvents(southTownPrePoint, southTownPrePointTabs);
	}
	
	function addRouteToBB()
	{
		var points = [new GLatLng(51.461750, -2.621662), new GLatLng(51.461059, -2.620952), new GLatLng(51.459156, -2.618825), new GLatLng(51.458248, -2.618321), new GLatLng(51.458080, -2.619223), new GLatLng(51.457884, -2.620093), new GLatLng(51.457802, -2.620478), new GLatLng(51.456892, -2.620062), new GLatLng(51.456729, -2.619964), new GLatLng(51.456676, -2.620172), new GLatLng(51.456619, -2.620813), new GLatLng(51.456468, -2.621839), new GLatLng(51.456081, -2.623344), new GLatLng(51.455942, -2.624169), new GLatLng(51.455944, -2.624651), new GLatLng(51.455978, -2.625163), new GLatLng(51.455944, -2.625357), new GLatLng(51.453811, -2.630615), new GLatLng(51.453499, -2.630840), new GLatLng(51.453241, -2.631037), new GLatLng(51.452958, -2.631448), new GLatLng(51.452881, -2.631668), new GLatLng(51.451683, -2.636888), new GLatLng(51.451752, -2.637403), new GLatLng(51.451905, -2.637968), new GLatLng(51.456622, -2.649154), new GLatLng(51.456375, -2.649371), new GLatLng(51.456302, -2.649476), new GLatLng(51.456262, -2.649941)];

		map.addOverlay(new GPolyline(points));
	}
	
	function zoomToLocation(location)
	{
		var toLocation;		
		var fromLocation = map.getCenter();
		var zoomLevel = map.getZoom();
		 
		/*closes the currently opened info window (if any) before relocating to another point in the map*/
		map.closeInfoWindow();
		var routeToBB = document.getElementById("RouteToBB");
		var routeToCC = document.getElementById("RouteToCC");
		routeToBB.style.display = "none";
		routeToCC.style.display = "none";
		
		var directions = document.getElementById("directionsDiv");
		
		if(location == "reset")
		{
			zoomLevel = 16;
			toLocation = new GLatLng(51.462, -2.620);
			if(currentView == "mainBuildings")
			{
				routeToBB.style.display = "inline";		
			}
		}
		else if(location == "upper school")
		{
			if(map.getZoom() != 18)
			{
				zoomLevel = 18;
			}
			toLocation = new GLatLng(51.462161, -2.620699);
			routeToBB.style.display = "inline";
		}
		else if(location == "prep school")
		{	
			if(map.getZoom() != 18)
			{
				zoomLevel = 18;
			}
			toLocation = new GLatLng(51.464255, -2.620458);	
		}
		else if(location == "butcombe")
		{
			if(map.getZoom() != 18)
			{
				zoomLevel = 18;
			}
			toLocation = new GLatLng(51.463575, -2.618523);
		}
		else if(location == "reception")
		{
			if(map.getZoom() != 18)
			{
				zoomLevel = 18;
			}
			toLocation = new GLatLng(51.461593, -2.621998);
			routeToBB.style.display = "inline";
		}
		else if(location == "ccsl")
		{
			if(map.getZoom() != 18)
			{
				zoomLevel = 18;
			}
			toLocation = new GLatLng(51.459963, -2.618185);
			routeToBB.style.display = "inline";
		}
		else if(location == "theatre")
		{
			if(map.getZoom() != 18)
			{
				zoomLevel = 18;
			}
			toLocation = new GLatLng(51.460160, -2.621996);
		}
		else if(location == "sports ground")
		{
			if(map.getZoom() != 17)
			{
				zoomLevel = 17;
			}
			toLocation = new GLatLng(51.455598, -2.650131);
			routeToCC.style.display = "inline";	
		}
		else if(location == "route to BB")
		{
			if(map.getZoom() != 17)
			{
				zoomLevel = 17;
			}
			toLocation = new GLatLng(51.455598, -2.650131);
		}
		else if(location == "route to CC")
		{
			if(map.getZoom() != 17)
			{
				zoomLevel = 17;
			}
			toLocation = new GLatLng(51.461593, -2.621998);
		}
		else if(location == "moberlysHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.461742, -2.622186);
		}
		else if(location == "hallwardsHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.461416, -2.621784);
		}
		else if(location == "northAndEastTown")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.461267, -2.621615);
		}
		else if(location == "oakeleysHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.461011, -2.621525);
		}
		else if(location == "westTown")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.460806, -2.621106);
		}
		else if(location == "schoolHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.461899, -2.621451);
		}
		else if(location == "watsonsHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.462140, -2.621281);
		}
		else if(location == "southTown")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.462318, -2.620933);
		}
		else if(location == "worcesterHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.459875, -2.618766);
		}
		else if(location == "wisemansHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.459961, -2.618280);
		}
		else if(location == "poolesHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.463162, -2.619671);
		}
		else if(location == "guthrieHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.463254, -2.619389);
		}
		else if(location == "hartnellsHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.464266, -2.620069);
		}
		else if(location == "wollastonsAndTaits")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.464742, -2.621264);
		}
		else if(location == "hankeysHouse")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.463617, -2.618437);
		}
		else if(location == "northTownPre")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.464655, -2.619492);
		}
		else if(location == "southTownPre")
		{
			if(map.getZoom() != 19)
			{
				zoomLevel = 19;
			}
			toLocation = new GLatLng(51.464777, -2.619614);
		}
		
		/*pans from the current to the new location*/
		var reachedDestination = false;
		if((location != "route to BB") && (location != "route to CC"))
		{
			/*NEED SOME WAY HERE TO DETERMINE WHETHER THE TOLOCATION IS WITHIN SMOOTH PANNING DISTANCE OR NOT*/
			map.setZoom(zoomLevel);
			map.panTo(toLocation);
		}
			/*while(!reachedDestination)
			{
				if((map.getBounds()).contains(toLocation))
				{
					map.panTo(toLocation);
					reachedDestination = true;
				}
				else
				{
					var midPoint = new GLatLng(((fromLocation.lat() + toLocation.lat()) / 2), 
											   ((fromLocation.lng() + toLocation.lng()) / 2));
					map.panTo(midPoint);
					fromLocation = midPoint;
					/*pan to the new location via midway points which are in the maps bounds*/
		/*		}
			}
		}*/
		else if(location == "route to BB")
		{	
			directions.style.display = "none";
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.461593, -2.621998));
			}, 1000);
			map.setZoom(17);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.459779, -2.619542));
			}, 2000);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.458243, -2.618354));
			}, 2900);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.457794, -2.620430));
			}, 3800);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.456771, -2.620065));
			}, 4700);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.456096, -2.623426));
			}, 5600);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.455403, -2.626669));
			}, 6500);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.454922, -2.627851));
			}, 7400);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.454157, -2.629823));
			}, 8300);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452508, -2.633486));
			}, 9200);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452096, -2.635185));
			}, 10100);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452496, -2.639420));
			}, 11000);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452877, -2.640264));
			}, 11900);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.454318, -2.643691));
			}, 12800);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.455860, -2.647213));
			}, 13700);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.455598, -2.650131));
			}, 14600);
			window.setTimeout(function()
			{
				routeToCC.style.display = "inline";
				directions.style.display = "block";
			}, 15500);
		}
		else if(location == "route to CC")
		{
			directions.style.display = "none";
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.455598, -2.650131));
			}, 1000);
			map.setZoom(17);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.455860, -2.647213));
			}, 2000);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.454318, -2.643691));
			}, 2900);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452877, -2.640264));
			}, 3800);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452496, -2.639420));
			}, 4700);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452096, -2.635185));
			}, 5600);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.452508, -2.633486));
			}, 6500);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.454157, -2.629823));
			}, 7400);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.454922, -2.627851));
			}, 8300);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.455403, -2.626669));
			}, 9200);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.456096, -2.623426));
			}, 10100);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.456771, -2.620065));
			}, 11000);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.457794, -2.620430));
			}, 11900);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.458243, -2.618354));
			}, 12800);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.459779, -2.619542));
			}, 13700);
			window.setTimeout(function() 
			{
				map.panTo(new GLatLng(51.461593, -2.621998));
			}, 14600);
			window.setTimeout(function()
			{
				routeToBB.style.display = "inline";
				directions.style.display = "block";
			}, 15500);
		}
		//map.setZoom(zoomLevel);
	}
