//<![CDATA[

 
// *** Setup ******************************************************************************************************	  
	var side_bar_html = new Array()
	side_bar_html[0] = "";
	side_bar_html[1] = "";
	side_bar_html[2] = "";
	side_bar_html[3] = "";
	side_bar_html[4] = "";
	side_bar_html[5] = "";
	side_bar_html[6] = "";

	var freqList = new Array()
	freqList[0] = "";
	freqList[1] = "";
	freqList[2] = "";
	freqList[3] = "";
	
	var searchPolygon;
	
	var isGeoSat = "";
		  
	var gmarkers = [];
	var lastlinkid;
	
	
	// smaller radius in km		
	var distTo; //var distTo = 500;
		  
	// bigger radius in km			
	var distToBig; //var distToBig = 1500;
		  
	// how smooth is the circle?
	var pointInterval = 30
	
	var showSignalType = "" // defaults the signal type to Standard
		  
	// custom icon
	var veriposIcon = new GIcon();
	veriposIcon.image = "/images/veriposmin.png";
	veriposIcon.shadow = "";
	veriposIcon.iconSize = new GSize(20, 20);
	veriposIcon.shadowSize = new GSize(0, 0);
	veriposIcon.iconAnchor = new GPoint(10, 10);
	veriposIcon.infoWindowAnchor = new GPoint(10, 10);
	veriposIcon.infoShadowAnchor = new GPoint(0,0);
	veriposIcon.transparent = "/images/markerTransparent.png";
	veriposIcon.printImage = "/images/veriposie.gif";
	veriposIcon.mozPrintImage = "/images/veriposff.gif";
	
	// geosat overlay
	var geo = new GIcon();
	geo.image = "/images/geo.png";
	geo.iconSize = new GSize(635, 500);
	geo.shadowSize = new GSize(0,0);
	geo.iconAnchor = new GPoint(317.5, 250);
	geo.infoWindowAnchor = new GPoint(317.5,250);
	geo.infoShadowAnchor = new GPoint(317.5, 250);
	
	// apex overlay
	var apex = new GIcon();
	apex.image = "/images/apex.png";
	apex.iconSize = new GSize(635, 500);
	apex.shadowSize = new GSize(0,0);
	apex.iconAnchor = new GPoint(317.5, 250);
	apex.infoWindowAnchor = new GPoint(317.5,250);
	apex.infoShadowAnchor = new GPoint(317.5, 250);
	
	// ultra overlay
	var ultra = new GIcon();
	ultra.image = "/images/ultra.png";
	ultra.iconSize = new GSize(635, 500);
	ultra.shadowSize = new GSize(0,0);
	ultra.iconAnchor = new GPoint(317.5, 250);
	ultra.infoWindowAnchor = new GPoint(317.5,250);
	ultra.infoShadowAnchor = new GPoint(317.5, 250);
	
	
	// 98W overlay
	var o98W = new GIcon();
	o98W.image = "/images/98W.png";
	o98W.iconSize = new GSize(635, 500);
	o98W.shadowSize = new GSize(0,0);
	o98W.iconAnchor = new GPoint(317.5, 250);
	o98W.infoWindowAnchor = new GPoint(317.5,250);
	o98W.infoShadowAnchor = new GPoint(317.5, 250);
	
	// AORW overlay
	var AORW = new GIcon();
	AORW.image = "/images/aorw.png";
	AORW.iconSize = new GSize(635, 500);
	AORW.shadowSize = new GSize(0,0);
	AORW.iconAnchor = new GPoint(317.5, 250);
	AORW.infoWindowAnchor = new GPoint(317.5,250);
	AORW.infoShadowAnchor = new GPoint(317.5, 250);	
	
	// AORE overlay
	var AORE = new GIcon();
	AORE.image = "/images/aore.png";
	AORE.iconSize = new GSize(635, 500);
	AORE.shadowSize = new GSize(0,0);
	AORE.iconAnchor = new GPoint(317.5, 250);
	AORE.infoWindowAnchor = new GPoint(317.5,250);
	AORE.infoShadowAnchor = new GPoint(317.5, 250);
	
	// o25E overlay
	var o25E = new GIcon();
	o25E.image = "/images/25E.png";
	o25E.iconSize = new GSize(635, 500);
	o25E.shadowSize = new GSize(0,0);
	o25E.iconAnchor = new GPoint(317.5, 250);
	o25E.infoWindowAnchor = new GPoint(317.5,250);
	o25E.infoShadowAnchor = new GPoint(317.5, 250);	
	
	// IOR overlay
	var IOR = new GIcon();
	IOR.image = "/images/ior.png";
	IOR.iconSize = new GSize(635, 500);
	IOR.shadowSize = new GSize(0,0);
	IOR.iconAnchor = new GPoint(317.5, 250);
	IOR.infoWindowAnchor = new GPoint(317.5,250);
	IOR.infoShadowAnchor = new GPoint(317.5, 250);	
	
	// o109E overlay
	//var o109E = new GIcon();
	//o109E.image = "/images/109E.png";
	//o109E.iconSize = new GSize(635, 500);
	//o109E.shadowSize = new GSize(0,0);
	//o109E.iconAnchor = new GPoint(317.5, 250);
	//o109E.infoWindowAnchor = new GPoint(317.5,250);
	//o109E.infoShadowAnchor = new GPoint(317.5, 250);

	// o109E overlay
	var o143_5E = new GIcon();
	o143_5E.image = "/images/143.5E.png";
	o143_5E.iconSize = new GSize(635, 500);
	o143_5E.shadowSize = new GSize(0, 0);
	o143_5E.iconAnchor = new GPoint(317.5, 250);
	o143_5E.infoWindowAnchor = new GPoint(317.5, 250);
	o143_5E.infoShadowAnchor = new GPoint(317.5, 250);
	
	// POR overlay
	var POR = new GIcon();
	POR.image = "/images/por.png";
	POR.iconSize = new GSize(635, 500);
	POR.shadowSize = new GSize(0,0);
	POR.iconAnchor = new GPoint(317.5, 250);
	POR.infoWindowAnchor = new GPoint(317.5,250);
	POR.infoShadowAnchor = new GPoint(317.5, 250);	

	  
