Refactor js for frontpage image flipping