
(function($) {

   tabAnimate = {
			quoteIndex: 0,
			tab: null,
			quotes: null,
			duration: {
				'ROTATE': 2500,
				'ANIMATE_IN': 600,
				'HOLD': 3200,
				'ANIMATE_OUT': 700
			},
			
			init: function(tab, quotes)
			{
			  if(this.tab && this.quotes) return;
				this.tab = jQuery(tab);
				this.quotes = quotes;
				this.tabOverlay = this.tab.find('.tabOverlay');
				this.tabOverlay.css('opacity', 0);
        this.rotateContent();
        this.animateIn();
			},
			
			
			rotate: function()
			{
        var self = this;
        var tabContent = this.tab.find('.content');
        this.tabOverlay.animate({ 'opacity': 1 }, self.duration.ANIMATE_OUT, function()
        {
          self.rotateContent();
          
          self.tabOverlay.animate({ 'opacity': 0 }, self.duration.ANIMATE_IN, function()
          {
            setTimeout(function()
            {
              return self.rotate();
              
            }, self.duration.HOLD);
          });
        });
			},
			
			rotateContent: function(){
			  var self = this;
				if(this.quoteIndex >= this.quotes.length)
					this.quoteIndex = 0;						

				var currentQuote = this.quotes[this.quoteIndex];
				var tabContent = this.tab.find('.content');
				tabContent.empty();
				tabContent.append($('<p/>').html(currentQuote['content']));
				tabContent.append($('<span class="quote-source"/>').html(currentQuote['quote-source']));
				tabContent.append($('<span class="quote-date"/>').html(currentQuote['quote-date']));
				this.quoteIndex++;
			},
			
			animateIn: function()
			{
				var self = this;

				this.tab.animate({
					'right': 0
				}, this.duration.ANIMATE_IN, function()
				{
				  setTimeout(function(){
				    return self.rotate();  
				  }, self.duration.HOLD);
					
				});
			}
		}

})(jQuery);