// *** Point circles ***************************************************************************************************	  
		  

	function getCirclePoints(center,radius){
	
		var circlePoints = Array();
		var searchPoints = Array();
			
		with (Math) {

			var d = radius/6378.8;	// radians
			var lat1 = (PI/180)* center.lat(); // radians
			var lng1 = (PI/180)* center.lng(); // radians

			for (var a = 0 ; a < 361 ; a++ ) {
				var tc = (PI/180)*a;
				var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
				var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
				var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function
				var point = new GLatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI)));
				circlePoints.push(point);
			}
					
			searchPolygon = new GPolygon(circlePoints, '#e31b30', 2, 1, '#e31b30', 0.1); // circle borders and colour

		}	
			
		map.addOverlay(searchPolygon);

		return searchPoints;

	}
		  
		  
// *** Main Map ***************************************************************************************************	

	function createMarker(point,name,sid,satcov,status,html,distTo,distToBig,regionID,standard,standardPlus,dglonass) {
		
		
		var freq = "";
		
		if (standard == true){freq += "Standard"; freqList[0] = "standard";}
		if (standard != false && standardPlus != false){freq += ", ";}
		if (standardPlus == true){freq += "Standard+"; freqList[1] = "standardplus";}
		if (standardPlus != false && dglonass != false){freq += ", ";}
		if (dglonass == true){freq += "DGlonass"; freqList[2] = "glonass";}

		
		//alert(showSignalType);
		
		var marker = null;
		
		if ((("standard" == showSignalType) && standard) ||
				(("standardplus" == showSignalType) && standardPlus) ||
						(("glonass" == showSignalType) && dglonass))		
		{		
		
			marker = new GMarker(point,veriposIcon);
			var linkid = "link"+(gmarkers.length);
		
			GEvent.addListener(marker, "click", function() {
					
				map.clearOverlays();  //clear out old
				addPoints(); // add the new
						
				marker.openInfoWindowHtml("<span class='mapinfobox' style='background-image:url(/images/" + status + ".jpg);'><span class='infotxt'><strong>Place</strong>: " + name + "<br /><strong>ID</strong>: " + sid + "<br /><strong>Coverage</strong>: " + satcov + "<br /><strong>Status</strong>: " + status + " <br /><strong>System</strong>: " + freq + "</span></span>");
				
				document.getElementById(linkid).className += " selected";

				lastlinkid=linkid;
				
				searchPoints = getCirclePoints(point,distToBig); // show range
				searchPoints = getCirclePoints(point,distTo); // show range
				
				//map.panTo(point);
				map.setCenter(point, 3);
				
				// show the nav
				//$("ul#subNav li ul li").children("ul").hide();
				document.getElementById(linkid).parentNode.style.display="block";

			});
					
			// save the info we need to use later for the side_bar
			gmarkers.push(marker);
			side_bar_html[regionID] += '<li class="mapplace" id="'+linkid+'"><a href="javascript:void(0)" onclick="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + ' - ' + sid +'<\/a><\/li>';

	updateSideBar();


			return marker;
		
		}		
		else 
			return null;		
	}
	
	function updateSideBar()
	{   
		// all this should be a loop - will be one day...
		document.getElementById("side_bar0").innerHTML = side_bar_html[0];
		document.getElementById("side_bar1").innerHTML = side_bar_html[1];
		document.getElementById("side_bar2").innerHTML = side_bar_html[2];
		document.getElementById("side_bar3").innerHTML = side_bar_html[3];
		document.getElementById("side_bar4").innerHTML = side_bar_html[4];
		document.getElementById("side_bar5").innerHTML = side_bar_html[5];
		document.getElementById("side_bar6").innerHTML = side_bar_html[6];
		
		if ($("ul#subNav li ul#coverageArea li ul#side_bar0").is(':parent')) {
			$("ul#subNav li ul#coverageArea li ul#side_bar0").parent().show();
		}
	
		if ($("ul#subNav li ul#coverageArea li ul#side_bar1").is(':parent')) {
			$("ul#subNav li ul#coverageArea li ul#side_bar1").parent().show();
		}
		
		if ($("ul#subNav li ul#coverageArea li ul#side_bar2").is(':parent')) {
			$("ul#subNav li ul#coverageArea li ul#side_bar2").parent().show();
		}
		
		if ($("ul#subNav li ul#coverageArea li ul#side_bar3").is(':parent')) {
			$("ul#subNav li ul#coverageArea li ul#side_bar3").parent().show();
		}

		if ($("ul#subNav li ul#coverageArea li ul#side_bar4").is(':parent')) {
			$("ul#subNav li ul#coverageArea li ul#side_bar4").parent().show();
		}
		
		if ($("ul#subNav li ul#coverageArea li ul#side_bar5").is(':parent')) {
			$("ul#subNav li ul#coverageArea li ul#side_bar5").parent().show();
		}
		
		if ($("ul#subNav li ul#coverageArea li ul#side_bar6").is(':parent')) {
			$("ul#subNav li ul#coverageArea li ul#side_bar6").parent().show();
		}			
		
	}
	
	function resetSideBar()
	{
		side_bar_html[0] = "";
		side_bar_html[1] = "";
		side_bar_html[2] = "";
		side_bar_html[3] = "";
		side_bar_html[4] = "";
		side_bar_html[5] = "";
		side_bar_html[6] = "";
		$("ul#subNav li ul#coverageArea li").hide(); // hide coverage areas to start
		$("ul#subNav li ul#coverageArea li ul").hide(); // hide coverage area locations to start		
	}

			
