
	window.onload = onPageLoad;
	var map;

	function onPageload(county) {
		if (GBrowserIsCompatible()) {
		  		  
			var counties = new Array();		
			counties['kent'] = [51.486514,0.977783, 9];		
		
			var selected_county = counties[county];
		  
			map = new GMap2(document.getElementById("map"));
				
			if (selected_county == undefined) {
				/* check for saved cookie */
				data=readCookie('ukweathercams');			

				if (data != null) {
					values = data.split(",");
					//alert(values[0]+" "+values[1]+" "+values[2]);
					map.setCenter(new GLatLng(parseFloat(values[0]),parseFloat(values[1])),parseInt(values[2]));
				}
				else {				
					map.setCenter(new GLatLng(54.300014,-2.922363), 6);
				}
			}				
			else {
				map.setCenter(new GLatLng(selected_county[0],selected_county[1]), selected_county[2]);	
			}
      
			map.setMapType(G_SATELLITE_MAP);
			var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(8,25));
		
			var extLargeMapControl = new ExtLargeMapControl();
    	    map.addControl(extLargeMapControl, bottomRight);		
					
var sites = [					 
["Isle Of Sheppey Sailing Club","http://www.iossc.org.uk/weather/index.php?n=3", 51.44037461742552, 0.7785245776176453],
["Hythe and Saltwood Sailing Club","http://www.s119568945.websitehome.co.uk/weathercentral3.htm", 51.066741, 1.088520],
["Sandwich","http://www.sandwichonline.info/", 51.280817,1.338615],
["Harwich","http://www.harwichweather.eu/", 51.951566, 1.290035],
["Bexhill Sailing Club","http://www.bexwatch.co.uk/", 50.878561,0.487518],
["Dracote Water Sailing Club","http://www.draycotewater.co.uk/weather/", 52.325006,-1.311665],
["Headcorn","http://www.headcorn.org/html/weather_webcam.html", 51.197633,0.636864],
["Rainham", "http://www.shaggysworld.com/wdlive/index.html", 51.37028,0.630684],
["Worthing", "http://seaspritesports.com/weather-cams-stream.php", 50.843237,-0.354652],
["Whitstable Yacht Club", "http://www.wyc.org.uk/flattened/home_webcam.php", 51.3621833397043, 1.025274395942688],
["Whitstable Marine", "http://www.whitstablemarine.co.uk/weather.asp", 51.36224865524542, 1.0259073972702026],
["Broadstairs","http://www.stella-maris.org.uk/mml/wxindex1.shtml", 51.36385, 1.438866],
["Borard-Worx, Whitstable", "http://www.board-worx.com/liveweather/", 51.364466,1.032114],
["Datchet Water Sailing Club", "http://www.dwsc.co.uk/live_weather.php", 51.490896, -0.529404],
["Sandettie Lightship","http://www.ndbc.noaa.gov/station_page.php?station=62304",51.122489,1.804504],
["Station 62125","http://www.ndbc.noaa.gov/station_page.php?station=62125", 53.875202,-3.510132],
["Greenwich Lightship","http://www.ndbc.noaa.gov/station_page.php?station=62305", 50.41026792102014, 0],
["Sevenstones Lightship", "http://www.ndbc.noaa.gov/station_page.php?station=62107",50.10274427610123, -6.10015869140625],
["Channel Lightship","http://www.ndbc.noaa.gov/station_page.php?station=62103",49.900052680341155, -2.8997039794921875],
["M5 Buoy","http://www.ndbc.noaa.gov/station_page.php?station=62094", 51.689904256812554, -6.703891754150391],
["K7 Buoy","http://www.ndbc.noaa.gov/station_page.php?station=64046",60.70116441036431, -4.499931335449219],
["Station 62144, North Sea", "http://www.ndbc.noaa.gov/station_page.php?station=62144", 53.400116832693065, 1.7003059387207031],
["Station 62145, North Sea", "http://www.ndbc.noaa.gov/station_page.php?station=62145", 53.10288830390625, 2.800140380859375],
["Station 62142, North Sea","http://www.ndbc.noaa.gov/station_page.php?station=62142", 53.000336,2.101028],
["Tonbridge", "http://www.tonbridge-weather.org.uk/weathercam.htm", 51.196665239562826, 0.27431488037109375],
["M4 - Donegal Bay","http://www.ndbc.noaa.gov/station_page.php?station=62093", 54.67065452767033, -9.0692138671875],
["Herne Bay Sailing Club", "http://www.hernebaysailingclub.co.uk/live-weather", 51.37281849692684, 1.1390483379364014],
["New Biggin Sailing Club", "http://www.newbigginsailingclub.org/sailing/webcam/webcam.html", 55.191314,-1.505814],
["Stokes Bay Sailing Club", "http://www.stokesbay-sc.co.uk/weather.php", 50.782212,-1.154509],
["Aberdeen", "http://www.aberdeencity.gov.uk/xwc_WebcamList.asp",57.245623,-2.028351],
["Chimet", "http://www.chimet.co.uk/", 50.782063, -0.940704],
["Cambermet, Chichester Harbour", "http://www.cambermet.co.uk/", 50.80343959160811, -0.9087753295898438],
["Bramblemet, Bramble Bank", "http://www.bramblemet.co.uk/", 50.780326138892775, -1.2974166870117188],
["Sotonmet, Southampton ", "http://www.sotonmet.co.uk/",50.88180989329177, -1.3921737670898438],
["Royal Lymington Yacht Club", "http://www.rlymyc.org.uk/More/webcams.html", 50.7543437797544, -1.5285158157348633],
["Shoreham", "http://www.shorehambeachweather.co.uk/", 50.827544614133764, -0.2678346633911133],
["Portland Harbour","http://www.weather-file.com/portland/", 50.5850316334852, -2.4141865968704224],
["Hurst Castle","http://www.weather-file.com/hurst/",50.716406307953505, -1.5761947631835938],
["Scaling Dam Sailing Club", "http://scalingdam.org/WeatherVigil/Live/index.htm", 54.50295363678442, -0.8578240871429443],
["Warsash Sailing Club", "http://www.aqqs83.dsl.pipex.com/WSC_Pro_Plus.htm", 50.85320522211456, -1.3072657585144043],
["Rutland Sailing Club","http://rutlandsc.co.uk/rutlandsailingclub.htm", 52.64027705593024, -0.6393742561340332],
["Dabchicks Sailing Club", "http://www.dabchicks.org/weather/WeatherReport.php", 51.78033376037005, 0.8986017107963562],
["Poole Yacht Club", "http://www.pooleyc.co.uk/cms/index.asp?dir=101&Page=Live+Weather", 50.722152886006896, -2.0036208629608154],
["Bala Sailing Club", "http://www.balasc.org.uk/weather.html", 52.900704905782, -3.5966143012046814],
["Aldenham Sailing Club", "http://www.aldenhamsc.co.uk/attheclub/webcam.html", 51.64562692527086, -0.3090360760688782],
["Burnham on Crouch", "http://www.burnhamoncrouchweather.com/wxlive.php", 51.62600970290608, 0.8215713500976562],
["South Caernarvonshire Yacht Club","http://www.scyc.co.uk/webcams.asp", 52.824040780043546, -4.5000386238098145],
["Burghfield Sailing Club", "http://www.burghfieldsailing.org/weather/", 51.42854440775405, -1.0639142990112305],
["Fishers Green Sailing Club", "http://www.fishersgreensc.org.uk/weather/allstats2.php", 51.72054497277978, -0.0037282705307006836],
["Blackwater Sailing Club", "http://www.blackwatersailingclub.co.uk/bsc03/weather-display/index.asp", 51.73424130977673, 0.7142990827560425],
["Iwade", "http://gorrie.zapto.org/", 51.38005789925143, 0.728917121887207],
["Queen Mary Sailing Club","http://85.91.57.190/pagebuild/Local/pagebuild.cgi?PAGE=../std-files/static4.conf&MENU=0&SITE=Local&SUB=../br_oggle/vars.sub&SITENAME=Reservoir", 51.42275108609216, -0.4554927349090576],
["Weir Wood Sailing Club", "http://www.wwsc.org.uk/webcam.htm", 51.09809176315004, 0.00909268856048584],
["Royal Norfolk &amp; Suffolk Yacht Club", "http://www.rnsyc.net/news.php", 52.472063387553085, 1.7502593994140625],
["Maidenhead Sailing Club", "http://www.maidenheadsc.org.uk/main/content/view/47/75/", 51.53494440735916, -0.7109034061431885],
["Boothferry Park, Hull", "http://www.cwuhull.karoo.net/", 53.763325,-0.328217],
["Grafham Water Sailing Club", "http://www.grafham.org/?page_id=48", 52.291367575702346, -0.31497716903686523],
["Hayling Island Surf Cam", "http://www.hayling.co.uk/surfcam/", 50.78464043237572, -0.988919734954834],
["Wroxham Bridge","http://www.norfolkwebcams.com/camera/wroxham-bridge", 52.71162532129838, 1.4075589179992676],
["Dun Laoghaire Harbour","http://www.dlharbour.ie/webcam/dlh1.php", 53.29692061562852, -6.133224964141846],
["Highcliffe Sailing Club", "http://www.weather-file.com/highcliffe/", 50.724482562635835, -1.7419713735580444],
<!--["", "http://www.bssc.net/webcam_new.htm",52.966615,0.666612], out of date-->
["Abersoch (West Coast Surf Shop)", "http://www.westcoastsurf.co.uk/webcam.htm",52.825328,-4.504073],
["Looe","http://www.looe.co.uk/webcam/webcam.htm", 50.35203276986297, -4.454612731933594],
["Abersoch", "http://www.abersochholidays.co.uk/accweb.html",52.922979,-4.488602],
["Starcross Yacht Club","http://www.starcrossyc.org.uk/syc1/index.php?option=com_wrapper&view=wrapper&Itemid=87",50.626924338112914, -3.4474754333496094],
["Fife", "http://www.fifeweather.co.uk/weathercam.php",56.132159,-3.310146],
["Cambridge University", "http://www.bbc.co.uk/cambridgeshire/content/webcams/cambridge_uni_tower_webcam.shtml", 52.20413512006535, 0.11964797973632812],
["Old Windsor", "http://www.oldwindsorweather.dyndns.org/",51.484804,-0.569916],
["Torbay", "http://www.torbay.gov.uk/torquay-webcam.htm",50.451766037915625, -3.5576820373535156],
["Langland","http://www.gowerlive.co.uk/langlandwebcam.php",51.56992135385942, -4.003143310546875],
["Oxford Sailing Club","http://www.oxfordsailingclub.com/weather-info/osc-web-cam",51.75327704134268, -1.3484430313110352],
["Bollington", "http://www.auwo89.dsl.pipex.com/",53.300364,-2.105942],
["Portpatrick", "http://www.gmercer-gm4bes.co.uk/current_vantage_pro.html",54.863963,-5.112762],
["London Gliding Club", "http://www.londonglidingclub.co.uk/webcam.xml",51.8717, -0.551233],
["St. Ives", "http://www.nci-stives.org/activexcamera.htm",50.216582,-5.478208],
["Lasham", "http://www.lashamweather.co.uk/webcam.php",51.191824,-1.026535],
["Blakeney ", "http://www.glavenvalley.co.uk/pages/else/webcam.php", 52.954986,1.018188],
["Rhosneigr Beach", "http://www.camserv.co.uk/rhos/index.htm", 53.229005,-4.522526],
["Olympic Village", "http://www.london2012.com/plans/olympic-park/webcams/olympic-village.php",51.530426,-0.001888],
["Chilthorne Domer", "http://www.chilthorneweather.co.uk/",50.969671,-2.689075],
["Saunton", "http://www.eyeball-surfcheck.co.uk/saunton.html",51.119687,-4.205532],
["Newtown", "http://www.newtownweather.co.uk/webcam.html", 52.557986,-3.312378],
["Tramore", "http://www.surftbay.com/beachcam.php", 52.161876,-7.1521],
["Ramsgate Marina", "http://www.portoframsgate.co.uk/portoframsgate/welcome_to_the_marina/web_cam.aspx", 51.33222, 1.4217],
["Cowes Harbour", "http://www.cowesharbourweather.com/webcam.aspx", 50.763825,-1.299047],
["Felixstowe Ferry Sailing Club", "http://www.ffsc.co.uk/ffsc/ffscweather1.htm", 51.989056, 1.390886],
["Haverfordwest", "http://www.broadhavenholidaypark.com/cam.php",51.784555,-5.097506],
["Clevedon", "http://www.clevedonweather.co.uk/",51.438815,-2.85284],
["Eoropie", "http://www.eoropaidh.co.uk/webcam/webcam.htm",58.503034,-6.263838],
["Douglas Harbour", "http://www.visitisleofman.com/webcam/webcam.aspx?webcam=4",54.1475,-4.480265],
["Exmouth", "http://www.exmouthcam.co.uk/webcam/",50.625073,-3.411942],
["Bewl Valley Sailing Club", "http://www.bewlvalleysc.co.uk/abo_content_detail_p.php/116/Web+camera", 51.082364,0.393491],
["Thorpe Bay Yacht Club", "http://www.tbyc.org/weather-station/", 51.527779, 0.765360]
];
						
		function createMarker(tip, url, lat, lng) {
			var marker = new PdMarker(new GLatLng(lat, lng));
	  
			if (tip != "") marker.setTooltip(tip);
			marker.setHoverImage("imgs/yellow_marker.png");
	  
			GEvent.addListener(marker,"click", function() {
				window.open(url);
			});
			
			return marker;
		}								
		
		for (var i=0; i<sites.length; i++) {

			var subsite = sites[i];	
			
			marker = createMarker(subsite[0], subsite[1], subsite[2], subsite[3]);
			map.addOverlay(marker);			

		}
						
    }
   }
   
   function saveMap() {		
		var z = map.getZoom();
		var p = map.getCenter();
		
		data = p.lat() +","+p.lng()+","+z;
		alert("Current map position and zoom level have been saved to a cookie and \nwill be automatically reloaded on your next visit.");
		
		setCookie('ukweathercams',data,60);		
	}
	
	function setCookie(c_name,value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +value+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}