	function ucfirst (str) {
	    str += '';
	    var f = str.charAt(0).toUpperCase();
	    return f + str.substr(1);
	}

    
    var crosshairsSize=25;
	GMap2.prototype.addCrosshairs=function()
	{
		var container=this.getContainer();
		if(this.crosshairs)
		this.removeCrosshairs();
		
		var crosshairs=document.createElement("img");
		crosshairs.src='crosshair.png';
		crosshairs.style.width=crosshairsSize+'px';
		crosshairs.style.height=crosshairsSize+'px';
		crosshairs.style.border='0';
		crosshairs.style.position='relative';
		crosshairs.style.top=((container.clientHeight-crosshairsSize)/2)+'px';
		crosshairs.style.left=((container.clientWidth-crosshairsSize)/2)+'px'; 
		crosshairs.style.zIndex='9999';
		container.appendChild(crosshairs);
		this.crosshairs=crosshairs;
		return crosshairs;
	};

	 var icon2a = new GIcon();     
	 icon2a.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm2a.png';   
	 icon2a.iconSize = new GSize(24, 24);    
	 icon2a.iconAnchor = new GPoint(1, 3);    
	 icon2a.infoWindowAnchor = new GPoint(5, 1);
	 
	 var icon2d = new GIcon();     
	 icon2d.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm2d.png';    
	 icon2d.iconSize = new GSize(24, 24);    
	 icon2d.iconAnchor = new GPoint(-5, -3);    
	 icon2d.infoWindowAnchor = new GPoint(5, 1);
	 
	 var icon2dm = new GIcon();     
	 icon2dm.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm2dm.png';   
	 icon2dm.iconSize = new GSize(24, 24);    
	 icon2dm.iconAnchor = new GPoint(0, 2);    
	 icon2dm.infoWindowAnchor = new GPoint(5, 1);

	 var icon6a = new GIcon();     
	 icon6a.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm6a.png';    
	 icon6a.iconSize = new GSize(24, 24);     
	 icon6a.iconAnchor = new GPoint(-10, -5);    
	 icon6a.infoWindowAnchor = new GPoint(5, 1);

	 var icon10a = new GIcon();     
	 icon10a.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm10a.png';    
	 icon10a.iconSize = new GSize(24, 24);    
	 icon10a.iconAnchor = new GPoint(-10, 15);    
	 icon10a.infoWindowAnchor = new GPoint(5, 1);

	 var icon70a = new GIcon();     
	 icon70a.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm70a.png';    
	 icon70a.iconSize = new GSize(24, 24);    
	 icon70a.iconAnchor = new GPoint(-5, 10);

	 var icon70d = new GIcon();     
	 icon70d.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm70d.png';    
	 icon70d.iconSize = new GSize(24, 24);    
	 icon70d.iconAnchor = new GPoint(4, -3);
	 
	 var icon70dm = new GIcon();     
	 icon70dm.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm70dm.png';    
	 icon70dm.iconSize = new GSize(24, 24);    
	 icon70dm.iconAnchor = new GPoint(1, -4);

	 var icon23a = new GIcon();     
	 icon23a.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm23a.png';    
	 icon23a.iconSize = new GSize(24, 24);    
	 icon23a.iconAnchor = new GPoint(1, -5);
	 
	 var icon23d = new GIcon();     
	 icon23d.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm23d.png';    
	 icon23d.iconSize = new GSize(24, 24);    
	 icon23d.iconAnchor = new GPoint(1, -5);
	 
	 var icon23tv = new GIcon();     
	 icon23tv.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm23tv.png';    
	 icon23tv.iconSize = new GSize(24, 24);    
	 icon23tv.iconAnchor = new GPoint(-5, -5);
	 
	 var icon13a = new GIcon();     
	 icon13a.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm13a.png';    
	 icon13a.iconSize = new GSize(24, 24);    
	 icon13a.iconAnchor = new GPoint(-5, -5);
	 
	 var icon13d = new GIcon();     
	 icon13d.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm13d.png';    
	 icon13d.iconSize = new GSize(24, 24);    
	 icon13d.iconAnchor = new GPoint(-5, -5);

	 var icon13tv = new GIcon();     
	 icon13tv.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm13tv.png';    
	 icon13tv.iconSize = new GSize(24, 24);    
	 icon13tv.iconAnchor = new GPoint(-5, 3);

	 var icon3a = new GIcon();     
	 icon3a.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm3a.png';    
	 icon3a.iconSize = new GSize(24, 24);    
	 icon3a.iconAnchor = new GPoint(-5, 5);
	 
	 var icon3d = new GIcon();     
	 icon3d.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm3d.png';    
	 icon3d.iconSize = new GSize(24, 24);   
	 icon3d.iconAnchor = new GPoint(5, -5);
	 
	 var icon3tv = new GIcon();     
	 icon3tv.image = 'http://grampianrepeatergroup.co.uk/img/gmIcons/gm3tv.png';    
	 icon3tv.iconSize = new GSize(24, 24);    
	 icon3tv.iconAnchor = new GPoint(-2, -5);

    if (GBrowserIsCompatible()) {
		var gmarkers = [];
		var gicons = [];
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.iconAnchor = new GPoint(9,34);
		baseIcon.iconSize = new GSize(20,34);
		baseIcon.infoWindowAnchor = new GPoint(9,2);
		
		GDownloadUrl("grgUkRepeaterXMLQuery.php", function(doc) {
				var xmlDoc = GXml.parse(doc);
				var markers = xmlDoc.documentElement.getElementsByTagName("marker");
				
				for (var i = 0; i < markers.length; i++) {
						var callsign = markers[i].getAttribute("callsign");    
						var qth = markers[i].getAttribute("qth");    
						var qra = markers[i].getAttribute("qra");
						var out = markers[i].getAttribute("out");
						var inp = markers[i].getAttribute("in");
						var ctcss = markers[i].getAttribute("ctcss");
						var band = markers[i].getAttribute("band");
						var type = markers[i].getAttribute("type");
						var category = markers[i].getAttribute("type");
						var shift = markers[i].getAttribute("shift");
						var keeper = markers[i].getAttribute("keeper");
						var region = markers[i].getAttribute("region");
						var channel = markers[i].getAttribute("channel");
						var altitude = markers[i].getAttribute("altitude");
						var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),                            
						parseFloat(markers[i].getAttribute("lng")));    
						var marker = createMarker(map, point, callsign, qth, qra, out, inp, ctcss, band, type, shift, keeper, region, channel, altitude);    
						map.addOverlay(marker);  	
						GEvent.addListener(map, "zoomend", function() {
						  	var zoom = map.getZoom();
							 
							$("#zoomLevel").html("Zoom : " + zoom);
						});
				}
				show("analog");
				hide("digital");
				hide("television");
				hide("dualmode");
				hide("voice");
      });

	function showTooltip(marker){
			tooltip.innerHTML = marker.tooltip;
			var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
			var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
			var anchor=marker.getIcon().iconAnchor;
			var width=marker.getIcon().iconSize.width;
			var height=tooltip.clientHeight;
			var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height));
			pos.apply(tooltip);
			tooltip.style.visibility="visible";
	}

	function createMarker(map,point, callsign, qth, qra, out, inp, ctcss, band, type, shift, keeper, region, channel,altitude) {
			var icon = icon2a;
			var bandIcon = "gm2a";
			var bandStyle = "blue";
			
			if(band == "2M"){
				icon = icon2a; 
				bandIcon = "gm2a";
				bandStyle = "blue";				
				if(type == "digital"){icon = icon2d;bandIcon = "gm2d";};
				if(type == "dualmode"){icon = icon2dm;bandIcon = "gm2dm";};
			};
			
			if(band == "70CM"){
				icon = icon70a;
				bandIcon = "gm70a";
				bandStyle = "green";
				if(type == "digital"){icon = icon70d;bandIcon = "gm70d";};
				if(type == "dualmode"){icon = icon70dm;bandIcon = "gm70dm";};
			};
			
			if(band == "23CM"){
				icon = icon23a;
				bandIcon = "gm70d";
				bandStyle = "green";
				if(type == "digital"){icon = icon23d;bandIcon = "gm23d";};
				if(type == "dualmode"){icon = icon23dm;bandIcon = "gm23dm";};
				if(type == "television"){icon = icon23tv;bandIcon = "gm23tv";};
			};
			
			if(band == "13CM"){
				icon = icon13a;
				bandIcon = "gm13a";
				bandStyle = "green";
				if(type == "digital"){icon = icon13d;bandIcon = "gm13d";};
				if(type == "dualmode"){icon = icon13dm;bandIcon = "gm13dm";};
				if(type == "television"){icon = icon13tv;bandIcon = "gm13tv";};
			};
			
			if(band == "3CM"){
				icon = icon3a;
				bandIcon = "gm3a";
				bandStyle = "green";
				if(type == "digital"){icon = icon3d;bandIcon = "gm3d";};
				if(type == "dualmode"){icon = icon3dm;bandIcon = "gm3dm";};
				if(type == "television"){icon = icon3tv;bandIcon = "gm3tv";};
			};
									
			if(band == "6M"){icon = icon6a; bandIcon = "gm6a";bandStyle = "blue";};
			if(band == "10M"){icon = icon10a; bandIcon = "gm10a";bandStyle = "blue";};
			var tag = ctcss;;	
			if(type == "analog"){tag = ctcss + "Hz <span class='subData'>(CTCSS)</span>";}
			if(type == "digital"){tag = "GMSK";}	     	

			var marker = new GMarker(point,{icon:icon});
			marker.mycategory = type;                                 
			marker.myname = callsign;
			marker.mytype = type;
			marker.tooltip = '<div class="tooltip">'
							+ '<table>'
							+ '<tr><th>' + "<img style='vertical-align:middle;' src='" + icon.image + "'/>" + '<\/th><th><strong>' + callsign + '<\/strong><\/th><\/tr>'
							+ '<tr><td class="ttLabel">QTH<\/td><td>' + qth + '<\/td><\/tr>'
							+ '<tr><td class="ttLabel">Output<\/td><td>' + out + ' MHz<\/td><\/tr>'
							+ '<tr><td class="ttLabel">Shift<\/td><td>' + shift + ' MHz<\/td><\/tr>'
							+ '<tr><td class="ttLabel">Type<\/td><td>' + ucfirst(type) + '<\/td><\/tr>'
							+ '<tr><td class="ttLabel">Access<\/td><td>' + tag + '<\/td><\/tr>'
							+ '<tr><td colspan="2" id="ttSub"><img src="iconSW.png" \/>Click the Icon!<\/td><\/tr>'
							+ '<\/table>'
							+ '<\/div>';
				
			var html = "";
	 		html += "<table id='ajaxReturn'>";
	 		html += "<tr style='font-weight:bold;font-size:16px;letter-spacing:2px;height:32px;background:#222E1B;'>"
			 	 + "<td>"
			     + "<img style='text-align:center;vertical-align:middle;' src='" + icon.image + "'/>"
				  + "</td><td>"
			 	 + callsign + "</td></tr>";
	 		html += "<tr><td>Location</td><td><strong>" + qth + " " + qra + "</strong></td></tr>";
	 		html += "<tr><td>Region</td><td><strong>" + region + "</strong></td></tr>";
	 		html += "<tr><td>Elevation</td><td><strong>" + altitude + " ft <span class='subData'>(USGS Data)</span></strong></td></tr>";
	 		html += "<tr><td>Channel</td><td><strong>" + channel + "</strong></td></tr>";
	 		html += "<tr><td>Output</td><td><strong>" + out + "MHz</strong></td></tr>";
	 		html += "<tr><td>Input</td><td><strong>" + inp + "MHz</strong></td></tr>";
	 		
	 		
	 		html += "<tr><td>Split</td><td><strong>" + shift + "</strong></td></tr>";
	 		html += "<tr><td>Access</td><td><strong>" + tag + "</strong></td></tr>";
	 		html += "<tr><td>Type</td><td><strong>" + ucfirst(type) + "</strong></td></tr>";
	 		html += "<tr><td>Keeper</td><td><strong>" + keeper +  "</strong></td></tr>";	
	 		var callsignLowerCase = callsign.toLowerCase();
	 		html += "<tr><td>Coverage</td><td><a target='_blank' class='new-window' href='http://www.ukrepeater.net/repeaters/maps/" + callsignLowerCase + ".jpg'>ETCC Coverage Map</a></td></tr>";
	 		html += "<tr><td>ETCC Link</td><td><a target='_blank' class='new-window' href='http://www.ukrepeater.net/repeaters/" + callsignLowerCase + ".htm'>" + callsign + "</a></td></tr>";
	 		html += "<tr style='background:#222E1B;color:#eee;font-weight:bold;'><td>Access Tag</td><td>" + out + " " + shift + " " + tag + "</strong></td></tr>";
	 		html += "</table>";

			GEvent.addListener(marker, 'click', function() {        
				$("#currentStationDetail").hide().html(html).fadeIn(500);
				$("#ukFeedback").slideUp('500').html("");
				$("#instructionPara").hide();
					
			});
			GEvent.addListener(marker, 'dblclick', function() {        
				$("#currentStationDetail").html("");	
			});
   			GEvent.addListener(marker, 'mouseover', function() {        
				$("#currentStation").html("" + callsign + " <span class='small'>(Click for More)").fadeIn(500);
				showTooltip(marker);
				//$(".tooltip").slideDown(100).css('opacity', 0.8);
					
			});
			GEvent.addListener(marker, 'mouseout', function() {        
				$("#currentStation").html("");
				//tooltip.style.visibility="hidden";
				$(".tooltip").slideUp(200);	
			});	
        gmarkers.push(marker);
        return marker;
      }//fn.createMarker
      
		function show(category) {
			for (var i=0; i<gmarkers.length; i++) {
		 		if (gmarkers[i].mycategory == category) {
		    		gmarkers[i].show();
				}
			}
			var cat = category+"box";
			var el = document.getElementById(cat);
			el.checked = true;
			$("label[for='" + cat + "']").attr('class', 'checked'); 
		}

      function hide(category) {
        for (var i=0; i<gmarkers.length; i++) {
          if (gmarkers[i].mycategory == category) {
            gmarkers[i].hide();
          }
        }
        var cat = category+"box";
			var el = document.getElementById(cat);
			el.checked = false;
			$("label[for='" + cat + "']").attr('class', 'unchecked');
        map.closeInfoWindow();
      }

      function boxclick(box,category) {
        if (box.checked) {
          show(category);
        } else {
          hide(category);
        }
      }

      function myclick(i) {
        GEvent.trigger(gmarkers[i],"click");
      }

      // init the mappy wappy
		var map = new GMap2(document.getElementById("map"));
		map.addMapType(G_PHYSICAL_MAP);
		map.setMapType(G_PHYSICAL_MAP);  
		map.addMapType(G_NORMAL_MAP);
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0,40));
		map.addControl(new GLargeMapControl3D(), pos);	       
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		var geoco = new GLatLng(57.214495, -2.341861);
		map.setCenter(new GLatLng(57.214495, -2.341861), 8);
		//map.enableScrollWheelZoom();
		map.enableContinuousZoom();
		map.addCrosshairs();
		var pos = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,150)); 
		map.addControl(new GScaleControl(), pos);
		var tooltip = document.createElement("div");
		map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);
		tooltip.style.visibility="hidden";
		var minMapScale = 5; 
		var maxMapScale = 18;
		var mapTypes = map.getMapTypes(); 
		// overwrite the getMinimumResolution() and getMaximumResolution() methods
		for (var i=0; i<mapTypes.length; i++) { 
		mapTypes[i].getMinimumResolution = function() {return minMapScale;} 
		mapTypes[i].getMaximumResolution = function() {return maxMapScale;} 
		}
				
		function formatCall(row) {
			return "<b>" + row[0] + "</b> - <span>" + row[1] + "</span>";
		}
		function formatQth(row) {
			return "<b>" + row[0] + "</b> - <span>" + row[1] + "</span>";
		}
		function submitCall(){$("#ukRepeaterSubmit").click();}
		function submitQth(){$("#ukQthSubmit").click();}
		
		$("#callsign").autocomplete("/ajax/ukStationsAc.php", { minChars:2, cacheLength: 1,matchSubset: false, formatItem: formatCall, onItemSelect: submitCall, extraParams: {type: 'call'} });
		$("#qth").autocomplete("/ajax/ukStationsAc.php", { minChars:1, cacheLength: 12, delay:200,matchSubset: false,  formatItem: formatQth, onItemSelect: submitQth, extraParams: {type: 'qth'} });
			
