var oldlat = '74.455746';
var oldlon = '-112.851563';
var latlonnew;
var visitor;
var locdesc;
var speed = 1000;

function handleHttpResponse() {
	if (http.readyState == 4) {
    
		results = http.responseText.split("|");
		
		if (results[2]) {
			latlonnew = new GLatLng(results[0],results[1]);
			latlonold = new GLatLng(oldlat,oldlon,2);
			
			map.panTo(latlonnew,2);
			visitor = new GMarker(latlonnew,2);
			map.addOverlay(visitor);
			
			locdesc = results[3];
			map.openInfoWindowHtml(new GLatLng(results[0],results[1]),locdesc);
			
			oldlat = results[0];
			oldlon = results[1];
		}
	}
}

function GetLatLon() {

	var random = Math.random();
	var url = "live-map.func.php?r=" + random;

	http.open("GET", url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function getHTTPObject() {
  var xmlhttp;
    /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'unknown') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var http = getHTTPObject();


function DoGeo() {
	setInterval("GetLatLon()",speed);
}


function StartMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("geomap"));
		map.setCenter(new GLatLng(oldlon,oldlat), 2);
	}
}