// JavaScript Document
$(document).ready(function(){
	
	cycleInquiry = setTimeout("fadeTweet()",timeBetweenTweets);	
});
		
		// eventually we'll need to namespace all this and move it out into a functions file
		// but, for now, lets just keep it simple and with fewer server requests
		// events.js = common.js
		
		function stripslashes (str) {
			return (str + '').replace(/\\(.?)/g, function (s, n1) {
				switch (n1) {
				case '\\':
					return '\\';
				case '0':
					return '\u0000';
				case '':
					return '';
				default:
					return n1;
				}
			});
		}

		function fadeTweet(){
			$("article.favorites h1").animate({ opacity: 0 }, 500);;
			$("article.favorites h2").animate({ opacity: 0 }, 500,function(){ nextTweet(); });
		}
		
		function nextTweet(){
			var nextIndex = tweetIndex + 1;
			if (nextIndex > ((tweets.length)-1)){
				nextIndex = 0;	
			}
			var tweet = stripslashes(tweets[nextIndex][0]);
			var timestamp = tweets[nextIndex][1];
			var permalink = tweets[nextIndex][2];
			var username = tweets[nextIndex][3];
			
			var meta = 'From <a href="http://twitter.com/'+username+'">@'+username+'</a> - <a href="http://twitter.com/'+username+'/status/'+permalink+'" class="permalink">'+timestamp+'</a></h2';
			
			tweetIndex = nextIndex;
			
			$("article.favorites h1").html(tweet).animate({ opacity: 1 }, 500);
			$("article.favorites h2").html(meta).delay(200).animate({ opacity: 1 }, 500, function(){ cycleInquiry = setTimeout("fadeTweet()",timeBetweenTweets); });
			
		}
