gallery navigation buttons

gallery navigation buttons

dear all,

i am writing a simple gallery for my portfolio.

I have navigation buttons, to show the next, previous, last and first picture. This works fine as long as i remain within 1 gallery.

But i need 4 different galleries. So based on the gallery, the buttons will need to load images from different folders.

For example, in 1 gallery i use:
$("#foto1 img").attr('src','portfolio/webdesign/1.jpg');

Whereas in another gallery i should use:
$("#foto1 img").attr('src','portfolio/drukwerk/1.jpg');

How can i accomplish this, without having to write the full code 4 times?

thanks!

Matt