var timer; 
var timerDisplay;  
var tweetCount = 0; 
var tweets = new Array();
 
$(document).ready(function() {   
	getSearch(); 
});   
  
function getSearch()   
{
	clearTimeout(timer);   
	var count = 0;
	var currentTweet = tweets[tweetCount];
	
	$.post("getSearch.php", function(xml){   
		$('entry',xml).each(function(i){ 
			tweets[count] = $(this).find("title").text();
			
			if (currentTweet == tweets[count]){
				tweetCount += (count - tweetCount);
			}
			
			count++;
		});
		
		if (tweetCount == 0){
			tweetCount = tweets.length - 1;
		}
		displayTweets();	
	});   
	
	timer = setTimeout('getSearch()', 30000);   
}

function displayTweets(){
	clearTimeout(timerDisplay); 
	$("#bubble").fadeIn("slow");
	$(".str").html(tweets[tweetCount]);
	timerDisplay = setTimeout('fadeTweets()', 7000);  
}

function fadeTweets(){
	clearTimeout(timerDisplay); 
	$("#bubble").fadeOut("slow");
	
	if (tweetCount > 0){
		tweetCount--;
	}	
	
	timerDisplay = setTimeout('displayTweets()', 2000);  
}