// *** Go *********************************************************************************************************
	
	
	// This function picks up the click and opens the corresponding info window
	function myclick(i) {
		GEvent.trigger(gmarkers[i], "click");
	}
	
	
	// This function picks up the signal type click and refreshes the map accordingly
	function signalclick(signalType) {

	
	// || (signalType == "o109E") 
		if ((signalType == "apex")
		|| (signalType == "ultra")
		|| (signalType == "geo")
		|| (signalType == "o98W")
		|| (signalType == "AORW")
		|| (signalType == "AORE")
		|| (signalType == "o25E")
		|| (signalType == "IOR")
		|| (signalType == "o143_5E") 
		|| (signalType == "POR")) {
			var satType = signalType;
			isGeoSat = true;
			
			//$("ul#subNav li#pointArea").hide(); // hide pointArea coverage
			//$("ul#subNav li#geoSat").show(); // show geosat coverage to start
			
			map.clearOverlays();  //clear out old
			map = new GMap2(document.getElementById("gmap"));
			map.setCenter(new GLatLng(0,0), 1);
			var sat01 = new GMarker(map.getCenter(), window[satType]); 
			map.addOverlay(sat01);
			
			if(signalType.charAt(0) == "o"){
				signalType = signalType.substr(1, signalType.length);
			}
			signalType = signalType.replace("_", ".");

			
			$("h5#coverageTypeSelect").text("Coverage Type: " + signalType);
			
		}else{
		
			isGeoSat = false;
			
			showSignalType = signalType;
			map.clearOverlays();  //clear out old
			map = new GMap2(document.getElementById("gmap"));
			map.setCenter(new GLatLng(0,0), 1);
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			addPoints(); // add the points
			
			showSignalTypeText = showSignalType;
			
			if(showSignalType == "standardplus"){
				showSignalTypeText = "Standard Plus";
			}
			
			$("h5#coverageTypeSelect").text("Coverage Type: " + showSignalTypeText)
			
			//$("ul#subNav li#geoSat").hide(); // hide geosat coverage to start
			//$("ul#subNav li#pointArea").show(); // show pointArea coverage
		}
		
		
		
	}	


		
	
	// create the main map  
	var map = new GMap2(document.getElementById("gmap"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());

	map.setCenter(new GLatLng(0,0), 1);

	addPoints(); // add the points
						   
						   
	GEvent.addListener(map,"infowindowclose", function() {
		document.getElementById(lastlinkid).className = document.getElementById(lastlinkid).className.replace(" selected",'')
	});
	

	// put the assembled side_bar_html contents into the side_bar divs
	updateSideBar();
	
	//$("ul#subNav li ul li").children("ul").hide();
	 
		 
//]]>
