/*

Real Time Search in Twitter Ajax JQuery 

Created by Ignacio Gorostiza : http://www.hellogoogle.com

Base on code by Steve Reynolds : http://www.reynoldsftw.com 

*/



var timer;   

var max_id=0;

var flag_update;

var my_time;

var theQuery = "Haiti";   





  

$(document).ready(function() {   

$("#term").html(theQuery);

getSearch(); 

  

});   

  

function getSearch()   

{



	clearTimeout(timer);   

	var results_all = "";   

  

	$.post("getSearch.php", {query: theQuery, id:max_id},  function(xml){   

		flag_update=false;

		$('entry',xml).each(function(i){   

			var title = $(this).find("title").text();  

			var id= $(this).find("id").text().split(":")[2];  

			if (id>max_id) {



				max_id=id;

				$("#container_id").html(max_id);

				flag_update=true;

			}

				results_all = results_all + title + "<BR>";   



		});   

	

	   if (flag_update){$("#container_all").fadeOut(1000, function () {

		$("#container_all").html(results_all);

		$("#container_all").fadeIn(1000);

						my_time=0;

      });}

	   else{

		   			my_time =my_time+15;

	   }

	   		$("#my_time").html(my_time);



	  

	});   

  

	timer = setTimeout('getSearch()', 15000);   





}
