carousel JS code rewrite