Grouping images to make thumbnail pages.

Grouping images to make thumbnail pages.

Hello I looked all over the forum, but can't figure it out.
I would like to place every n-th element in a div.

change this html
  1. <div id="container">
  2.       <img />
  3.       <img />
  4.       <img />
  5.       <img />
  6.       <img />
  7.       <img />
  8. </div>
into this:
  1. <div id="container">
  2.       <div>
  3.             <img />
  4.             <img />
  5.             <img />
  6.       </div>
  7.       <div>
  8.             <img />
  9.             <img />
  10.             <img />
  11.       </div>
  12. </div>

Can anyone help me with the jquery code?
Thanks.