More generic version of my gallery script (WIP)