XML photo gallery - disable buttons

Okay, trying to do a little add-on, but having trouble.

I want to disable the previous button on the first image and disable the next button on the last image. I’ve been trying stuff like this:

if (p == 0) {
previous_btn.enabled = false;
}
 
if (p == total) {
next_btn.enabled = false;
}

But no worky :(, any help?