var ThemeOfDay = function(container, config) {

	this._container = $(container);

	this._config = $.extend({
		links: 'li.ui-tabs-nav-item',
		timeout: 5000
	}, config || {});

	this._links = this._container.find(this._config.links);
	this._current_link = 0;

	this._start();

}


ThemeOfDay.prototype = {

	_container: null,
	_config: null,
	_links: [],

	_current_link: 0,

	_start: function() {

		var self = this;

		setInterval(function() {
			self._toggle();
		}, this._config.timeout);

	},
	
	_toggle: function() {
		this._links.removeClass('ui-state-active').removeClass('ui-tabs-selected');

		var currentTab = this._getCurrentTab();

		var self = this;
		
		currentTab.fadeOut('slow', function() {
			currentTab.addClass('ui-tabs-hide');
			self._nextLink().addClass('ui-state-active').addClass('ui-tabs-selected');
			self._getCurrentTab().fadeIn('fast').removeClass('ui-tabs-hide');
		});
		
	},

	_getCurrentLink: function() {
		return $(this._links[this._current_link]);
	},

	_nextLink: function() {
		++this._current_link;
		this._current_link = this._current_link % this._links.length;

		return this._getCurrentLink();
	},

	_getCurrentTab: function() {
		return this._container.find('#' + this._getCurrentLink().find('a').attr('rel'));
	}

}