var areaamenities = [];

	
function gload() {
	
}


function showMap(mapid, c1, c2) {

	if (GBrowserIsCompatible()) {
		elmap = document.getElementById(mapid);
		if (!elmap) return false;

		var map = new GMap2(elmap);
		var point = new GLatLng(c1,c2);
//		map.addControl(new GLargeMapControl());
//		map.addControl(new GMapTypeControl());
		map.setCenter(point, 11);


//	  function createMarker(point, txt) {
//		var marker = new GMarker(point);
//		GEvent.addListener(marker, "click", function() {
//		  marker.openInfoWindowHtml(txt);
//		});
//		return marker;
//	  }
	  

	}
}



var map;
var directionsPanel;
var directions;
function getDirections(id) { 
	code = document.getElementById("postcode");
	el = document.getElementById("map2");
	el.style.display = "block";
	el.innerHTML = "";
	map = new GMap2(document.getElementById("map1"));
	  var point = new GLatLng(points[id][0], points[id][1]);
	  map.addControl(new GLargeMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setCenter(point, 15);
	directions = new GDirections(map, el); 
	directions.load("from: "+code.value+" to: "+points[id][0] +","+ points[id][1]+"");
	if (getQueryVariable("s") == "directions") {
			GEvent.addListener(directions, "addoverlay", function() { 
			  window.print();
			});		
	} else {
			GEvent.addListener(directions, "addoverlay", function() { 
				el = document.getElementById("map2");
				el.innerHTML = '<br><a href="#self" onclick="printDirections(2);" class="orange2">Print directions </a><br>' +el.innerHTML ;
			});		
	}
}

function showStreetView(id) {
	var myPoint = new GLatLng(points[id][0], points[id][1]); panoramaOptions = { latlng:myPoint };
	var myPano = new GStreetviewPanorama(document.getElementById("map1"), panoramaOptions);	

}


function printDirections(id) {
	code = document.getElementById("postcode");
	d= window.open("index.php?s=directions&id=" + id + "&postcode=" + code.value, "Directions", "width=600, height=1000");
	d.write("Directions");
}

function showAreaAmenities() {

	if (GBrowserIsCompatible()) {
	  var map = new GMap2(document.getElementById("map1"));
	  var point = new GLatLng(43.67675,-79.380000);
	  map.addControl(new GLargeMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setUIToDefault();
	  map.setCenter(point, 12);
//	  map.setMapType(G_HYBRID_MAP);
	  map.enableRotation();

//if (id == 2)
//{
//
//		var cafeIcon = new GIcon(); 
//		cafeIcon.image = "http://preview.thebrandfactory.com/viva/v2/images/icon_waterside2.png"; 
////		cafeIcon.shadow = "http://preview.thebrandfactory.com/viva/v2/images/icon_waterside_shadow.png"; 
//		cafeIcon.iconSize = new GSize(109, 84); 
////		cafeIcon.shadowSize = new GSize(96, 48); 
//		cafeIcon.iconAnchor = new GPoint(24, 10); 
//		cafeIcon.infoWindowAnchor = new GPoint(24, 1); 
//		// Set up our GMarkerOptions object literal 
//		markerOptions = { icon:cafeIcon };
//		var point = new GLatLng(points[id][0], points[id][1]); 
//		map.addOverlay(new GMarker(point, markerOptions)); 
//} else {
//	  var point = new GLatLng(points[id][0], points[id][1]); map.addOverlay(createMarker(point, "Head Office"));
//}

	  function createMarker(point, txt, icontouse) {
		markerOptions = { icon:icontouse};
		var marker = new GMarker(point, markerOptions);
		GEvent.addListener(marker, "click", function() {
		  marker.openInfoWindowHtml(txt);
		});
		return marker;
	  }

		var pastIcon = new GIcon(); pastIcon.image = "http://preview.thebrandfactory.com/plaza/images/legend-past.png"; 
		pastIcon.iconSize = new GSize(26, 26); pastIcon.iconAnchor = new GPoint(1, 1);  pastIcon.infoWindowAnchor = new GPoint(13, 13); 

		var presentIcon = new GIcon(); presentIcon.image = "http://preview.thebrandfactory.com/plaza/images/legend-present.png"; 
		presentIcon.iconSize = new GSize(26, 26); presentIcon.iconAnchor = new GPoint(1, 1);  presentIcon.infoWindowAnchor = new GPoint(13, 13); 

		var futureIcon = new GIcon(); futureIcon.image = "http://preview.thebrandfactory.com/plaza/images/legend-future.png"; 
		futureIcon.iconSize = new GSize(26, 26); futureIcon.iconAnchor = new GPoint(1, 1);  futureIcon.infoWindowAnchor = new GPoint(12, 16); 

//		cafeIcon.shadow = "http://preview.thebrandfactory.com/viva/v2/images/icon_waterside_shadow.png"; 
//		cafeIcon.shadowSize = new GSize(26, 26); 
		// Set up our GMarkerOptions object literal 
		

		var myicon;
		for (i in areaamenities)
	  {

		switch (areaamenities[i][4])
		{
			case "past": myicon = pastIcon; break;
			case "active": myicon = presentIcon; break;
			case "coming": myicon = futureIcon; break;
			case "future": myicon = futureIcon; break;
			default: myicon = futureIcon; break;
		}
		point2 = new GLatLng(areaamenities[i][1], areaamenities[i][2]); 
		txt = "";
		commImage =   "";
		switch (areaamenities[i][4])
		{
		case "past":
			if (areaamenities[i][7]) commImage = "<img src='"+ areaamenities[i][7] + "' style='float: left;margin: 0 10px 0px 0px'>";
			txt = "<div style='width: 400px; height: 150px;'><h2 class='gmap'>"+ areaamenities[i][0] + "</h2><div class='gmap'>" + commImage  + areaamenities[i][3] + "</div></div>";
			break;
		case "active":
			if (areaamenities[i][6]) commImage = "<img src='"+ areaamenities[i][6] + "' style='float: left;margin: 0 10px 0px 0px'>";
			txt = "<div style='width: 400px;'><a href='index.php?s=community-"+areaamenities[i][5]+"'><h2 class='gmap'>" + areaamenities[i][0] + "</h2></a><div class='gmap'>" + commImage  + areaamenities[i][3] + "</div></div>";
			break;
		case "future":
		case "coming":
			if (areaamenities[i][6]) commImage = "<img src='"+ areaamenities[i][6] + "' style='float: left;margin: 0 10px 0px 0px'>";
			txt = "<div style='width: 400px;;'><a href='index.php?s=community-"+areaamenities[i][5]+"'><h2 class='gmap'>" + areaamenities[i][0] + "</h2></a><div class='gmap'>" + commImage  + areaamenities[i][3] + "</div></div>";
			break;
		}
//		if (areaamenities[i][4] != "past")
//		{
//			txt = "<div style='width: 400px;'><a href='index.php?s=community-"+areaamenities[i][5]+"'><h2 class='gmap'>" + areaamenities[i][0] + "</h2></a><div class='gmap'>" + areaamenities[i][3] + "</div></div>";
//		} else {
//			txt = "<div style='width: 400px;'><h2 class='gmap'>" + areaamenities[i][0] + "</h2><div class='gmap'>" + areaamenities[i][3] + "</div></div>";
//		}
//		if (areaamenities[i][3])
//		{
//			txt = txt + "<br>" + "<center><img src='images/neighbourhood/" + areaamenities[i][3] + "' style=''></center>";
//		}
		map.addOverlay(createMarker(point2, txt,myicon));


	  }

	}

}
