title: Move to next tab
body: <p>I am trying to create an extension that changes to the next tab in an array of tabs and it also has to be able to loop back to the beginning.  I have been pounding away at this for a couple of days now and can not for the life of me figure it out.</p>
  
  <p>The way this extension works is it listens for a tab to update, then it runs one function before this nextTab function.  </p>
  
  <p>Here is what I currently have as my nextTab function:</p>
  
  <pre><code>function nextTab(){
       // get the current window
      chrome.windows.getCurrent(function(win)
      {
          // get an array of the tabs in the window
          chrome.tabs.getAllInWindow(win.id, function(tabs)
          {
              var tabIds = [];
              for (i in tabs)
              tabIds.push(i);
                  for (var i = 0; i &lt; tabIds.length; i++)
                  {
                      var tab = tabs[tabIds[i]];
                      chrome.tabs.update(tab.id, { selected: true});
                  }
  
          });
      });
  };
  </code></pre>
  
  <p>So far it will cycle through the tabs from the looks of it when I run it.  But it always ends up on the last tab.  Does anyone have an easier way to do this or can give me any tips on what I am doing wrong?</p>