// FUNCIONES EXTERNAS ##################################################

// jQuery syncAnimation by John Resig
jQuery.fn.syncAnimate = function(other, prop, speed, easing, callback){
	if ( !this.length ) return this;

	var totals = {}, ratio = [], cur = jQuery(this), others = jQuery(other),
		opt = jQuery.speed(speed, easing, callback);

	jQuery.each(prop, function(type){
		totals[type] = 0;

		others.each(function(i){
			if ( !ratio[i] ) ratio[i] = {};
			totals[type] += (ratio[i][type] = parseInt( jQuery(this).css(type)) );
		});

		others.each(function(i){
			ratio[i][type] /= totals[type];
		});

		totals[type] += cur.is(":visible") ? parseInt(cur.css(type)) : 0;
	});

	opt.step = function(now, fx){
		var last = totals[fx.prop] - now;
		others.each(function(i){
			var num = Math.round((totals[fx.prop] - now) * ratio[i][fx.prop]);
			jQuery(this).css(fx.prop, i === others.length - 1 ? last : num);
			last -= num;
		});
	};

	opt.complete = opt.old || callback || jQuery.isFunction(easing) && easing;

	return this.animate( prop, opt );
};

// FUNCIONES EXTERNAS ##################################################


// TWITTER SLIDER	
var c=0;
var t;
var timer_is_on=0;

(function($){

	$.fn.nextTweet = function(options) {
		
		if ($('.li',this).length > 3) {
			var object = $(this);
			var element = $('.li:first',this);
			if (object.hasClass('play')) {
				element.removeClass('primero').clone().appendTo(this);
				element.fadeTo(200,0, function(){
					$(this).animate({'height': 0, 'margin-bottom': 0, 'margin-top': 0, 'padding-bottom': 0, 'padding-top': 0}, function(){
						$(this).remove();
					});
				}).next().addClass('primero');
			}
			
			setTimeout(function(){object.nextTweet(options);},options.time);
		}
	}
	
	$.fn.startTwitter = function(options) {
		var opts = $.extend({}, $.fn.startTwitter.defaults, options);
		
		$(this).addClass('play').nextTweet(opts);
		
		$(this).mouseenter(function(){ $(this).removeClass('play') });
		$(this).mouseleave(function(){ $(this).addClass('play') });
	}
	
	$.fn.startTwitter.defaults = { time: 10000 };
	
})(jQuery);
