
onload = ()=>{bgCarousel(document.querySelector(".bg-swap"),["hero_2.jpg","hero_3.jpg","hero_4.jpg"],5)}

function bgCarousel(element,images,time){
    
    
    var index = Number(element.getAttribute("index"));
    var delay = 1000;
    if(time != null){delay = time * 1000}
    
    
    const swap = () =>{
        index += 1;
        if(index >= images.length){index = 0}
        element.style.backgroundImage = "url(images/" + images[index] + ")";
        element.setAttribute("index",index);
        
        setTimeout(()=>{swap()},delay);
    }
    swap();
    

}