//add the location of the GMap generator
var mapControlsLocation = "http://maps.metrolandwest.com/";

var map; 


function mapPrepare(Latitude, Longitude, Zoom, zoomControls, brand, normal, satellite, hybrid, terrain, mapType, itemTitleHTML) {
		//<![CDATA[
		function load() {
			if (google.maps.BrowserIsCompatible()) {	
				test=document.getElementById("map");
				map=new google.maps.Map2(test); 
				map.setCenter(new google.maps.LatLng(Latitude,Longitude),Zoom);
				addControls(zoomControls, brand, normal, satellite, hybrid, terrain, itemTitleHTML);
				setMapType2(mapType);
				addPoints();
			} 
		}
				  //]]>
	function addLoadEvent(A){var B=window.onload;if(typeof window.onload!="function"){window.onload=A}else{window.onload=function(){if(B){B()}A()}}}addLoadEvent(load);if(window.attachEvent){window.attachEvent("onunload",function(){GUnload()})}else{window.addEventListener("unload",function(){GUnload()},false)};
 }
 
 function addControls(zoom, brand, normal, satellite, hybrid, terrain, itemTitleHTML) {

//CREATE ELEMENTS
	//creates item title
 	  var itemTitle = function(html) {
					this.html_ = "<span>" + html + "</span>";
				};
	itemTitle.prototype = new google.maps.Control();
	itemTitle.prototype.initialize = function(map) {
					var container = document.createElement("div");
					container.innerHTML = this.html_;
					container.style.fontFamily='Arial, Helvetica, sans-serif';
					container.style.fontSize='x-large';
					container.style.fontWeight='bold';
					//container.style.color='#3DB403';
					//container.style.height='37px';
					//url = this.url_;
					map.getContainer().appendChild(container);
					return container;
				};
	itemTitle.prototype.getDefaultPosition = function() {
				return new google.maps.ControlPosition(G_ANCHOR_TOP_LEFT, new google.maps.Size(35, 10));
				};
	map.addControl(new itemTitle(itemTitleHTML));


		//creates custom zoom-in/zoom-out
		if (zoom==true) {
				function SpecZoomControl() {}
				
				// To "subclass" the GControl, we set the prototype object to an instance of the GControl object
				SpecZoomControl.prototype = new google.maps.Control();
				
				// Places the icons in their own divs, in a container div. We add the control to
				// to the map container and return the element for the map class to
				// position properly.
				SpecZoomControl.prototype.initialize = function(map) {
				  var container = document.createElement("div");
				
				  var zoomInDiv = document.createElement("div");
				  this.setButtonStyle_(zoomInDiv);
				  container.appendChild(zoomInDiv);
				  zoomInDiv.innerHTML = '<img src="'+mapControlsLocation+'Images/zoom-in.png" border="0">';
				  google.maps.Event.addDomListener(zoomInDiv, "click", function() {
					map.zoomIn();
					//if(document.getElementById("zoomSelect")){document.getElementById("zoomSelect").value=map.getZoom()};
				  });
				  var zoomOutDiv = document.createElement("div");
				  this.setButtonStyle_(zoomOutDiv);
				  container.appendChild(zoomOutDiv);
				  zoomOutDiv.innerHTML = '<img src="'+mapControlsLocation+'Images/zoom-out.png" border="0">';
				  google.maps.Event.addDomListener(zoomOutDiv, "click", function() {
					map.zoomOut();
					//if(document.getElementById("zoomSelect")){document.getElementById("zoomSelect").value=map.getZoom()};
				  });
				  map.getContainer().appendChild(container);
				  return container;
				}
				
				// By default, the control will appear in the top left corner of the
				// map with 7 pixels of padding.
				SpecZoomControl.prototype.getDefaultPosition = function() {
				  return new google.maps.ControlPosition(G_ANCHOR_TOP_LEFT, new google.maps.Size(7, 7));
				}
				
				// Sets the proper CSS for the given button element.
				SpecZoomControl.prototype.setButtonStyle_ = function(button) {
				  button.style.marginBottom = "3px";
				  button.style.width = "23px";
				  button.style.height = "23px";
				  button.style.cursor = "pointer";
				}
				
				//adds the element
				map.addControl(new SpecZoomControl());	
		}
		
		
		//creates the Spec.com branding
		if (brand==true) {
				var SpecName = function(url) {
					this.url_ = url;
					};
				SpecName.prototype = new google.maps.Control(true);
					
					
				SpecName.prototype.initialize = function(map) {
					var container = document.createElement("div");
					container.innerHTML = '<img style="width:171px;height:37px" src="'+mapControlsLocation+'Images/the-spec-logo.png" border="0">';
					url = this.url_;
					google.maps.Event.addDomListener(container, "click", function() {
					document.location = url;
					});
					map.getContainer().appendChild(container);
					return container;
				};
				
				SpecName.prototype.getDefaultPosition = function() {
				return new google.maps.ControlPosition(G_ANCHOR_BOTTOM_LEFT, new google.maps.Size(70, 0));
				};
				
				
			map.addControl(new SpecName('http://www.thespec.com'));			
		}		
		
		
		//creates custom type controls
			function SpecTypeControl() {
			}
			
			// To "subclass" the GControl, we set the prototype object to an instance of the GControl object
			SpecTypeControl.prototype = new google.maps.Control();
			
			// Places the icons in their own divs, in a container div.
			SpecTypeControl.prototype.initialize = function(map) {
			var container = document.createElement("div");
		
		if (normal==true) {
					  var normalTypeDiv = document.createElement("div");
					  this.setButtonStyle_(normalTypeDiv);
					  container.appendChild(normalTypeDiv);
					   normalTypeDiv.innerHTML = '<img src="'+mapControlsLocation+'Images/map-icon.gif" border="0">';
					  google.maps.Event.addDomListener(normalTypeDiv, "click", function() {
						map.setMapType(G_NORMAL_MAP);
					  });
			}  
		if (satellite==true) {
					  var satelliteTypeDiv = document.createElement("div");
					  this.setButtonStyle_(satelliteTypeDiv);
					  container.appendChild(satelliteTypeDiv);
					  satelliteTypeDiv.innerHTML = '<img src="'+mapControlsLocation+'Images/satellite-icon.gif" border="0">';
					  google.maps.Event.addDomListener(satelliteTypeDiv, "click", function() {
						map.setMapType(G_SATELLITE_MAP);
					  });
		   }
		if (hybrid==true) {		  
					  var hybridTypeDiv = document.createElement("div");
					  this.setButtonStyle_(hybridTypeDiv);
					  container.appendChild(hybridTypeDiv);
					  hybridTypeDiv.innerHTML = '<img src="'+mapControlsLocation+'Images/hybrid-icon.gif" border="0">';
					  google.maps.Event.addDomListener(hybridTypeDiv, "click", function() {
						map.setMapType(G_HYBRID_MAP);
					  });
			}
		if (terrain==true) {	
					  var terrainTypeDiv = document.createElement("div");
					  this.setButtonStyle_(terrainTypeDiv);
					  container.appendChild(terrainTypeDiv);
					  terrainTypeDiv.innerHTML = '<img src="'+mapControlsLocation+'Images/terrain-icon.gif" border="0">';
					  google.maps.Event.addDomListener(terrainTypeDiv, "click", function() {
						map.setMapType(G_PHYSICAL_MAP);
					  });
		   }
				
				  map.getContainer().appendChild(container);
				  return container;
				}
				
				// Postions the control
				SpecTypeControl.prototype.getDefaultPosition = function() {
				  return new google.maps.ControlPosition(G_ANCHOR_TOP_RIGHT, new google.maps.Size(7, 7));
				}
				
				// Sets the proper CSS for the given button element.
				SpecTypeControl.prototype.setButtonStyle_ = function(button) {
				  button.style.marginTop = "3px";
				  button.style.width = "77px";
				  button.style.height = "20px";
				  button.style.cursor = "pointer";
				}
	
	//map.addControl (new google.maps.OverviewMapControl());
	//if (document.mainForm.specBranding.checked=="true") {
		map.addControl(new SpecTypeControl());	
	//}
 }

