// JavaScript Document

function TabbedPanelsCycler(tp)
{
this.tp = tp;
this.timerID = 0;
this.interval = 5000; // Milliseconds
}

TabbedPanelsCycler.prototype.start = function()
{
this.stop();
var self = this;
this.timerID = setTimeout(function() { self.next(); }, this.interval);
};

TabbedPanelsCycler.prototype.stop = function()
{
if (this.timerID)
clearTimeout(this.timerID);
this.timerID = 0;
};

TabbedPanelsCycler.prototype.next = function()
{
var tp = this.tp;
tp.showPanel((tp.getCurrentTabIndex()+1) % tp.getTabbedPanelCount());
if (this.timerID)
this.start();
};

TabbedPanelsCycler.prototype.previous = function()
{
var tp = this.tp;
var curIndex = tp.getCurrentTabIndex();
tp.showPanel(((curIndex < 1) ? tp.getTabbedPanelCount() : curIndex) - 1);
if (this.timerID)
this.start();
};
