
var startCapture = false; // required for compatibility with the minisite functionality

function initOverviewMap() {
 	waitingHTML = "<div style=\"position: absolute;margin-left:100px;margin-top: 100px;width: auto;height: 19px;padding: 4px 10px 0px 10px;"
 	waitingHTML += "color: #CC0000;background-color: rgb(221, 221, 238);border: 1px solid #979797;font-size: 14px;font-weight: 800;\">Loading map, please wait . . . this may take some time</div>";       
 
 	document.getElementById('overviewmapinterface').innerHTML = waitingHTML;
 
	// this is the main page so we have a fixed zoom
	var pts = [new GLatLng(51.5157934336253,-0.09613037109375),new GLatLng(51.5157934336253,0.075531005859375),new GLatLng(51.4972021458538,0.075531005859375),new GLatLng(51.4972021458538,-0.09613037109375),new GLatLng(51.5157934336253,-0.09613037109375)]; 
	var p = new GPolyline(pts, "#FF00FF",5,0.5,{});
	var zoomLevel = getZoomLevelForPoints(pts);
	   
	map = new GMap2(document.getElementById("overviewmapinterface"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());
	   
 	map.setCenter(getCenterPointFromPolyline(p),zoomLevel,G_HYBRID_MAP);

 	geocoder = new GClientGeocoder();
	geocoder.setBaseCountryCode("UK"); // gr is the iso code for great britain!

	 xmlUpdateMap = createXMLHttpRequest();
	 xmlUpdateMap.open("POST", "overviewMapDataAvailable.php");
	 xmlUpdateMap.onreadystatechange = processOverviewMap;
	 
	 try {
	   //xmlUpdateMap.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   xmlUpdateMap.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
	 	// this only works in internet explorer
	 }
	 xmlUpdateMap.send(null);
}
function processOverviewMap() {
           if (xmlUpdateMap.readyState != 4)  {
	   		return;
	   	}
	
	var responseText = xmlUpdateMap.responseText;
	
	setupOverviewSearch();
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.text = responseText;
	headID.appendChild(newScript);
	updateOverviewMap();
	
	// version 3- we need to cache the icons here as they are required to show the search results, even though this is an overview map
	preloadImages();
	createIcons();

	
	
	GEvent.addListener(map,'moveend',function() {
		updateOverviewMap();
		if (infodisplayed == true) {
			// claire - version 3 - moving the map closes the window!
			doCloseInfoWindow();
		}

	}); 
	
	
	// get the HTML content for the search tab ..
	
}
function updateOverviewMap() {
        // generate the icon and layer colours for minisites
        // this is separate from the usual site

	// now add the data layer
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var getVars = 'ne=' + northEast.toUrlValue()
	+ '&sw=' + southWest.toUrlValue()

	var showminisites = true;
	var minisitesdatastring = "../includes/processDataRequest.php?approved=1&queryType=layer&tablename=minisites&" + getVars;
	//alert(minisitesdatastring);
	minisites = new GeoXml("minisites", "MiniSites", "map",false, showminisites, map,  minisitesdatastring, {sidebarid:"minisitesHTML"});
	minisites.parse();
}



//******************************************
// FUNCTIONALITY FOR VERSION 3- FOR THE SEARCH PROCESS - WE NEED TO KEEP THE POINTS that we move to from the search result on the map
// and also make sure that the info pop-up works 


var overviewLat;
var overviewLng;
function getOverviewInfo(point,layername,tablename,id) {

		overviewLat = point.lat();
		overviewLng = point.lng();

	getOverviewInfoHTML(layername, id);
}


function getOverviewInfoHTML(layername, resultID) {
	 xmlGetInfo = createXMLHttpRequest();
	 xmlGetInfo.open("GET", "getInfoHTML.php?layername="+layername+"&resultID="+resultID);
	 xmlGetInfo.onreadystatechange = showOverviewInfoWindow;
	 
	 try {
	   //xmlUpdateMap.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	   xmlGetInfo.setRequestHeader('Content-Type','text/html')
	 }
	 catch (e) {
	 	// this only works in internet explorer
	 }
	 xmlGetInfo.send(null);
	

}
function showOverviewInfoWindow() {

           if (xmlGetInfo.readyState != 4)  {
	   		return;
	   	}
	
	var responseText = xmlGetInfo.responseText;
	// split off any javascript
	var readonlyhtml = responseText.split("|XX|");
	var scriptsource = readonlyhtml[2];
	if (scriptsource) {
		if (scriptsource.length > 0) {
			// we will only have source info if there is a photo
		//  	alert(scriptsource);
			var headID = document.getElementsByTagName("head")[0];
			var newScript = document.createElement('script');
			newScript.type = 'text/javascript';
			newScript.text = scriptsource;
			headID.appendChild(newScript);
		   }
	}
	var layername = readonlyhtml[0];
	var taggedName = "";
	var desc = readonlyhtml[1];
	  var html1 = desc; //createInfo(this.layername,taggedName,desc);
	  var html2 = generateHeading();
	  var html3 = getInfoCloseButton();

	
	showInfo(html1,html2,html3,overviewLat,overviewLng);

}
