
var Tabs = function(tabs, content, selectClass, cycleDelay)
{
    var self = this;

    this.tabs = $(tabs);
    this.content = $(content);
    this.selectClass = selectClass;
    this.cycleDelay = cycleDelay;

    this.cycleInterval;
    this.cycleStarTimeout;

    this.tabs.hover(function()
    {
        self.select($(this).attr('name'));
        clearInterval(self.cycleInterval);
        clearTimeout(self.cycleStartTimeout);
    }, function() 
    { 
        self.cycleStartTimeout = setTimeout(function() {
            self.cycle();
        }, 2000);
    });

    this.select(this.tabs.eq(0).attr('name'));
    this.cycle();
};
Tabs.prototype.cycle = function()
{
    var self = this;

    if (!this.cycleDelay)
        return;

    var i = 0;
    this.cycleInterval = setInterval(function() {
        var name = self.tabs.eq(i).attr('name');
        self.select(name);
        i = (i + 1) % self.tabs.length;
    }, this.cycleDelay);
};
Tabs.prototype.select = function(name)
{
    var f = '[name='+name+']';
    this.tabs.not(f).removeClass(this.selectClass);
    this.tabs.filter(f).addClass(this.selectClass);
    this.content.not(f).hide();
    this.content.filter(f).show();
};

