$(function(){
	
	totalT = 0;
	
	$("#twitter").getTwitter({
		userName: "GoMySites",
		numTweets: 5,
		loaded: function(){
			
			totalT = $('#twitter_update_list li').size();
			
			$('#twitter_update_list li:first').clone().appendTo('#twitter_update_list');
			
			Cufon.refresh('#twitter_update_list li'); 
			
			$('#twitter p.loading').animate({opacity:0},400,'easeInOutExpo',function(){
				$(this).remove();
				$('#twitter_update_list').animate({top:0},400,'easeInOutExpo',function(){
					tweetCycle();
				});
			});
		}
	});
	
	currentY = 0;
	currentT = 1;
	
	var tweetTimer = {};
	
	$('#twitter').hover(function(){
		$.clearTimer(tweetTimer);
	},function(){
		tweetCycle();
	});
	
	function tweetCycle(){
		tweetTimer = $.timer(3800,function(){
			$.clearTimer(tweetTimer);
			if(currentT==totalT+1){
				$('#twitter_update_list').css({top:0});
				currentY = 0;
				currentT = 1;
			}
			currentY = currentY - 38;
			$('#twitter_update_list').animate({top:currentY},400,'easeInOutExpo');
			currentT = currentT + 1;
			tweetCycle();
		});
	}

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};
	
});
