var xFactor=0;
var yFactor=0;
//var xFactor=0.00144715;
//var yFactor=-0.00280285;
var map;
var camNorthVideo = new GIcon();
var camSouthVideo = new GIcon();
var camEastVideo = new GIcon();
var camWestVideo = new GIcon();
var camNorth = new GIcon();
var camSouth = new GIcon();
var camEast = new GIcon();
var camWest = new GIcon();
var speedLowImpact = new GIcon();
var speedMedImpact = new GIcon();
var speedHighImpact = new GIcon();
var sgnBN = new GIcon();
var sgnBS = new GIcon();
var sgnBE = new GIcon();
var sgnBW = new GIcon();
var sgnGN = new GIcon();
var sgnGS = new GIcon();
var sgnGE = new GIcon();
var sgnGW = new GIcon();
var incH = new GIcon();
var incM= new GIcon();
var incL= new GIcon();
var incU= new GIcon();
var _center;
function CreateGrpsAndMrks(input)
{
    try
   { 
    if(input!="GETUPDATE")
        DrawCity();
    _ajaxManager.AjaxRequest(input);	  
   }
  catch(e)
  {
    alert(e.message + " - CreateGrpsAndMrks");
  }  
}
function SetMapAndIconProperties(xCenter,yCenter,zZoom)
{
	try
	{
       incH.image=_iDr + "inc_h.gif";
       incH.iconSize = new GSize(18, 18);
       incH.iconAnchor = new GPoint(9, 9);
       incH.infoWindowAnchor = new GPoint(9, 9);

        incM.image=_iDr + "inc_m.gif";
        incM.iconSize = new GSize(18, 18);
        incM.iconAnchor = new GPoint(9, 9);
        incM.infoWindowAnchor = new GPoint(9, 9);

        incL.image=_iDr + "inc_l.gif";
        incL.iconSize = new GSize(18, 18);
        incL.iconAnchor = new GPoint(9, 9);
        incL.infoWindowAnchor = new GPoint(9, 9);

        incU.image=_iDr + "inc_u.gif";
        incU.iconSize = new GSize(18, 18);
        incU.iconAnchor = new GPoint(9, 9);
        incU.infoWindowAnchor = new GPoint(9, 9);

        sgnBN.image=_iDr + "sgn_blk_n.gif";
        sgnBN.iconSize = new GSize(20,15);
        sgnBN.iconAnchor = new GPoint(10,8);
        sgnBN.infoWindowAnchor = new GPoint(10,8);

        sgnBS.image=_iDr + "sgn_blk_s.gif";
        sgnBS.iconSize = new GSize(20,15);
        sgnBS.iconAnchor = new GPoint(10,8);
        sgnBS.infoWindowAnchor = new GPoint(10,8);

        sgnBE.image=_iDr + "sgn_blk_e.gif";
        sgnBE.iconSize = new GSize(15, 20);
        sgnBE.iconAnchor = new GPoint(8,10);
        sgnBE.infoWindowAnchor = new GPoint(10,8);

        sgnBW.image=_iDr + "sgn_blk_w.gif";
        sgnBW.iconSize = new GSize(15,20);
        sgnBW.iconAnchor = new GPoint(8,10);
        sgnBW.infoWindowAnchor = new GPoint(8,10);

        sgnGN.image=_iDr + "sgn_grn_n.gif";
        sgnGN.iconSize = new GSize(20,15);
        sgnGN.iconAnchor = new GPoint(10,8);
        sgnGN.infoWindowAnchor = new GPoint(10,8);

        sgnGS.image=_iDr + "sgn_grn_s.gif";
        sgnGS.iconSize = new GSize(20,15);
        sgnGS.iconAnchor = new GPoint(10,8);
        sgnGS.infoWindowAnchor = new GPoint(10,8);

        sgnGE.image=_iDr + "sgn_grn_e.gif";
        sgnGE.iconSize = new GSize(15,20);
        sgnGE.iconAnchor = new GPoint(8,10);
        sgnGE.infoWindowAnchor = new GPoint(8,10);

        sgnGW.image=_iDr + "sgn_grn_w.gif";
        sgnGW.iconSize = new GSize(15,20);
        sgnGW.iconAnchor = new GPoint(8,10);
        sgnGW.infoWindowAnchor = new GPoint(8,10);

		camNorthVideo.image=_iDr + "sm_cam_north_video.gif";
		camNorthVideo.iconSize = new GSize(16, 16);
		camNorthVideo.iconAnchor = new GPoint(8,8);
		camNorthVideo.infoWindowAnchor =new GPoint(8,8);

		camSouthVideo.image=_iDr + "sm_cam_south_video.gif";
		camSouthVideo.iconSize = new GSize(16, 16);
		camSouthVideo.iconAnchor = new GPoint(8,8);
		camSouthVideo.infoWindowAnchor = new GPoint(8, 8);

		camEastVideo.image=_iDr + "sm_cam_east_video.gif";
		camEastVideo.iconSize = new GSize(16, 16);
		camEastVideo.iconAnchor = new GPoint(8,8);
		camEastVideo.infoWindowAnchor = new GPoint(8,8);

		camWestVideo.image=_iDr + "sm_cam_west_video.gif";
		camWestVideo.iconSize = new GSize(16, 16);
		camWestVideo.iconAnchor = new GPoint(8,8);
		camWestVideo.infoWindowAnchor = new GPoint(8,8);
		
		camNorth.image=_iDr + "sm_cam_north.gif";
		camNorth.iconSize = new GSize(16, 16);
		camNorth.iconAnchor = new GPoint(8,8);
		camNorth.infoWindowAnchor =new GPoint(8,8);

		camSouth.image=_iDr + "sm_cam_south.gif";
		camSouth.iconSize = new GSize(16, 16);
		camSouth.iconAnchor = new GPoint(8,8);
		camSouth.infoWindowAnchor = new GPoint(8, 8);

		camEast.image=_iDr + "sm_cam_east.gif";
		camEast.iconSize = new GSize(16, 16);
		camEast.iconAnchor = new GPoint(8,8);
		camEast.infoWindowAnchor = new GPoint(8,8);

		camWest.image=_iDr + "sm_cam_west.gif";
		camWest.iconSize = new GSize(16, 16);
		camWest.iconAnchor = new GPoint(8,8);
		camWest.infoWindowAnchor = new GPoint(8,8);

		speedLowImpact.image=_iDr + "lowimpactcar.gif";
		speedLowImpact.iconSize = new GSize(18, 18);
		speedLowImpact.iconAnchor = new GPoint(9, 9);
		speedLowImpact.infoWindowAnchor = new GPoint(9, 9);

		speedMedImpact.image=_iDr + "medimpactcar.gif";
		speedMedImpact.iconSize = new GSize(18, 18);
		speedMedImpact.iconAnchor = new GPoint(9, 9);
		speedMedImpact.infoWindowAnchor = new GPoint(9, 9);

		speedHighImpact.image=_iDr + "highimpactcar.gif";
		speedHighImpact.iconSize = new GSize(18, 18);
		speedHighImpact.iconAnchor = new GPoint(9, 9);
		speedHighImpact.infoWindowAnchor = new GPoint(9, 9);

		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl(new GSize(200,200)));
		//map.addControl(new GScaleControl());
				
		GEvent.addListener(map, "moveend", function() {
			_center = map.getCenter();
		});
		GEvent.addListener(map, "resize", function() {
			map.setCenter(_center);
		});
	        
		GEvent.addListener(map, "click", function(marker,point)
			{
				if(marker)
				{
					
					if(_mkrType==1)
					{
						try
						{
							hidetip2();
							clearTimeout(_myOPHideTime2);
							clearTimeout(_myOPShowTime2);
						}
						catch(e)
						{
							//keep going
						}
						
						try
						{
							hidetip();
							clearTimeout(_myOPHideTime);
							clearTimeout(_myOPShowTime);
							ShowOPToolTip();
						}
						catch(e)
						{
							//keep going
						}
					}
					else if(_mkrType==2)
					{
						try
						{
							hidetip();
							clearTimeout(_myOPHideTime);
							clearTimeout(_myOPShowTime);
						}
						catch(e)
						{
							//keep going
						}
						try
						{
							hidetip2();
							clearTimeout(_myOPHideTime2);
							clearTimeout(_myOPShowTime2);
							ShowOPToolTip2();
						}
						catch(e)
						{
							//keep going
						}
					}
				}
				else
				{	
					try
					{
						hidetip();
						clearTimeout(_myOPHideTime);
						clearTimeout(_myOPShowTime);
					}
					catch(e)
					{
						//keep going
					}
					try
					{
						hidetip2();
						clearTimeout(_myOPHideTime2);
						clearTimeout(_myOPShowTime2);
					}
					catch(e)
					{
						//keep going
					}
				}
				//_mkrType=-1;
				});	
		
		map.setCenter(new GLatLng(yCenter, xCenter), zZoom);
		_center=map.getCenter();
		
		var omap=document.getElementById("map_overview");
	        
		// == restyling ==
	    
		omap.firstChild.style.border = "1px solid gray";

		omap.firstChild.firstChild.style.left="4px";
		omap.firstChild.firstChild.style.top="4px";
		omap.firstChild.firstChild.style.width="190px";
		omap.firstChild.firstChild.style.height="190px";
		
		map.setCenter(new GLatLng(yCenter, xCenter), zZoom);
		_center=map.getCenter();
		
        GEvent.addListener(map,'load',CreateGrpsAndMrks('GETNEWDATA'));
	}
	catch(e)
	{
		//the Google API could generate various errors
		//depending on the browser being used
		//just ignore them
		var sErr=e.message;
	}
}


