var request=null;


	var map = new YMap(document.getElementById('map'));

	// Add map type control
	map.addTypeControl();
	// Set map type to either of: YAHOO_MAP_SAT, YAHOO_MAP_HYB, YAHOO_MAP_REG
	map.setMapType(YAHOO_MAP_REG);
	// Display the map centered on a geocoded location
	map.drawZoomAndCenter("United States", 12);



function createRequest(){
	try{
		request= new XMLHttpRequest();
	}
	catch(trymicrosoft){
		try {
		request= new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (othermicrosoft) {
	try {
		request = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(failed){
			request=null;
		}
		}
		}
	if (request == null)
		alert("Error creating request object");
}

function updatePage(){
	if(request.readyState == 4){
		var loc = request.responseText;

		if(loc == "ERROR")
		{
			alert("Sorry. Fire Eagle is encountering issues. Please try again in a few");
		}
		else if(loc != "")
		{

		var location =loc.split(",,",5);
		var currentGeoPoint = new YGeoPoint( location[1], location[0] );
		var newMarker= new YMarker(currentGeoPoint, createCustomMarkerImage());
		newMarker.addAutoExpand("<b>"+location[2]+"</b> - "+location[3] );
		map.addOverlay(newMarker);
		map.panToLatLon(currentGeoPoint);
		replaceText(document.getElementById("location"),location[2]);
		setTimeout('grabRecent();', 4000);

	}
	else
	{
		//alert("not updating");
	}

	}
}

function createCustomMarkerImage(){
		 	var myImage = new YImage();
		  	myImage.src = 'http://skeevisarts.com/projects/birdwatcher/binoc.gif';
		 	myImage.size = new YSize(20,20);
		  	myImage.offsetSmartWindow = new YCoordPoint(0,0);
			return myImage;
		}


function grabRecent()
{
	//alert("sending req");
	createRequest();
	var url = "update.php";
	request.open("GET",url,true);
	request.onreadystatechange=updatePage;
	request.send(null);
}


function replaceText(e1,text){
	if(e1 != null){
	clearText(e1);
	var newNode = document.createTextNode(text);
	e1.appendChild(newNode);
	}
}

function clearText(e1){
if(e1 != null){
	if(e1.childNodes){
	for (var i = 0; i < e1.childNodes.length;i++){
	var childNode = e1.childNodes[i];
	e1.removeChild(childNode);
	}
	}
}

}
