I am making an application that allows users to use the key board to interface with it. I am using YUI for the key listening and have almost all of my functions working.

The ones that seems impossible right now is I have a search result page where links to items are in a table. I need functions that I can call from my YUI key listener to do the following:

Right arrow function: Gets the next link on the page in a defined table. If the selected one is in a TD at the end of the row, this should go to the first link in the next row. At the last item in the last row, it should go to the first item (this is a nice to have)

Down arrow function: Goes to the link in the current position in the next row. For example if you are on the 3rd link in the 2nd row, and hit down, you will be in the 3rd link in the 3rd row. On the last row, you will go to the first row (this is a nice to have)

Left arrow function: Get the previous link in a defined table. If the current link is the first link, the function should go to the last link in the previous row. If it is the first item, this should go to the last item in the last row (this is a nice to have)

Up arrow function: Goes to the link in the current position in the previous row. For example if you are on the 3rd link in the 2nd row, and hit down, you will be in the 3rd link in the 1st row. On the first row, you will go to the last row (this is a nice to have)

I have tried this 100 different ways, arrays, hashes ... and it is not working. I am open to using divs, I am using tables so I can select rows of data