if (GBrowserIsCompatible())
{	
	function ToggleCameras()
	{
		try
		{	    
			camNorthVideoGroup.toggleMarkersVisible();
			camSouthVideoGroup.toggleMarkersVisible();
			camEastVideoGroup.toggleMarkersVisible();
			camWestVideoGroup.toggleMarkersVisible();
			camNorthGroup.toggleMarkersVisible();
			camSouthGroup.toggleMarkersVisible();
			camEastGroup.toggleMarkersVisible();
			camWestGroup.toggleMarkersVisible();
		}
		catch(e)
		{
			//keep going
			var sErr=e.message;
		}
	}
	
	function ToggleLinks(input)
	{
		try
		{
			if(_aPolylines&&input.toUpperCase()=="SHOW")
			{
				for(var t=0;t<_aPolylines.length;t++)
				{
					map.addOverlay(_aPolylines[t]);
					//_aPolylines[t].display[true];
				}
				speedLowImpactGroup.toggleMarkersVisible();
				speedMedImpactGroup.toggleMarkersVisible();
				speedHighImpactGroup.toggleMarkersVisible();
				if(document.getElementById('lyrLegend'))
				{
					document.getElementById('lyrLegend').style.display='';
				}
			}
			else if(_aPolylines&&input.toUpperCase()=="HIDE")
			{
				for(var t=0;t<_aPolylines.length;t++)
				{
					//_aPolylines[t].display[false];
					map.removeOverlay(_aPolylines[t]);
				}
				speedLowImpactGroup.toggleMarkersVisible();
				speedMedImpactGroup.toggleMarkersVisible();
				speedHighImpactGroup.toggleMarkersVisible();
				if(document.getElementById('lyrLegend'))
				{
					document.getElementById('lyrLegend').style.display='none';
				}
			}
		}
		catch(e)
		{
			var sErr=e.message;
		}
	}
	    
}
else
{
    alert("Sorry, the Google Maps API is not compatible with this browser.");
}

  

