I think, it's a deja vu for me. The solution should be based on mouse position (assuming user always switches pages with a mouse). I can make experiments and use hardcoded constants to determine, which tab did I click.
UPDATE. Yes, the solution was easy after all. I already solved the problem using amouseobj function. Now, what if the user selects next page using keyboard?
If it's not broken, fix it until it is.
My Blog