	var map;
	var gdir;
	var geocoder = null;
	var addressMarker;
	
	//Pasadena coordinates
	var CPasadena = {
		coord:new GLatLng(34.149019, -118.139904),
		name: "Pasadena Campus",
		address: "135 N. Oakland Ave.<br />Pasadena, CA 91182",
		image:"fuller.jpg",
		route: "135 N.Oakland Ave., Pasadena, CA 91182"
	};
	
	//Pasadena coordinates
	var CAdmissions = {
		coord:new GLatLng(34.150342, -118.138453),
		name: "Admissions Office Pasadena",
		address: "(Student Services Building)<br />250 N. Madison Ave.,<br />Pasadena, CA 91182",
		image:"fuller.jpg",
		route: "250 N. Madison Ave., Pasadena, CA 91182"
	};
	
	//California Coast coordinates
	var CCaliforniaCoast = {
		coord:new GLatLng(33.678119, -117.858389),
		name: "California Coast Campus",
		address: "2061 Business Center Drs.<br />Irvine, CA 92612",
		image:"fuller.jpg",
		route: "2061 Business Center Dr,.Irvine, CA 92612"
	};
	
	//Colorado coordinates
	var CColorado = {
		coord:new GLatLng(38.841423, -104.824730),
		name: "Colorado Campus",
		address: "540 N. Cascade Ave.<br />Colorado Springs, CO 80903",
		image:"fuller.jpg",
		route:"540 N. Cascade Ave., Colorado Springs, CO 80903"
	};
	
	//Northern California coordinates
	var CNorthernCalifornia = {
		coord:new GLatLng(37.456238, -122.167475),
		name: "Northern California Campus",
		address: "320 Middlefield Road<br />Menlo Park, CA 94026",
		image:"fuller.jpg",
		route:"320 Middlefield Road, Menlo Park, CA 94026"
	};
	
	//Northwest coordinates
	var CNorthwest = {
		coord:new GLatLng(47.650123, -122.358045),
		name: "Northwest Campus",
		address: "101 Nickerson St.<br />Seattle, WA 98109",
		image:"fuller.jpg",
		route: "101 Nickerson St., Seattle, WA 98109"
	};
	
	//Southwest coordinates
	var CSouthwest = {
		coord:new GLatLng(33.451149, -111.981039),
		name: "Southwest Campus",
		address: "4646 E. Van Buren St.<br />Phoenix, AZ 85008",
		image:"fuller.jpg",
		route: "4646 E. Van Buren St., Phoenix, AZ 85008"
	};
	
	//Texas coordinates
	var CTexas = {
		coord:new GLatLng(29.784004, -95.593971),
		name: "Texas Campus",
		address: "11757 Katy Freeway<br />Houston, TX 77079",
		image:"fuller.jpg",
		route: "11757 Katy Freeway, Houston, TX 77079"
	};

	var campuses = [CPasadena, CAdmissions, CCaliforniaCoast, CColorado, CNorthernCalifornia, CNorthwest, CSouthwest, CTexas];

	var iniCoord = new GLatLng(40, -105);
	var iniZoom = 4;
	var campusZoom = 16;
	
	var url = window.location.href;
	var qparts = url.split("=");
	var camp = qparts[1];
	var camp = parseInt(camp);
	if (camp > 0) {
		camp = camp+1;
	}
	if (camp || camp==0) {
		var iniCoord = campuses[camp].coord;
		var iniZoom = campusZoom;
	}
	
	//Directions
	function setDirections(fromAddress, toAddress) {
		gdir.load('from: ' + fromAddress + ' to: ' + toAddress);
		document.getElementById("cleardir").style.display = "block";
		document.getElementById("printdir").style.display = "block";
	}
	

    function initialize() {		
		
		//Adding campus buttons
		
		function MDControl() { }
		MDControl.prototype = new GControl();
		MDControl.prototype.initialize = function(map) {
			var container = document.createElement("div");
			
			//creating toggle button
			var buttonToggle = document.createElement("div")
			buttonToggle.className = "MDbuttons";
			buttonToggle.title = "Hide Campus List";
			buttonToggle.id = "bToggle";
			buttonToggle.style.background = "#DDD";
			container.appendChild(buttonToggle);
			buttonToggle.appendChild(document.createTextNode("Hide Campus List"));
			GEvent.addDomListener(buttonToggle, "click", toggleMenu);
			
			//creating list of buttons holder
			var list = document.createElement("div")
			container.appendChild(list);
			list.id = "campus_menu";
			list.style.display = "block";
			
			var iniZoom = campusZoom;
			
			
			
			function getCallback(map, coord){
				return (function() {
					map.setZoom(campusZoom);
					map.panTo(coord);
					});
			}

			
			//Creating buttons
			for(var i=0; i<campuses.length; i++){
				var map_button = document.createElement("div");
				map_button.title = "Go to the " + campuses[i].name;
				map_button.className = "MDbuttons";
				list.appendChild(map_button);
				map_button.appendChild(document.createTextNode(campuses[i].name));
				GEvent.addDomListener(map_button, "click", getCallback(map, campuses[i].coord));
			}
			
			//Back to main menu button
			var mainmap_button = document.createElement("div");
			mainmap_button.title = "Back to main map";
			mainmap_button.className = "MDbuttons";
			list.appendChild(mainmap_button);
			mainmap_button.appendChild(document.createTextNode("Main Map"));
			GEvent.addDomListener(mainmap_button, "click", function() {map.setZoom(4); map.panTo(iniCoord)});
			
			map.getContainer().appendChild(container);
			return container;
		}

		MDControl.prototype.getDefaultPosition = function() {
			return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7,31));
		}
	
	
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map_canvas"));
			gdir = new GDirections(map, document.getElementById("directions"));
			
			map.setCenter(iniCoord, iniZoom);
			map.enableContinuousZoom();
			map.enableScrollWheelZoom();
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new MDControl());
			GEvent.addListener(gdir, "error", handleErrors);
			
			
			// Create the marker and corresponding information window
			function createInfoMarker(point, content) {
				var marker = new GMarker(point);
				GEvent.addListener(marker, "click",
				function() {
					marker.openInfoWindowHtml(content);
				}
				);
				return marker;
			}
			
			//Display all the markers on the map
			for(var i=0; i<campuses.length; i++){
				var content = '<div id="info" style="width:275px; height:100px">' +
							   '<b>' + campuses[i].name + '</b><br />' +
							   campuses[i].address + '<br /><br />' +
							   '<div><b>Get directions: </b><a id="linkFrom" href="javascript:toggleFrom();">From</a> - <a id="linkTo" href="javascript:toggleTo();">To</a><br />' +
							   
							   //Form Directions "from" hidden
							   '<div style="display:none" id="fromBlock"><form name="fromform" action="javascript:setDirections(document.fromform.from.value, document.fromform.to.value);">' +
							   '<input type="text" size="30" id="from" name="from" />' +
							   '<input type="hidden" name="to" id="to" value="' + campuses[i].route + '" />' +
							   '</form></div>' +
							   
							   //Form Directions "to" hidden
							   '<div style="display:none" id="toBlock"><form name="toform" action="javascript:setDirections(document.toform.from.value, document.toform.to.value);">' +
							   '<input type="text" size="30" id="to" name="to" />' +
							   '<input type="hidden" name="from" id="from" value="' + campuses[i].route + '" />' +
							   '</form></div>' +
							   
							   '</div></div>';		
							   
				var marker = createInfoMarker(campuses[i].coord, content);
				map.addOverlay(marker);
			}

      
		}
	

	
		function handleErrors(){
			if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
				alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
			}
		
			else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) {
				alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
			}
			else if (gdir.getStatus().code == G_GEO_MISSING_QUERY){
				alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
			}
			else if (gdir.getStatus().code == G_GEO_BAD_KEY) {
				alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
			}
			else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) {
				alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
			}
			else alert("An unknown error occurred.");
	   
		}
	
	
			
	
	}
		
		
	//toggling the campus list on the map
	function toggleMenu() {
		var menu = document.getElementById("campus_menu");
		var toggle = document.getElementById("bToggle");
				
		if (menu.style.display == "block") {
			menu.style.display = "none";
			toggle.innerHTML = "Show Campus List";
			toggle.title = "Show Campus List";
		}
			
		else if (menu.style.display == "none") {
			menu.style.display = "block";
			toggle.innerHTML = "Hide Campus List";
			toggle.title = "Hide Campus List";
		}
	}
			
			
	//Toggling to and from directions
	function toggleTo() {
		var blockF = document.getElementById("fromBlock");
		var blockT = document.getElementById("toBlock");
		var linkF = document.getElementById("linkFrom");
		var linkT = document.getElementById("linkTo");
		var bubble = document.getElementById("info");
		
		linkT.style.color = "black";
		linkT.style.textDecoration = "none";
		linkT.style.cursor = "default";
		linkT.style.fontWeight = "bold";
		blockT.style.display = "block";
			
		linkF.style.color ="blue"
		linkF.style.textDecoration = "underline";
		linkF.style.cursor = "pointer";
		linkF.style.fontWeight = "normal";
		blockF.style.display = "none";
	}
		
	function toggleFrom() {
		var blockF = document.getElementById("fromBlock");
		var blockT = document.getElementById("toBlock");
		var linkF = document.getElementById("linkFrom");
		var linkT = document.getElementById("linkTo");
		var bubble = document.getElementById("info");
			
		linkF.style.color = "black";
		linkF.style.textDecoration = "none";
		linkF.style.cursor = "default";
		linkF.style.fontWeight = "bold";
		blockF.style.display = "block";
			
		linkT.style.color ="blue"
		linkT.style.textDecoration = "underline";
		linkT.style.cursor = "pointer";
		linkT.style.fontWeight = "normal";
		blockT.style.display = "none";
	}
	
	//Print and clear direction links toggle
	
	function clearDirections() {
		gdir.clear();
		document.getElementById("cleardir").style.display = "none";
		document.getElementById("printdir").style.display = "none";
	}
