﻿/// <reference path="VeJavaScriptIntellisenseHelper.js" />
Type.registerNamespace("vdot");

vdot.Map = function(service, mapArgs) {
	/// <summary>
	///   The VE Map.
	///   Supports load on demand
	/// </summary>
	/// <param name="service">The webservice to call for the map data.</param>
	/// <param name="mapArgs">The map initalisation data.</param>

	this._service = service;

	this._mapArgs = mapArgs;

	var currDate = new Date();
	this._map = null;
	this._pinID = 0;
	this._zoomlevel = 0;
	this._layer = null;
	this._showTile = true;
	this._disabled = false;
	this._disabledMessage = "";
	this._filters = "";
	this._eventDate = (currDate.getMonth()+1) & "/" + currDate.getDate() + "/" + currDate.getFullYear(); // +"T" + currDate.toTimeString();
	this._cameraLayer = null;
	this._tileLayer = null;
	
	//popup specific
	this._PopupPrefix = "POPUP";
	this._currentpin = null;
	this._currentindex = 0;
	this._processType = null;

	this.GetPinDataDelegate = null;
	this.PinHoverDelegate = null;
	this.PinClickDelegate = null;
	this.ZoomChangeDelegate = null;
	this.mouseDoubleClickDelegate = null;


	this.timerRefCameraShutoffPop = null;
	this.cameraShutoffMilliSecondsPop = 20 * 1000;
	this.cameraShutoffPop = true;
	this._currentCameras = null;
	this._totalCameras = 0;
	this._currentCamera = 0;
	this._cameraIncrement = 50;
	this._cameraTimeInterval = .1 * 1000;
	this._cameraInterval = null;

	this._MaxMapZoomLevel = 14;
	this._MinMapZoomLevel = 7;

	//Trip planning items
	this._isTripPlanning = false;

	this._refreshTime = 120 * 1000;
	this._refreshInterval = null;

	this._init();
}

