<br><br>

<div class="restrictedWidth">

    <head>
        <title>Red Jacket Robotics - Gallery</title>
    </head>

    <p class="largeText">Select a folder from the "Image List" dropdown menu</p>
    <br>
    </p>
    <?PHP
    if (!isset($_GET["imgPath"])) {
        echo '<details open>';
    } else {
        echo '<details>';
    }
    ?>
    <summary class="largeText">Image List</summary>

    <?PHP
    $path = '../images';
    $items = scandir($path);
    $folders = [];
    foreach ($items as $item) {
        if ($item != '.' && $item != '..') {
            $fullPath = $path . '/' . $item;
            if (is_dir($fullPath)) {
                $folders[] = $item;
            }
        }
    }
    foreach ($folders as $folder) {
        echo '<center><button class="galleryButtons" onclick="window.location.href=\'?imgPath=' . $folder . '\'">' . $folder . '</button></center>';
    }

    ?>

    </details>
    <br>

    <?PHP
    $imgPath = $_GET["imgPath"];
    $folder = '../images/' . $imgPath . '/';
    $images = glob($folder . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
    function images()
    {
        global $images;
        foreach ($images as $image) {
            echo '<a href="../images/' . $image . '"><img src="' . $image . '" class="galleryImagePref" alt="Image"></a>';
        }
    }
    ?>

    <div class="galleryContainer">
        <?PHP images() ?>
    </div>
    <?PHP
    if (!isset($_GET["imgPath"])) {
        echo '<img src="../cardinals.png" class="galleryImagePref" alt="Image">';
    }
    ?>

    <center>
        <p class="largeText">If you would like to request images to be put onto the gallery please contact <a
                href="mailto:stephen.powers@redjacket.org">stephen.powers@redjacket.org</a></p>
    </center>

</div>