finalize media gallery js