How do I detect if the user is "idle" with Javascript?

You may want to listen for some or all of the following events:

mouseMove, mouseClick, mouseUp, mouseDown, keyDown, keyUp, keyPress

set a timer to go off after some duration of idleness (60 seconds?) and that will turn off your switch make sure you check your switch before your ajax requests.

Ideally you'll exponentially throttle your ajax calls to some low value the longer a user remains idle.

$(window).bind('mousemove click mouseup mousedown keydown keypress keyup submit change mouseenter scroll resize dblclick', someEvent);
var active = true,
  delay = 60000,
  timer = null;

function someEvent(e)
{
  active = true;
  if (timer) clearTimeout(timer);
  timer = setTimeout(function(t){
    active = false;
  }, delay);
}

I think you're searching for this: https://github.com/jasonmcleod/jquery.idle