$page variable fix

if the user tryes to change the page > totalpages.. show the last page,
if page < totalpages show the first page