// Google map script for Portmoak
// Copyright © Portmoak Community Council 2009
//

//load map API dynamically (async) and then map - also allows us take account of different domains/keys
function initialize()
{
	var script = document.createElement("script");
  	script.type = "text/javascript";
  	script.src = "http://maps.google.com/maps?file=api&v=2.x&key=" + getGKey() + "&async=2&callback=loadMap";
  	document.body.appendChild(script);
}

//Get appropriate Google key for different domains
function getGKey(){
    exp = new RegExp("portmoak.org|portmoak.co.uk");
    var domain = exp.exec(location.href);

    if (domain == "portmoak.co.uk")
        { return ("ABQIAAAAbLlyTWZwR_K19rhZHDRTqhT9XUCPDQqmECtR612pHLH2MInQXxSBBixwtdddSunbVsrmj2mmDqyuew") }
    else if (domain == "portmoak.org")
        { return ("ABQIAAAAbLlyTWZwR_K19rhZHDRTqhQ-TeSnF0DfknbJC8tj8xWf70Q5sxSEzzlVVQAclGExjiHwg95Mwa1gMw") }
    else { alert("Invalid domain / key"); return; }
}

function getIcon() {
  var icon = new GIcon();

  icon.image = "images/Home.png";
  icon.shadow="images/shadow-Home.png";
  
  icon.iconSize = new GSize(32, 32);
  icon.iconAnchor = new GPoint(15, 32);
  return icon;
}	

    
function loadMap() {
      if (GBrowserIsCompatible()) 
	  {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(56.203772 ,-3.331432), 12);
		map.setUIToDefault();      


		//Portmoak boundary
		var points=
		[
		new GLatLng (56.23915268736493,-3.3649063110351562),
		new GLatLng (56.24029743391525,-3.354949951171875),
		new GLatLng (56.23724470041033,-3.332977294921875),
		new GLatLng (56.236481479014856,-3.319244384765625),
		new GLatLng (56.238580301258544,-3.3130645751953125),
		new GLatLng (56.233237618417704,-3.2904052734375),
		new GLatLng (56.23304679453367,-3.28216552734375),
		new GLatLng (56.231520169241456,-3.2804489135742187),
		new GLatLng (56.22846673614638,-3.2897186279296875),
		new GLatLng (56.22369525974297,-3.2886886596679687),
		new GLatLng (56.2221682618065,-3.2718658447265625),
		new GLatLng (56.21815960273243,-3.2639694213867187),
		new GLatLng (56.21319592010918,-3.267059326171875),
		new GLatLng (56.2124322195806,-3.2742691040039062),
		new GLatLng (56.20135685223722,-3.2701492309570312),
		new GLatLng (56.20135685223722,-3.2660293579101562),
		new GLatLng (56.19448087726972,-3.2622528076171875),
		new GLatLng (56.18492886719585,-3.3099746704101562),
		new GLatLng (56.179578702856986,-3.3061981201171875),
		new GLatLng (56.178049947492596,-3.29864501953125),
		new GLatLng (56.176712236605475,-3.3003616333007812),
		new GLatLng (56.17499225411259,-3.2965850830078125),
		new GLatLng (56.173272194560944,-3.2941818237304687),
		new GLatLng (56.17155205794858,-3.297271728515625),
		new GLatLng (56.16964070466387,-3.3072280883789062),
		new GLatLng (56.16868499234355,-3.3065414428710937),
		new GLatLng (56.16620002899272,-3.3175277709960937),
		new GLatLng (56.171934317188786,-3.3243942260742187),
		new GLatLng (56.17308107207619,-3.3305740356445312),
		new GLatLng (56.17288994864004,-3.3377838134765625),
		new GLatLng (56.173272194560944,-3.3443069458007812),
		new GLatLng (56.17174318804438,-3.3484268188476562),
		new GLatLng (56.16849384702521,-3.3559799194335937),
		new GLatLng (56.16696465022672,-3.3638763427734375),
		new GLatLng (56.16524423104225,-3.3707427978515625),
		new GLatLng (56.16581771266693,-3.37554931640625),
		new GLatLng (56.16524423104225,-3.39202880859375),
		new GLatLng (56.167346955135,-3.3923721313476562),
		new GLatLng (56.17155205794858,-3.3995819091796875),
		new GLatLng (56.17365443667635,-3.3995819091796875),
		new GLatLng (56.176330024933016,-3.3892822265625),
		new GLatLng (56.18225387824831,-3.3834457397460937),
		new GLatLng (56.18292264296403,-3.381471633911133),
		new GLatLng (56.183209252846474,-3.380098342895508),
		new GLatLng (56.18213445475144,-3.3782529830932617),
		new GLatLng (56.18180006698338,-3.3761072158813476),
		new GLatLng (56.180653572519134,-3.3738327026367187),
		new GLatLng (56.18027140008764,-3.371429443359375),
		new GLatLng (56.18062968685364,-3.3683395385742187),
		new GLatLng (56.18153733169337,-3.366107940673828),
		new GLatLng (56.18120293872317,-3.363618850708008),
		new GLatLng (56.18053414404304,-3.3621597290039062),
		new GLatLng (56.17881433278511,-3.358898162841797),
		new GLatLng (56.17824104524266,-3.3546066284179687),
		new GLatLng (56.17938761176594,-3.3477401733398437),
		new GLatLng (56.178909879876485,-3.3422470092773437),
		new GLatLng (56.17924429282339,-3.338298797607422),
		new GLatLng (56.17981756538306,-3.3352088928222656),
		new GLatLng (56.180104198452334,-3.333406448364258),
		new GLatLng (56.181059626558415,-3.332204818725586),
		new GLatLng (56.183925768188956,-3.3310890197753906),
		new GLatLng (56.185788645477494,-3.3309173583984375),
		new GLatLng (56.18808129339414,-3.3319473266601562),
		new GLatLng (56.18913204458089,-3.335723876953125),
		new GLatLng (56.19123346063798,-3.34259033203125),
		new GLatLng (56.1950539222603,-3.343963623046875),
		new GLatLng (56.2000199536332,-3.346710205078125),
		new GLatLng (56.20479437753578,-3.3498001098632812),
		new GLatLng (56.208422542208474,-3.354949951171875),
		new GLatLng (56.21185943420043,-3.3607864379882812),
		new GLatLng (56.21415052437646,-3.3625030517578125),
		new GLatLng (56.21968676038894,-3.3594131469726562),
		new GLatLng (56.22388613020696,-3.3614730834960937),
		new GLatLng (56.224649602556184,-3.368682861328125),
		new GLatLng (56.227130782643684,-3.371429443359375),
		new GLatLng (56.230756833781776,-3.3745193481445312),
		new GLatLng (56.23247431717827,-3.3693695068359375),
		new GLatLng (56.23915268736493,-3.3649063110351562)
		];


		//var polyline=new GPolyline(points, '#FF0000', 4);
		var polygon=new GPolygon(points, "#ff0000", 3, .5, "#ff0000", 0.05);
		map.addOverlay(polygon);		
		
		//Markers for Portmoak settlements
		var markers=
		[
		 {desc:"Glenlomond", coords:new GLatLng(56.23002926551517, -3.3409595489501953)},
		 {desc:"Wester Balgedie", coords:new GLatLng(56.22278861205632, -3.346238136291504)},
		 {desc:"Easter Balgedie", coords:new GLatLng(56.21732441265195, -3.337569236755371)},	
		 {desc:"Kinnesswood ", coords:new GLatLng(56.21213389492959, -3.3294153213500976)},
		 {desc:"Scotlandwell", coords:new GLatLng(56.200330309248024, -3.31437349319458)}
 		 
		];
		
		var marker;
		for (i=0; i<markers.length;i++)
		{
      		marker = new GMarker( markers[i].coords, {icon: getIcon(), draggable: false, title:markers[i].desc});
      		map.addOverlay(marker);		
		}	
			
      } //if
		
      } //initialize


