Counter that creates div

Counter that creates div

I'm using a jquery div slider for displaying image galleries. But I have to add those galleries all manually. To automate this, I have a scripts that generates thumbnails of bigger images. Then I use another jquery script to display the bigger images when a thumbnail is clicked. It lacks only one thing. I need some counter that counts images or li lines and creates a div when a specific amount is reached. For example: when I have more than 20 images (say 25), the counter detects it and creates a new div. So I then have two divs: one with 20 and one with 5. Is this possible to do? I don't have the programming skills for this. Is someone willing to help me out?