
// update the bbox; called at moveHandler
function updateBBOX() {
  var bounds = map.getBounds();
  var southWest = bounds.getSouthWest();
  var northEast = bounds.getNorthEast();

  bbox = "&BBOX=" + southWest.lng() + "," + southWest.lat() + "," + northEast.lng() + "," + northEast.lat();
}


// zoom in on a user - zooming to level 14
function zoomInOnUser(user) {
  var mrk = userMarkers.find2(user, function(m) {
    return m.mrkData["user"];
  });
  if (mrk != null) {
    map.getInfoWindow().hide();
    map.setCenter(mrk.getPoint(), 14);
  }
}


// after the timeout, clear the timer and issue a reload for the new bbox
function moveHandlerReload(loadMarkersCallback) {
  if ($('infop') != null) {
    $('infop').innerHTML = "Loading...";
  }
  if (timer != null) {
    clearTimeout(timer);
    timer = null;
  }
  loadMarkers(mapRefresh, loadMarkersCallback);
}


// called when the map is moved or zoomed
function moveHandler() {
  if (timer2 != null) {
    clearTimeout(timer2);
    timer2 = null;
  }
  
  if ($('setpos') != null) {
    if (!($('setpos').style.visibility == "hidden")) {
      var centerPos = map.getCenter();
      $('setposlat').innerHTML = centerPos.lat().toFixed(5);
      $('setposlon').innerHTML = centerPos.lng().toFixed(5);      
    }
  }

  updateBBOX();

  // wait for a couple of seconds, then reload the markers
  timer2 = setTimeout("moveHandlerReload()", 2500);
  // reset lastUpdate
  lastUpdateTime = new Date().getTime();
}


// called to make the map full size in embed mode
function fullSize() {
  // get height
  var winH = (navigator.appName.indexOf("Microsoft")!=-1) ? document.body.offsetHeight : window.innerHeight;
  $('gmaptrack').style.top = 0;
  $('gmaptrack').style.left = 0;
  $('gmaptrack').style.height = "100%";
  $('gmaptrack').style.width = "100%";
  $('map').style.top = 0;
  $('map').style.left = 0;
  $('map').style.height = "100%";
  $('map').style.width = "100%";

  // map object
  map.checkResize();
}


// called when the window is resized
function resizeHandler() {
  // get height
  var winH = (navigator.appName.indexOf("Microsoft")!=-1) ? document.body.offsetHeight : window.innerHeight;
  $('map').style.height = (winH - 160) + "px";
  $('mapleft').style.height = (winH - 140) + "px";

  // map object
  map.checkResize();
  moveHandler();
}


function mousewheel(event) {
  if (mouseinside) {
    if (event) {
      if (event.preventDefault && (Function == event.preventDefault.constructor))
        event.preventDefault();
      event.returnValue = false;
    }
    return false;
  } else {
    return true;
  }
}
