Dynamically adjustable gallery

HI, i’ve been currently working on a project which requires the functionality that’s similar to www.adidas.com for viewing images.

I’ve managed to create a single resizeable gallery box, but still not sure on how to calculate the distance between one box to another, and resize it dynamically when another box is enlarging. Also in my opinion, making this gallery static is not an option since there’ll be more than 20 boxes to be shown, and there’s possibility in the future that the number of boxes can be changed.

Thanks, Wazabii