I usually just keep track of the index of the currently selected item (the one in the middle), and then increase or decrease that index whenever the user "slides" the list right or left and mod by the size of the array.
For example,
PHP Code:
function onCreated() {
temp.arr = {"a", "b", "c", "d", "e", "f"};
temp.sel = 0; // The index of the item in the middle
this.printDisplay(temp.arr, temp.sel); // echoes "f a b"
/* Now, slide to the left */
temp.sel = (temp.sel + 1) % temp.arr.size(); // is now 1, so "b" is the middle item
this.printDisplay(temp.arr, temp.sel); // echoes "a b c"
/* Now, slide to the right twice
Assuming you'd always slide one at a time
whenever the user presses a key */
temp.sel = (temp.sel - 1) % temp.arr.size(); // is now 0, "a" is in the middle again
temp.sel = (temp.sel - 1) % temp.arr.size(); // is now 5, "f" is in the middle
this.printDisplay(temp.arr, temp.sel); // echoes "e f a"
}
/* This is generally how I would show what's on the
left and right of the selected item. You can do your image
drawing or whatever here.
If you have a special case for the one in the middle, such
as having it highlighted or something, just check
if (temp.i == 0) { <Stuff for the middle item here> }
*/
function printDisplay(arr, sel) {
temp.str = "";
for (temp.i = -1; temp.i =< 1; temp.i ++) {
temp.str @= temp.arr[(temp.sel + temp.i) % temp.arr.size()] @ " ";
}
echo(temp.str);
}