the Gallery recordset requires the PageContentsID URL Variable be passed in to populate.
you have code to convert the PageContentsID value to brs_<PageContentsID>
$_GET["GalleryContent"] = "brs_".$_GET['PageContentsID'];
and this is used to filter the gallery.
you rewrite is not passing that variable so the gallery recordset does not work.