     chrome.tabs.getSelected(null, (tab) ->
       chrome.tabs.sendRequest(tab.id,
         { name: "toggleHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId }))
+  nextFrame: (count) ->
+    chrome.tabs.getSelected(null, (tab) ->
+      frames = framesForTab[tab.id].frames
+      curr_index = getCurrFrameIndex(frames)
+
+      # TODO: Skip the "top" frame (which doesn't actually have a <frame> tag),
+      # since it exists only to contain the other frames.
+      new_index = (curr_index + count) % frames.length
+
+      chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[new_index].id, highlight: true }))
 
 # Selects a tab before or after the currently selected tab.
 # - direction: "next", "previous", "first" or "last".

  selectSpecificTab: selectSpecificTab,
  refreshCompleter: refreshCompleter

init = ->
  Commands.clearKeyMappingsAndSetDefaults()

  if Settings.has("keyMappings")
    Commands.parseCustomKeyMappings(Settings.get("keyMappings"))

  populateValidFirstKeys()
  populateSingleKeyCommands()
  if shouldShowUpgradeMessage()
    sendRequestToAllTabs({ name: "showUpgradeNotification", version: currentVersion })

  # Ensure that openTabs is populated when Vimium is installed.
  chrome.windows.getAll({ populate: true }, (windows) ->
    for window in windows
      for tab in window.tabs
        updateOpenTabs(tab)
        createScrollPositionHandler = ->
          (response) -> updateScrollPosition(tab, response.scrollX, response.scrollY) if response?
        chrome.tabs.sendRequest(tab.id, { name: "getScrollPosition" }, createScrollPositionHandler()))


init()

# Convenience function for development use.
runTests = -> open(chrome.extension.getURL('test_harnesses/automated.html'))

filterCompleter = (args, port) ->
  queryTerms = if (args.query == "") then [] else args.query.split(" ")
  completers[args.name].filter(queryTerms, (results) -> port.postMessage({ id: args.id, results: results }))

getCurrentTimeInSeconds = -> Math.floor((new Date()).getTime() / 1000)

