let slidearray;   // Declare slidearray in the global scope

function slideinit(slideNrImages) {
    slidearray = Array.from({length: slideNrImages}, (_, i) => i + 1); // Initialize slidearray inside the function
    console.log(slidearray);
}

slideinit(3);  // Example initialization with 3 slides

// Arrow up / right controls 
function UpArrow(slideNrImages) {
    for (let x = 0; x < slidearray.length; x++){
        slidearray[x] -= 1;
        if (slidearray[x] < 1) {
            slidearray[x] = slideNrImages;  // It would be the last slide if it goes below 1
        }
    }
    console.log(slidearray);  // Debug output
}

// Arrow down / left controls
function DownArrow(slideNrImages) {
    for (let x = 0; x < slidearray.length; x++){
        slidearray[x] += 1;
        if (slidearray[x] > slideNrImages) {
            slidearray[x] = 1;  // It would be the first slide if it exceeds the total number of slides
        }
    }
    console.log(slidearray);  // Debug output
}