
AC_FL_RunContent = 0;


function showFLVAA(pFilename) {
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '832',
			'height', '526',
			'src', '/flash-video',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'flash-video',
			'bgcolor', '#ffffff',
			'name', 'flash-video',
			'menu', 'true',
			'allowFullScreen', 'true',
			'allowScriptAccess','always',
			'movie', '/flash-video',
			'salign', '',
			'FlashVars', 'videourl=' + pFilename
		); 
	}
}

var pid = 0;
var map;
var icon;

var defDay = '';
var defCounty = '';
var isLoaded = false;



function load() {
	if (document.getElementById("day")) {
		defDay = document.getElementById("day").value;
		defCounty = document.getElementById("county").value;
	}
	if (document.getElementById("map")) {
		//alert(html);
		icon = new GIcon();
		icon.image = '/styles/marker.png';
		icon.iconSize = new GSize(35, 62);
		//icon.shadowSize = new GSize(10, 10);
		icon.iconAnchor = new GPoint(17, 61);
		icon.infoWindowAnchor = new GPoint(17, 17);  
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(53.3504, -6.2531), 13);			
		}
	}
	isLoaded = true;

}

function showMeetingInfo(code) {	
	$('#listing').load("/detail.do?id=" + code);
}


function showListings() {
	document.getElementById("listing").innerHTML = listingHTML;
}

function createMarker(point, markerObj) {	
	var html = "";
	var marker = new GMarker(point, icon);	
	useName = markerObj.getAttribute("name");
	if (markerObj.getAttribute("name") == '') { useName = "No name specified"; }
	if (markerObj.getAttribute("name") != null) html += "<h2 style='margin-bottom: 5px'>" + useName + "</h2>";
	if (markerObj.getAttribute("description") != null) html += "<p>" + markerObj.getAttribute("description") + "</p>";
	html += "<a class='details' href='#info' onclick='javascript:showMeetingInfo(\"" + markerObj.getAttribute("code") + "\")'>Meeting Information</a>";
	//html += " <a href='/removemarker.do?code=" + markerObj.getAttribute("code") + "'>.</a>";

	//alert(html);

    	maxWidth = 250;
    	GEvent.addListener(marker, 'mouseover', function() {
		marker.openInfoWindowHtml(html,{maxWidth:maxWidth});	
	});
  	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html,{maxWidth:maxWidth});	
	});
	return marker;
}


function refineSearch() {

	if (document.getElementById("map")) {
		if (!isLoaded) {
			load();
		} else {

			var searchUrl = '/markers.do?day=' + document.getElementById("day").value + '&county=' + document.getElementById("county").value;
			//alert(searchUrl);
			GDownloadUrl(searchUrl, function(data) {
				var xml = GXml.parse(data);
				updateResults(xml);
			});
		}
	}
}


function updateResults(xml) {
	listingHTML = "<h1>Search Results</h1><p>Click on a marker on the map above, or from the list below.</p>";
	var markers = xml.documentElement.getElementsByTagName('marker');  
	map.clearOverlays();
	if (markers.length == 0) {
		map.setCenter(new GLatLng(53.3504, -6.2531), 13);
		return;
	}
	var bounds = new GLatLngBounds();
	for (var i = 0; i < markers.length; i++) {
		var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')), parseFloat(markers[i].getAttribute('lng')));
		var marker = createMarker(point, markers[i]);
		map.addOverlay(marker);
		bounds.extend(point);
		useName = markers[i].getAttribute("name");
		//if (markers[i].getAttribute("name") == '') { useName = "No name specified"; }
		if (markers[i].getAttribute("name") != '') listingHTML += "<a class='listitem' href='javascript:showMeetingInfo(\"" + markers[i].getAttribute("code") + "\")'>" + useName + "<br><span class='markerdesc'>" + markers[i].getAttribute("description") + "</span></a>";
	}
	if (pid != 0) {
		map.setCenter(bounds.getCenter(), 15);
	} else {
		map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
	}
	document.getElementById("listing").innerHTML = listingHTML;
}


