/* * (c) 2009 Chad Etzel - TweetGrid.com * This file may not be reproduced without the express written permission of the author. */ var glb_search='';var glb_rpp=100;var lastID=0;var searchtimer;var timeout=10000;var timeout_min=10000;var timeout_max=60000;var initarr=[];function jtw_urlencode(str){str=escape(str);str=str.replace(/\+/g,'%2B');str=str.replace(/%20/g,'+');str=str.replace(/\*/g,'%2A');str=str.replace(/\//g,'%2F');str=str.replace(/@/g,'%40');str=str.replace(/#/g,'%23');return str;}function dehtmlify(str){str=str.replace(/</g,'<');str=str.replace(/>/g,'>');str=str.replace(/&/g,'&');str=str.replace(/"/g,'"');return str;}function getTweetsInit(arr,iter){var rand=Math.floor(Math.random()*3000000);var page=iter;var url="http://search.twitter.com/search.json?q="+jtw_urlencode(glb_search)+"&rpp="+glb_rpp.toString()+"&page="+iter+"&rand="+rand+"&callback=?";$.getJSON(url,function(data){arr=$.merge(arr,data.results);if(iter<5){getTweetsInit(arr,iter+1);}else{var obj={};obj.results=arr;handleTweets(obj);}});}function getTweets(){var rand=Math.floor(Math.random()*3000000);var url="http://search.twitter.com/search.json?q="+jtw_urlencode(glb_search)+"&rpp="+glb_rpp.toString()+"&since_id="+lastID+"&rand="+rand+"&callback=?";$.getJSON(url,handleTweets);}function removepunc(str){str=str.replace(/:/g,'');str=str.replace(/\./g,'');str=str.replace(/-/g,'');str=str.replace(/_/g,'');str=str.replace(/ /g,'');str=str.replace(/'/g,'');str=str.replace(//g,'');str=str.replace(/!/g,'');return str;}function handleTweets(arr){var i;for(i=arr.results.length-1;i>=0;i--){var m;if(arr.results[i].id<=lastID){continue;}var source=dehtmlify(arr.results[i].source);var re=new RegExp("href=\"(.*)\">(.*)<\/a","g");m=re.exec(source);link=m[1];source=m[2];updatesourcestab(source,link);}if(arr.results.length>0){lastID=arr.results[0].id;}throttle(arr.results.length);$('#sourcestab').trigger("update");$('#sourcestab').trigger("reSort");$('#loading').text('');tablify();}function throttle(hit){if(hit){timeout=timeout_min;}else{timeout=Math.floor(timeout*1.15);if(timeout>timeout_max){timeout=timeout_max;}}stoptimers();starttimers();}function tablify(){var i=0;var opac=100;$('#sourcestab tbody tr').each(function(){opac=Math.max((100-i),40);opac=opac/100;$(this).css('opacity',opac);i+=2;});}function updatesourcestab(src,link){srcc=removepunc(src);var obj=$('#sourcestab');if(obj.find('.'+srcc).length==0){obj.find('tbody').append('