
	// Shamrock Front-End Maps
	//-------------------------------
	
	// Global Variables + (Inherited from Document : v_case,v_cid,v_c_lat,v_c_lng,v_dae,v_weeks)
	var map;

	// Begin Google Maps
	google.load("maps","2");
	google.setOnLoadCallback(f_map_load);

	function f_map_load() {
		// Initialise Map
		switch (v_case) {
			case 1 : // Small Map with Single Marker for Property Details
				map = new google.maps.Map2(document.getElementById("gmap-small"));
				v_c_zoom = 14;
			break;
			case 2 : // Large Map with Many Markers for Counties and Search Pages
				map = new google.maps.Map2(document.getElementById("gmap-large"));
				v_c_lat = "53.425970"; //set default
				v_c_lng = "-7.897460";
				v_c_zoom = 6;
				if (v_cid == "1") { //wicklow
					v_c_lat = "53.10624";
					v_c_lng = "-6.05545";
					v_c_zoom = 8;
				}
				else if (v_cid == "2") { //waterford
					v_c_lat = "52.140638";
					v_c_lng = "-7.79428";
					v_c_zoom = 8;
				}
				else if (v_cid == "3") { //wexford
					v_c_lat = "52.184917";
					v_c_lng = "-6.368061";
					v_c_zoom = 8;
				}
				else if (v_cid == "4") { //kilkenny
					v_c_lat = "52.489138";
					v_c_lng = "-7.065128";
					v_c_zoom = 8;
				}
				else if (v_cid == "5") { //cork
					v_c_lat = "51.735411";
					v_c_lng = "-9.558897";
					v_c_zoom = 8;
				}	
				else if (v_cid == "6") { //tipparary
					v_c_lat = "52.281763";
					v_c_lng = "-7.95405";
					v_c_zoom = 8;
				}
				else if (v_cid == "7") { //offaly
					v_c_lat = "53.000428";
					v_c_lng = "-7.93127";
					v_c_zoom = 8;
				}
				else if (v_cid == "8") { //roscommon
					v_c_lat = "53.772673";
					v_c_lng = "-8.511939";
					v_c_zoom = 8;
				}	
				else if (v_cid == "9") { //limerick
					v_c_lat = "52.413005";
					v_c_lng = "-8.726797";
					v_c_zoom = 8;
				}	
				else if (v_cid == "10") { //clare
					v_c_lat = "52.59926";
					v_c_lng = "-9.768962";
					v_c_zoom = 8;
				}
				else if (v_cid == "11") { //galway
					v_c_lat = "53.268262";
					v_c_lng = "-9.60933";
					v_c_zoom = 8;
				}		
				else if (v_cid == "12") { //mayo
					v_c_lat = "53.901678";
					v_c_lng = "-9.705726";
					v_c_zoom = 8;
				}	
				else if (v_cid == "13") { //sligo
					v_c_lat = "54.334565";
					v_c_lng = "-8.354236";
					v_c_zoom = 8;
				}		
				else if (v_cid == "14") { //donegal
					v_c_lat = "54.867510";
					v_c_lng = "-8.129070";
					v_c_zoom = 8;
				}
				else if (v_cid == "15") { //kerry
					v_c_lat = "51.954932";
					v_c_lng = "-10.257739";
					v_c_zoom = 8;
				}
				else if (v_cid == "16") { //cavan
					v_c_lat = "53.989404";
					v_c_lng = "-7.370453";
					v_c_zoom = 8;
				}
				else if (v_cid == "100") { //Dublin
					v_c_lat = "53.339404";
					v_c_lng = "-6.270453";
					v_c_zoom = 8;
				}
			break;
		}
		map.setMapType(G_PHYSICAL_MAP);
		map.addControl(new google.maps.SmallMapControl());
		map.addControl(new google.maps.MapTypeControl());
		map.addControl(new google.maps.ScaleControl());
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();
		map.setCenter(new google.maps.LatLng(v_c_lat,v_c_lng),v_c_zoom);

		// Marker Icon
		var v_icon = new google.maps.Icon();
		v_icon.image = v_url_rel + "media/img/house-icon.png";
		v_icon.shadow = v_url_rel + "media/img/house-shadow.png";
		v_icon.shadowSize = new google.maps.Size(16,21);
		v_icon.iconSize = new google.maps.Size(16,16);
		v_icon.iconAnchor = new google.maps.Point(8,8);
		v_icon.infoWindowAnchor = new google.maps.Point(8,8);
		var markerOptions = {icon:v_icon};

		// Markers
		switch (v_case) {
			case 1 :
				// Add Marker
				var point = new google.maps.LatLng(v_c_lat,v_c_lng);
				map.addOverlay(new google.maps.Marker(point,markerOptions));
			break;
			case 2 :
				// Load Markers from XML
				xml_url = v_url_rel + "properties/xml/?cid=" + v_cid
				if (typeof v_date != 'undefined') {
					xml_url += "&d=" + v_date;
				}
				if (typeof v_weeks != 'undefined') {
					xml_url += "&w=" + v_weeks;
				}
				google.maps.DownloadUrl(xml_url,function(data,responseCode) {
					var xml = google.maps.Xml.parse(data);
					var markers = xml.documentElement.getElementsByTagName("marker");
					for (var i = 0; i < markers.length; i++) {
						var id = markers[i].getAttribute("id");
						var sku = markers[i].getAttribute("sku");
						var name = markers[i].getAttribute("name");
						var county = markers[i].getAttribute("county");
						var url = markers[i].getAttribute("url");
						var type = markers[i].getAttribute("type");
						var price = markers[i].getAttribute("price");
						var sleeps = markers[i].getAttribute("sleeps");
						var pets = markers[i].getAttribute("pets");
						var imgid = markers[i].getAttribute("imgid");
						
						if (pets == "Y") {
							var v_pet = "Pets OK";
						} else{
							var v_pet = "No Pets";
						}
						
						var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),
												parseFloat(markers[i].getAttribute("lng")));
						var marker = createMarker(id, point, name, county, url, type);
						map.addOverlay(marker);
					}
					function createMarker(id, point, name, county, url, type) {
						var marker = new google.maps.Marker(point, markerOptions);
						var html = '<div class="google-map-window">'
							+ '<h2>' + sku + '. ' + name + '</h2>'
							+ '<a href="' + v_url_rel + 'properties/' + county + '/' + url + '">';
						if(imgid.length > 0) {
							html = html + '<img width="80" src="' + v_url_rel + 'properties/details/' + id + '/media/img/' + imgid + 's.jpg" />';
						} else{
							html = html + name;
						}
						html = html + ''
						+ '</a>'
						+ '<table>'
						+ '<tbody>'
						+ '<tr>'
						+ '<th>Sleeps:</th>'
						+ '<td>' + sleeps + '</td>'
						+ '</tr>'
						+ '<tr>'
						+ '<th>Pets:</th>'
						+ '<td>' + v_pet + '</td>'
						+ '</tr>'
						+ '<tr>'
						+ '<th>Price:</th>'
						+ '<td>' + price + '</td>'
						+ '</tr>'						
						+ '</tbody>'
						+ '</table>'
						+ '</div>';
						google.maps.Event.addListener(marker, "click", function() {var opts = new Object();
							marker.openInfoWindowHtml(html);
						});
						return marker;
					}
				});
			break;
		}

	}
