Logic for maintaining index after reordering dom elements, and autoplay flag