/**  UK Repeater Searches **/
	
	function ukRepeaterSearch(){
		var param = $("#repeaterSearchForm").serialize();
		$("#ukFeedback").slideUp('500');
		$("#instructionPara").hide('200');
		$("#loader").animate({opacity:1.0},100).html("<img src='spinWorking.png' class='loaderPNG' />");
		$("#callsign").addClass("callsignActive");
		$.ajax({
			url: '/ajax/GMukRepeaterSearch.php',
			data: param,
			type: 'POST',
			success: function(res){
						if(res == "Error"){
							$("#ukFeedback").html("Not Found!");
						}else{
							var tmp = res.split("|");
							var lat = tmp[0];
							var lng = tmp[1];
							var type = tmp[2];
							var callsign = tmp[3];
							var coords = new GLatLng(lat,lng);
							map.setZoom(11);
							map.panTo(coords);
							var message = "<strong>Action:-<\/strong>&nbsp;";
							message += "Map Centered on <strong>" + callsign + "<\/strong> ";
							var cType = document.getElementById(type+"box").checked;
							if(cType == false){
								show(type);
								message += " and '<strong>" + ucfirst(type) + "<\/strong>' Overlay Selected. &nbsp; ";
							}
							message += " Click Map Icon for full details.";
							 
							$("#ukFeedback").slideDown().html(message);
							$("#loader").animate({opacity:0.5},250).html("<img src='spinWorking.png' class='loaderPNG' />");
							$("#loader").animate({opacity:0.5},1000).html("<img src='spinIdle.png' class='loaderPNG' />");
							$("#callsign").removeClass("callsignActive");
						}
					 },
			error: function(){
						$("#ukFeedback").html("Something went very very wrong!");
					}
		});
	}
	
	$("#ukRepeaterSubmit").click(function(){
		ukRepeaterSearch();
		return false;
	});

	$("#loader").html("<img src='spinIdle.png' class='loaderPNG' />");
	
	}else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
 }