title: Extract x items from array (slice) but continue from beginning if end is reached
body: <p>Lets say I have:</p>
  
  <pre><code>var array = [0,1,2,3,4,5,6,7,8,9]
  </code></pre>
  
  <p>I define:</p>
  
  <pre><code>var itemsToExtract  = 5
  var startindex = 7
  var direction = "forward"
  </code></pre>
  
  <p>I want to be able to do:</p>
  
  <pre><code>array.someMethod(startindex, itemsToExtract, direction)
  </code></pre>
  
  <p>and get</p>
  
  <pre><code>[7,8,9,0,1]
  </code></pre>
  
  <p>I also want it to work backwards, if I set direction to "backward" (slicing from right to left).</p>
  
  <p>I wasnt too lazy and tried something already, see here: <a href="http://jsfiddle.net/MkNrr/">http://jsfiddle.net/MkNrr/</a></p>
  
  <p>I am looking for something "tidier" if there is, also is there a name for this method, is it a known problem?</p>
  
  <p>Background: I am trying to build a sequential pre image loader (load one image(src) after the other) for use in an image gallery. Maybe even such a libary already exists?</p>