
kff.widgets.Tabs = function(element, options)
{
	this.options = $.extend({
		activeTab: 0,
		activeClass: 'active'	
	}, options);
	this.$element = $(element);
	this.$tabs = this.$element.find('li');
	this.activeTab = this.options.activeTab; 
};

kff.widgets.Tabs.prototype.init = function()
{
	this.switchTab(this.activeTab);	
	this.$element.delegate('a', 'mousedown', $.proxy(this.mouseDown, this));
	this.$element.delegate('a', 'click', function(){ return false; } );
	return this;
}

kff.widgets.Tabs.prototype.mouseDown = function(event)
{
	$li = $(event.currentTarget).closest('li');
	var tabNo = this.$tabs.index($li);	
	
	this.switchTab(tabNo);
	return false;	
}

kff.widgets.Tabs.prototype.switchTab = function(tabNo)
{
	var that = this;
	this.activeTab = tabNo;
	this.$tabs.each(function(i)
	{
		var $section = $($(this).find('a').attr('href'));
		if(i == that.activeTab)
		{
			$(this).addClass(that.options.activeClass);
			$section.show();
		}
		else
		{
			$(this).removeClass(that.options.activeClass);
			$section.hide();
		}
	});
}