vdot.Map.prototype = {

	_init: function() {
		/// <summary>
		///   Initialises the Map.
		/// </summary>       

		//setup map
		this._map = new VEMap(this._mapArgs.DivID);

		this._filters = this._mapArgs.filters;

		if (this._mapArgs.eventDate != "") {
			this._eventDate = this._mapArgs.eventDate;

		}
		this._map.HideDashboard();
		this._map.LoadMap(this._mapArgs.Center, this._mapArgs.Zoomlevel, this._mapArgs.Style, this._mapArgs.Fixed, this._mapArgs.Mode);
		this._map.SetScaleBarDistanceUnit(this._mapArgs.Scale);


		// Add base layers for showing items
		this._cameraLayer = new VEShapeLayer();
		this._cameraLayer.SetTitle("CameraLayer");

		this._tileLayer = new VEShapeLayer();
		this._tileLayer.SetTitle("TileLayer");

		this._layer = new VEShapeLayer();
		this._layer.SetTitle("EventLayer");

		this._showTile = this._mapArgs.showWeatherTile;
		//Order is controlling layer depth.
		this._map.AddShapeLayer(this._cameraLayer);
		this._map.AddShapeLayer(this._layer);
		this._map.AddShapeLayer(this._tileLayer);

		//Setup additional storage for shapes
		VEShape.prototype.Bounds = "";
		VEShape.prototype.vdotType = 'none';
		VEShape.prototype.cid = "";

		this.ZoomChangeDelegate = Function.createDelegate(this, this._ZoomChange);
		this._map.AttachEvent("onmousewheel", this.ZoomChangeDelegate);

		this.mouseDoubleClickDelegate = Function.createDelegate(this, this._MouseDoubleClick);
		this._map.AttachEvent("ondoubleclick", this.mouseDoubleClickDelegate);

		this._refreshInterval = setInterval(Function.createDelegate(this, this._GetPinData), this._refreshTime);
		//setup the function to get new data whenever the map changes
		//If the feeds are processing and available set the system up
		if (this._mapArgs.CurrentStatus == "success") {
			this.GetPinDataDelegate = Function.createDelegate(this, this._GetPinData);
			this._map.AttachEvent("onchangeview", this.GetPinDataDelegate);

			//turn off the standard popup and attach our custom handler
			this.PinHoverDelegate = Function.createDelegate(this, this._PinHover);
			this._map.AttachEvent("onmouseover", this.PinHoverDelegate);

			this.PinClickDelegate = Function.createDelegate(this, this._PinActivate);
			this._map.AttachEvent("onclick", this.PinClickDelegate);

			if (this._mapArgs.type != "editroutes") {
				this._processType = "popup";
			} else {
				this._processType = "popupSelect";
			}

			if (this._mapArgs.type == "tripplanning") {
				this._isTripPlanning = true;
			}

			if (this._filters.indexOf("camera") >= 0) {
				this._getCameraLayer();
			}

			//get the data for the default view
			if (this._showTile) {
				this._getRoadTile();
			}
		}

	},

	_GetPinData: function() {
		/// <summary>
		///   Get the latest map data from the webservice.
		/// </summary>

		//encode the current map bounds
		var points = new Array();
		var zoom;

		if (this._map.GetMapStyle() == VEMapStyle.Birdseye) {
			//set zoomlevel      
			zoom = 19;
			var be = this._map.GetBirdseyeScene();
			var rect = be.GetBoundingRectangle();
			points.push(rect.TopLeftLatLong);
			points.push(rect.BottomRightLatLong);

		} else {
			var view = this._map.GetMapView();
			points.push(view.TopLeftLatLong);
			points.push(view.BottomRightLatLong);

			//get zoomlevel
			zoom = this._map.GetZoomLevel();

		}
		var bounds = Utility.createEncodings(points);
		if (this._zoomlevel != zoom) {
			//clear existing pins
			this._layer.DeleteAllShapes();
			this._zoomlevel = zoom;
		}

		//call webservice
		if (this._mapArgs.CurrentStatus == "success") {
			this._service.GetClusteredMapData(bounds, zoom, this._filters, this._eventDate, Function.createDelegate(this, this._OnMapDataSucceeded), Utility.OnFailed);
		}
	},

	_OnMapDataSucceeded: function(results) {
		/// <summary>
		///   Receive data for map.
		/// </summary>  
		/// <param name="result">The webservice result object - Optomised CSV string</param>  

		//decode pins
		var result = results.split(",")
		var locs = Utility.decodeLine(result[0]);
		var newShapes = new Array();

		//clear existing pins
		this._layer.DeleteAllShapes();

		//add new pins
		for (x = 0; x < locs.length; x++) {
			var loc = locs[x];
			var bounds = result[x + 1];
			var icon = bounds.split("!")[1];
			bounds = bounds.split("!")[0];

			var newShape = new VEShape(VEShapeType.Pushpin, loc);
			newShape.Bounds = bounds;
			newShape.vdotType = 'incident';
			//set custom png pin, IE6 will require a PNG fix.
			if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version == 6) {
				//newShape.SetCustomIcon("<div class='myPushpinIE6'></div>");
				newShape.SetCustomIcon(icon);
			} else {
				//newShape.SetCustomIcon("<div class='myPushpin'></div>");
				newShape.SetCustomIcon(icon);
			}
			//Push the new shape into an array of shapes
			newShapes.push(newShape);

		}
		//Add the array of shapes to the layer.  This is the new bulk loading of icons instead of loading our old xml
		this._layer.AddShape(newShapes);

		var objImage;

		objImage = $get("img_tog_Incident");
		this._SetToolbarIcon(objImage);
		objImage = $get("img_tog_Event");
		this._SetToolbarIcon(objImage);
		objImage = $get("img_tog_Weather");
		this._SetToolbarIcon(objImage);
		objImage = $get("img_tog_Bridge");
		this._SetToolbarIcon(objImage);
	},

	_SetToolbarIcon: function(objImage) {

		if (BrowserDetect.browser == "Explorer") {

			objImage.src = "Images/VirtualEarth/icon_checkmark.png";

		} else {
			objImage.setAttribute("src", "Images/VirtualEarth/icon_checkmark.png");
		}
	},

	_PinHover: function(e) {
		/// <summary>
		///   Receives any mouse of event from VE
		/// </summary>  
		/// <param name="e">The MapEvent object</param>
		// check to see if we have hovered over a pushpin
		if (e.elementID != null) {
			//mouse is over a pushpin (or over a shape)
			pinref = this._map.GetShapeByID(e.elementID);

			pts = pinref.GetPoints();

			pinTitle = pinref.GetTitle();
			pinDetails = pinref.GetDescription();

			return true;
		}
	},

	_PinActivate: function(e) {
		/// <summary>
		///   Receives any mouse of event from VE
		/// </summary>
		/// <param name="e">The MapEvent object</param>


		if (e.elementID) {
			var s = this._map.GetShapeByID(e.elementID)
			//set current pin
			this._currentpin = s;
			this._currentindex = 0;
			if (s.vdotType == 'camera') {
				this._getCameraInfo(s.cid);
			} else if (s.vdotType == 'incident') {

				if (s) {
					// OLD CODE
					window.ero.setBoundingArea(
					new Msn.VE.Geometry.Point(0, 0),
					new Msn.VE.Geometry.Point(document.body.clientWidth,
					document.body.clientHeight));

					//END OLD CODE INSERT

					//get the content for the pin.
					this._getAJAXContent();
					this._currentpin.SetDescription("<div id='" + this._PopupPrefix + this._currentpin.GetID() + "'>Loading...</div>");
					this._currentpin.SetTitle("");
					this._map.ShowInfoBox(this._currentpin);

					//IF IE6 FIX IT

					if (isIE6) {
						if (this._isTripPlanning == false) {
							FixIE6div();
						}
						timerRefPop = setInterval("waitForPopup()", 350);
					}


				}
			} else {
				this._map.ShowInfoBox(this._currentpin);
			}
		}
	},

	_getCameraInfo: function(id) {
		//webserviceurl = "webServices/GeoRssFeed.asmx/GetCameraByWebID?webid=" + id;

		this._service.GetCameraByWebID(id, Function.createDelegate(this, this._CameraClickDelegate), Utility.OnFailed);
	},



	_getAJAXContent: function() {
		/// <summary>
		///   Request content for popup.
		/// </summary>

		//call the web service to get the popup info
		this._service.GetPushPin(this._currentpin.Bounds, this._currentindex, this._filters, this._eventDate, Function.createDelegate(this, this._OnContentSucceeded), Utility.OnFailed, this._currentpin.GetID());
	},

	_OnContentSucceeded: function(result, ID) {
		/// <summary>
		///   Receive content for popup.
		/// </summary>  
		/// <param name="result">The webservice result object - JSON PinData</param>  
		/// <param name="ID">The popup ID associated with this call</param>

		//verify this is the data for the current popup.

		if (ID == this._currentpin.GetID()) {
			if (this._map.GetMapMode() == VEMapMode.Mode3D) {
				//3D mode fails to be able to retrieve the div we placed earlier so resort to setting the title and description only
				this._currentpin.SetTitle(result.Title);
				this._currentpin.SetDescription(result.Details);
			} else {
				//create the content element
				//alert(this._currentpin.Latitude + " : " + this._currentpin.Longitude);
				var el = document.createElement("div");
				if (result.TotalRecords > 1) {
					//Just testing styles
					//Display details for popup from the feed
					//if (result.TotalRecords > 5) {
					//	$get(this._PopupPrefix + ID).innerHTML = "1 to 5 of " + result.TotalRecords + " Records <a href='javascript:void(0);' onclick='map._map.SetCenterAndZoom(new VELatLong(" + this._currentpin.Latitude + "," + this._currentpin.Longitude + "),map._zoomlevel+1);' alt='Zoom in for more'>View More</a>";
					//} else {
					$get(this._PopupPrefix + ID).innerHTML = result.TotalRecords + " Record(s) <a href='javascript:void(0);' onclick='map._map.SetCenterAndZoom(new VELatLong(" + this._currentpin.Latitude + "," + this._currentpin.Longitude + "),map._zoomlevel+1);' alt='Zoom in for more'><u>Zoom in</u></a>";
					//}
					//el.setAttribute("style", "border:0px;padding:0px;margin:0px;");
					el.innerHTML = result.Details;
					//el.innerHTML = (this._currentindex + 1) + " of " + result.TotalRecords + " Records<br />" + result.Title + " - " + result.Details;
				} else {
					//clear loading and attach the content
					$get(this._PopupPrefix + ID).innerHTML = "";
					el.innerHTML = result.Details;
				}
				//Add our new div to the popup
				$get(this._PopupPrefix + ID).appendChild(el);

			}
		}

	},

	_PreviousRecord: function() {
		/// <summary>
		///   Request the previous record.
		/// </summary>  
		this._currentindex--;
		$get(this._PopupPrefix + this._currentpin.GetID()).innerHTML = "Loading...";
		this._getAJAXContent();
	},

	_NextRecord: function() {
		/// <summary>
		///   Request the next record.
		/// </summary>      
		this._currentindex++;
		$get(this._PopupPrefix + this._currentpin.GetID()).innerHTML = "Loading...";
		this._getAJAXContent();
	},

	Dispose: function() {
		/// <summary>
		///   cleans up all objects. Detaches all events.
		/// </summary>
		if (this._map != null) {
			this._map.DetachEvent("onchangeview", this.GetPinDataDelegate);
			this._map.DetachEvent("onmouseover", this.PinHoverDelegate);
			this._map.DetachEvent("onclick", this.PinClickDelegate);
			this._map.DetachEvent("onmousewheel", this.ZoomChangeDelegate);
			this._map.DetachEvent("ondoubleclick", this.mouseDoubleClickDelegate);
			this._map.Dispose();
		}
		this._service = null;
		this._mapArgs = null;
		window.clearInterval(this._refreshInterval);
		this._refreshInterval = null;

		window.clearInterval(this.timerRefCameraShutoffPop);
		window.clearInterval(this.timerRefCamera);
		this.timerRefCameraShutoffPop = null
		this.timerRefCamera = null;
		window.clearInterval(this._cameraInterval);
		this._cameraInterval = null;

		this._map = null;
		this._pinID = null;
		this._zoomlevel = null;
		this._layer = null;
		this._cameraLayer = null;
		this._tileLayer = null;

		//popup specific
		this._PopupPrefix = null;
		this._currentpin = null;
		this._currentindex = null;

		this.GetPinDataDelegate = null;
		this.PinHoverDelegate = null;
	},

	_getRoadTile: function() {
		/// <summary>
		///   cleans up all objects. Detaches all events.
		/// </summary>
		if (this._showTile == true) {
			//var tileLayerURL = 'http://192.168.100.9:8080/geoserver/gwc/service/ve?quadkey=%4&format=image/png&layers=dg:RouteWeatherReports';
			//var tileLayerURL = 'http://209.96.234.113:8080/geoserver/gwc/service/ve?quadkey=%4&format=image/gif&layers=dg:RouteWeatherReportsSorted';
			var tileLayerURL = 'http://511.vatraffic.org:8080/geoserver/gwc/service/ve?quadkey=%4&format=image/png&layers=dg:RouteWeatherReportsSorted';
			//var tileLayerURL = 'http://209.96.234.107:8080/geoserver/gwc/service/ve?quadkey=%4&format=image/png&layers=dg:RouteWeatherReportsSorted';

			//if (remoteTileURL != "") {
			//	tileLayerURL = remoteTileURL
			//}

			var now = new Date();
			tileLayerURL = tileLayerURL + "&t=" + now.getTime();

			this._tileLayer = new VETileSourceSpecification('RouteWeatherReports', tileLayerURL);
			this._tileLayer.Opacity = 1;
			this._tileLayer.NumServers = 1;
			this._tileLayer.MinZoomLevel = this._MinMapZoomLevel;
			this._tileLayer.MaxZoomLevel = this._MaxMapZoomLevel;
			this._tileLayer.ZIndex = 100;
			this._map.AddTileLayer(this._tileLayer, true);
		}
	},

	_getCameraLayer: function() {
		if (this._mapArgs.CurrentStatus == "success") {

			//		//var myobj = GeoRSSFeed.GetGeorssCameras(
			this._service.GetGeorssCameras(Function.createDelegate(this, this._onFeedLoadCameras), Utility.OnFailed);
			//		//call webservice
			//		if (this._mapArgs.CurrentStatus == "success") {
			//			this._service.GetClusteredMapData(bounds, zoom, this._filters, Function.createDelegate(this, this._OnMapDataSucceeded), Utility.OnFailed);
			//		}
			//	var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, 'webServices/GeoRSSFeed.asmx/GetGeorssCameras', this._cameraLayer);
			//	this._map.ImportShapeLayerData(veLayerSpec, Function.createDelegate(this, this._onFeedLoadCameras), false);
		}
	},

	_onFeedLoadCameras: function(xmlDoc) {
		//alert("XML Root Tag Name: " + xmlDoc.documentElement.tagName);
		var numShapes = xmlDoc.getElementsByTagName("item");

		this._currentCameras = numShapes;
		this._totalCameras = numShapes.length;

		//Loop over loaded elements and set icons
		this._cameraInterval = setInterval(Function.createDelegate(this, this._cameraLoadNext), this._cameraTimeInterval);


	},

	_cameraLoadNext: function() {

		var objShape = null;
		var cLat = null;
		var cLon = null;
		var pointData = null;
		var pointArray = new Array();
		var counter
		//this._totalCameras = 0;
		//this._currentCamera = 0;
		//this._cameraIncrement = 50;
		//this._cameraTimeInterval = .5 * 1000;
		//this._cameraInterval = null;
		//this._currentCameras
		var i = 0;
		var j = 0;
		i = this._currentCamera;
		//test remove break
		//if (this._currentCamera + this._cameraIncrement <= this._totalCameras) {

		j = i + this._cameraIncrement;
		//}

		while (i < this._totalCameras) {

			try {

				//childNodes {title,description,point,icon}

				//var s = xmlDoc.GetShapeByIndex(i);
				//Splitting IcondId because ID is in this field as well
				//georss references <icon> to virtual earths IconId property
				//so we are piggybacking values here
				//value should look like this "./imgref.gif|244"
				//where format is "Image|ID"

				pointData = this._currentCameras[i].childNodes[2].childNodes[0].nodeValue.split(" ");

				objShape = new VEShape(VEShapeType.Pushpin, new VELatLong(pointData[0], pointData[1]));

				var v = this._currentCameras[i].childNodes[3].childNodes[0].nodeValue.split("|");
				objShape.SetZIndex(101);
				objShape.vdotType = 'camera';
				objShape.SetCustomIcon("<img src='" + v[0] + "' height='8' width='17'/>");
				pointArray.push(objShape);
				if (v[1] != undefined) {
					//ID
					objShape.cid = v[1];
					//var cameraWebid = v[1];
				}
			} catch (e) {
				alert('error: ' + e.message);
				//fail silently
			}

			//Drop out early if we reach our incremen
			if (i == j) {

				break;
			}

			i++
			this._currentCamera = i;
		}

		this._cameraLayer.AddShape(pointArray);

		if (this._currentCamera >= this._totalCameras) {

			window.clearInterval(this._cameraInterval);
			this._currentCameras = null;
			this._currentCamera = 0;
			var objImage;

			objImage = $get("img_tog_Camera");
			this._SetToolbarIcon(objImage);
		} else {
			//alert('breaking ' + i + " " + this._currentCamera + " " + this._totalCameras);
		}



	},

	_CameraClickDelegate: function(XMLref) {
		var cameratag = XMLref.getElementsByTagName("camera");

		attr = cameratag[0].attributes;
		webid = attr.getNamedItem("webid").nodeValue;
		name = attr.getNamedItem("name").nodeValue;
		orientation = attr.getNamedItem("orientation").nodeValue;
		tempdis = attr.getNamedItem("tempdis").nodeValue;
		halfimage = XMLref.getElementsByTagName("halfimage")[0].childNodes[0].nodeValue + "&random=" + Math.random();
		fullimage = XMLref.getElementsByTagName("fullimage")[0].childNodes[0].nodeValue + "&random=" + Math.random();


		if (this._processType == "popup") {
			//Build the description for the popup; name, fullimage, orientation.
			popupBody = "";
			popupBody += "<font color=\"black\"><b>" + name + "</b><br />";
			popupBody += "<img id=\"imgTrafficCam\" src=\"" + fullimage + "\" height=\"240\" width=\"352\" border=\"0\" /><br />";
			popupBody += "<b>" + orientation + "</b></font>";

			//finishPopup();
		}
		else {
			if (this._processType == "popupSelect") {
				//Build the description for the selectable popup; name, fullimage, orientation, selectable radio buttons.
				//descTextSelect &= "<form id=""frmSelectCamera""><img id=""imgTrafficCam"" src=""" & PageCameras.CameraArray(newArrayPointer).TL_FullImage & """ height=""240"" width=""352"" border=""0"" /><br/>"
				//descTextSelect &= PageCameras.CameraArray(newArrayPointer).TL_Orientation & "<br /><input type=""hidden"" id=""hidTrafficCamID"" value=""" & PageCameras.CameraArray(newArrayPointer).TL_Webid & """ /><span>Save as Traffic Camera: </span><input type=""Button"" id=""SaveCamera1"" value=""1"" onclick=""selectTrafficCam(" & PageCameras.CameraArray(newArrayPointer).TL_Webid & ", 1, '" & PageCameras.CameraArray(newArrayPointer).TL_Name & "')"" /><input type=""Button"" id=""SaveCamera2"" value=""2"" onclick=""selectTrafficCam(" & PageCameras.CameraArray(newArrayPointer).TL_Webid & ", 2, '" & PageCameras.CameraArray(newArrayPointer).TL_Name & "')"" /><input type=""Button"" id=""SaveCamera3"" value=""3"" onclick=""selectTrafficCam(" & PageCameras.CameraArray(newArrayPointer).TL_Webid & ", 3, '" & PageCameras.CameraArray(newArrayPointer).TL_Name & "')"" /><input type=""Button"" id=""SaveCamera4"" value=""4"" onclick=""selectTrafficCam(" & PageCameras.CameraArray(newArrayPointer).TL_Webid & ", 4, '" & PageCameras.CameraArray(newArrayPointer).TL_Name & "')"" /></form>"
				popupBody = "";
				popupBody += "<font color=\"black\"><b>" + name + "</b><br />";
				popupBody += "<img id=\"imgTrafficCam\" src=\"" + fullimage + "\" height=\"240\" width=\"352\" border=\"0\" /><br />";
				popupBody += "<b>" + orientation + "</b>";

				popupBody += "<form id=\"frmSelectCamera\">"
				popupBody += "<input type=\"hidden\" id=\"hidTrafficCamID\" value=\"" + webid + "\" /><span>Save as Traffic Camera: </span>"
				popupBody += "<input type=\"Button\" id=\"SaveCamera1\" value=\"1\" onclick=\"selectTrafficCam(" + webid + ", 1, '" + name + "')\" />&nbsp;&nbsp;"
				popupBody += "<input type=\"Button\" id=\"SaveCamera2\" value=\"2\" onclick=\"selectTrafficCam(" + webid + ", 2, '" + name + "')\" />&nbsp;&nbsp;"
				popupBody += "<input type=\"Button\" id=\"SaveCamera3\" value=\"3\" onclick=\"selectTrafficCam(" + webid + ", 3, '" + name + "')\" />&nbsp;&nbsp;"
				popupBody += "<input type=\"Button\" id=\"SaveCamera4\" value=\"4\" onclick=\"selectTrafficCam(" + webid + ", 4, '" + name + "')\" />"
				popupBody += "</font></form>"

				//finishPopup();
			}
			else {
				//Static image; halfimage with name as alt tag.
			}
		}

		//Build description.
		this._currentpin.SetDescription(popupBody);


		//showShapePinDetails();
		//pinref.Show();



		window.ero.setBoundingArea(
    new Msn.VE.Geometry.Point(0, 0),
    new Msn.VE.Geometry.Point(document.body.clientWidth,
        document.body.clientHeight));

		this._map.ShowInfoBox(this._currentpin);

		if (isIE6) {
			FixIE6div();
			//timerRefPop = setInterval("waitForPopup()", 350);
		}

		//afterPopup();
		this.cameraShutoffPop = false;
		// 7/28/2008 JH - Camera refresh limit removed.
		// JH - Added back in for TrafficLand.
		// CS Do not forget to dispose of these items to reduce possible memory leak
		this.timerRefCameraShutoffPop = setTimeout(Function.createDelegate(this, this.shutOffCamerasPop), this.cameraShutoffMilliSecondsPop);
		this.timerRefCamera = setInterval(Function.createDelegate(this, this.refreshPopupCamera), 2000);


	},
	//	},

	//	_getCameraWebid: function(shape) {
	//		var cameraWebid = 0;
	//		var v = shape.IconId.split("|");
	//		if (v[1] != undefined) {
	//			//ID
	//			cameraWebid = v[1];
	//		}
	//		return cameraWebid;
	//	},

	shutOffCamerasPop: function() {
		//alert("Shutoff");
		this.cameraShutoffPop = true;
	},

	refreshPopupCamera: function() {
		if (this.cameraShutoffPop == false) {

			//isPopupHidden found in utiltiy.js
			if (isPopupHidden() == false) {
				popCamera = document.getElementById("imgTrafficCam");
				camSrc = popCamera.src;
				ptr = camSrc.lastIndexOf("&");
				if (ptr > 0) {
					camSrc = camSrc.substring(0, ptr);
					camSrc = camSrc + "&random=" + Math.random();
				}
				popCamera.src = camSrc;
				//alert(camSrc);
				//alert("refresh: ok - " + timerRefCamera);
			}
			else {
				if (this.timerRefCamera != null) {
					//clear the interval
					clearInterval(this.timerRefCamera);
					this.timerRefCamera = null;
					this.cameraShutoffPop = true;
					//clear the timeout
					clearTimeout(this.timerRefCameraShutoffPop);
					this.timerRefCameraShutoffPop = null;
					//alert("refresh: hidden - " + timerRefCamera);
				}
			}
		}
		else {
			if (this.timerRefCamera != null) {
				//clear the interval
				clearInterval(this.timerRefCamera);
				this.timerRefCamera = null;
				this.cameraShutoffPop = true;
				//clear the timeout
				clearTimeout(this.timerRefCameraShutoffPop);
				this.timerRefCameraShutoffPop = null;
				//alert("refresh: shutoff- " + timerRefCamera);
			}
		}

	},

	//Called during camera selection in control room
	selectTrafficCam: function(cameraID, cameraPosition, cameraTitle) {
		//alert('Camera ID: ' + cameraID +  ' Camera Position: ' +  cameraPosition +  ' Camera Title: ' +  cameraTitle)
		//Functin setCameraInfo is added dynamically in editplaces.aspx.vb
		setCameraInfo(cameraPosition, cameraID, cameraTitle)
	},

	_ZoomChange: function(event) {
		//return false;
		var currentZoom = this._map.GetZoomLevel();
		// If the current zoom is within the max and min boundaries
		//Returning true stops the event

		if (((event.mouseWheelChange < 0) && (currentZoom <= this._MinMapZoomLevel)) || ((event.mouseWheelChange > 0) && (currentZoom >= this._MaxMapZoomLevel))) {
			return true;
		}

	},

	_MouseDoubleClick: function(e) {
		var currentZoom = this._map.GetZoomLevel();
		//Returning true stops the event
		if (currentZoom >= this._MaxMapZoomLevel) {
			return true;
		}
	},

	_buildNavigation: function() {
		//May have to build out nav controls from here. hopefully will not have to do this
	},

	addFilter: function(strFilter) {

		this._filters += strFilter.replace("%25", "");
		this._filters = this._filters.replace("%20", "");
		this._filters = this._filters.replace("%25", "");
		this._filters = this._filters.replace(" ", "");
		if (strFilter.toLowerCase() == "camera") {
			this._getCameraLayer();
		} else {
			this._GetPinData();
		}
		Utility.setCookie("mapFilters", this._filters, 30, "/", "", "");
	},

	removeFilter: function(strFilter) {
		this._filters = this._filters.replace(new RegExp(strFilter, "g"), "");
		if (strFilter.toLowerCase() == "camera") {
			//Remove the shapelayer for cameras
			if (this._cameraLayer != null) {
				this._cameraLayer.DeleteAllShapes();
				//Remove camera interval to catch users showing and hiding cameras in quick succession;
				if (this._cameraInterval != null) { window.clearInterval(this._cameraInterval); }
			}
		} else {
			this._GetPinData();
		}
		Utility.setCookie("mapFilters", this._filters, 30, "/", "", "");
	},

	GetZoomLevel: function() {
		return this._map.GetZoomLevel();
	},

	ZoomIn: function() {
		this._map.ZoomIn();

	},

	ZoomOut: function() {
		this._map.ZoomOut();

	},

	ZoomToIcon: function(objIcon) {

	},

	StartContinuousPan: function(x, y) {
		this._map.StartContinuousPan(x, y);
	},

	EndContinuousPan: function() {
		this._map.EndContinuousPan();
	}
}

vdot.Map.registerClass('vdot.Map', null, Sys.IDisposable);




if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

document.write("<style type='text/css'>@import url('App_Themes/VA/cameramap.css');</style>");