function setMapType2(selectedMapType) {
		if (selectedMapType=="normal") {
				map.setMapType(G_NORMAL_MAP);
		} else if (selectedMapType=="satellite") {
				map.setMapType(G_SATELLITE_MAP);
		} else if (selectedMapType=="hybrid") {
				map.setMapType(G_HYBRID_MAP);
		} else if (selectedMapType=="terrain") {
				map.setMapType(G_PHYSICAL_MAP);
		}
 }
  
   	//CREATES MARKERS
function addMarkerLatLng (lat, long1, title, desc) {
	var point1 = new google.maps.LatLng(lat, long1);
	addMarker (point1, title, desc);}
function addMarker (point1, title, desc) {
	var marker1 = new google.maps.Marker(point1);
		var infoWindowHTML = document.createElement ("div");
		
		if (title) {
			infoWindowHTML.innerHTML = '<h3>'+unescape(title)+'</h3>'
		}
		if (desc) {	
		desc=desc.replace(/\n/gi, '<br/>');
			infoWindowHTML.innerHTML = infoWindowHTML.innerHTML + '<div style="width:230px;max-height:158px;overflow-y:auto;padding:5px">'+unescape(desc)+'</div>';
			google.maps.Event.addListener(marker1, 'click',function() {marker1.openInfoWindowHtml(infoWindowHTML)});
		} else if (!desc) {
			if (title) {
				google.maps.Event.addListener(marker1, 'click',function() {marker1.openInfoWindowHtml(infoWindowHTML)});
			}	
		}
	map.addOverlay(marker1);
	}