Well, if you look at the PHP code you have on your page, you could see that you set the category id to "1", so it make sense that the page is loading the first image, but it is always going to be true. The question here is how do you determine the Category ID, are you sending in the URL:
If so you would want to do this:
$CategoryID = $_GET['CategoryID'];
And you would need to update all the links in PowerStore to add a Category ID.
If you could please explain a little more about how you are determining what is the Category ID that you are going to use, i should be able to help you.