/*
JUITTER 1.0.0 - 22/07/2009 - http://juitter.com
BY RODRIGO FANTE - http://rodrigofante.com
Modified by Instantiate LLP - http://instantiate.co.uk
Juitter is distributed under the MIT License
*/
(function(b){var l=20,i='<p id="juitter_loading">Loading messages...</p>',m="Read it on Twitter",q="",h=1,e,d,j,n,c,r,s,o,p=1,k,t=1,u=!1;b.Juitter={registerVar:function(a){e=a.searchType;d=a.searchObject;j=a.live;n="";c=a.placeHolder?a.placeHolder:"juitterContainer";i=a.loadMSG?a.loadMSG:i;r=a.imgName?a.imgName:"loader.gif";l=a.total?a.total:l;m=a.readMore?a.readMore:m;s=a.nameUser?a.nameUser:"image";o=a.filter;openLink=a.openExternalLinks?"target='_blank'":""},start:function(a){ultID=0;b("#"+c)&&
(this.registerVar(a),this.loading(),q=this.createURL(),this.conectaTwitter(1),j!=void 0&&!u&&this.temporizador())},update:function(){this.conectaTwitter(2);j!=void 0&&this.temporizador()},loading:function(){i=="image/gif"?b("<img></img>").attr("src",r).appendTo("#"+c):b("#"+c).html(i)},createURL:function(){var a="";jlg=n.length>0?"&lang="+n:jlg="";var b=d.search(/,/);b>0&&(d=d.replace(/,/g,"+OR+from%3A"));e=="fromUser"&&b<=0?a="http://search.twitter.com/search.json?q=from%3A"+d:e=="fromUser"&&b>=
0?a="http://search.twitter.com/search.json?q=from%3A"+d:e=="toUser"&&b<=0?a="http://search.twitter.com/search.json?q=to%3A"+d:e=="toUser"&&b>=0?a="http://search.twitter.com/search.json?to%3A"+d:e=="searchWord"&&(a="http://search.twitter.com/search.json?q="+d+jlg);a+="&rpp="+l;return a},conectaTwitter:function(){b.ajax({url:q,type:"GET",dataType:"jsonp",timeout:1E4,error:function(){b("#"+c).html('<p id="juitter_loading">Failed to get twitter feeds!</p>');t=1},success:function(a){t==1&&b("#"+c).html("");
b.each(a.results,function(a,f){a==0&&(k=-p+1,h=0,b("<ul></ul>").attr("id","twittList"+k).attr("class","twittList").prependTo("#"+c));if(f.text!="undefined"){var d="http://twitter.com/"+f.from_user+"/status/"+f.id,e=f.text;mHTML=s=="image"?"<a href='http://www.twitter.com/"+f.from_user+"'><img src='"+f.profile_image_url+"' alt='"+f.from_user+"' class='juitterAvatar' /></a><span class='juitterUser'>"+f.from_user+"</span>"+b.Juitter.textFormat(e)+"<span class='juitterTime'>"+b.Juitter.pretty_date(f.created_at)+
"</span>":"<a href='http://www.twitter.com/"+f.from_user+"'>@"+f.from_user+":</a> "+b.Juitter.textFormat(e)+"<span class='time'>"+f.created_at+"</span><a href='"+d+"' "+openLink+">"+m+"</a>";b("<li></li>").html(mHTML).attr("id","twittLI"+h).attr("class","twittLI").appendTo("#twittList"+k);b("#twittLI"+h).hide();b("#twittLI"+h).show("slow");h++}});b("#twittList"+p).hide("slow",function(){b(this).remove()});p=k}})},filter:function(a){return o?(searchWords=o.split(","),searchWords.length>0?(cleanHTML=
a,b.each(searchWords,function(a,b){sW=b.split("->").length>0?b.split("->")[0]:b;rW=b.split("->").length>0?b.split("->")[1]:"";regExp=eval("/"+sW+"/gi");cleanHTML=cleanHTML.replace(regExp,rW)})):cleanHTML=a,cleanHTML):a},textFormat:function(a){var c=/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,a=a.replace(c,"<a href='$1' class='extLink' "+openLink+">$1</a>"),c=/[\@]+([A-Za-z0-9-_]+)/ig,a=a.replace(c,"<a href='http://twitter.com/$1' class='profileLink'>@$1</a>"),c=/[\#]+([A-Za-z0-9-_]+)/ig,
a=a.replace(c,"<a href='http://juitter.com/#$1' onclick='$.Juitter.start({searchType:\"searchWord\",searchObject:\"$1\"});return false;' class='hashLink'>#$1</a>");e=="searchWord"&&(tempParam=d.replace(/&ors=/,""),arrParam=tempParam.split("+"),b.each(arrParam,function(b,c){regExp=eval("/"+c+"/gi");newString=new String(" <b>"+c+"</b> ");a=a.replace(regExp,newString)}));return a},temporizador:function(){u=!0;aTim=j.split("-");aTim[0]=="live"&&aTim[1].length>0&&(tempo=aTim[1]*1E3,setTimeout("$.Juitter.update()",
tempo))},pretty_date:function(a){var b=[[60,"seconds",1],[120,"1 minute ago","1 minute from now"],[3600,"minutes",60],[7200,"1 hour ago","1 hour from now"],[86400,"hours",3600],[172800,"yesterday","tomorrow"],[604800,"days",86400],[1209600,"last week","next week"],[2419200,"weeks",604800],[4838400,"last month","next month"],[29030400,"months",2419200],[58060800,"last year","next year"],[290304E4,"years",29030400],[580608E4,"last century","next century"],[580608E5,"centuries",290304E4]],a=(new Date-
new Date(a))/1E3,c="ago",d=1;a<0&&(a=Math.abs(a),c="from now",d=2);for(var e=0,g;g=b[e++];)if(a<g[0])return typeof g[2]=="string"?g[d]:Math.floor(a/g[2])+" "+g[1]+" "+c;return time}}})(jQuery);
