From http://www.evensongraphics.co.nz/2013/03/masonry-nextgen-gallery-template/