var Twidget=new Class({Implements:[Options,Events],options:{user:"mootools",element:"tweets",count:5},toElement:function(){return $(this.options.element)},initialize:function(a){my=this;my.setOptions(a);my.element=$(my.options.element);try{$(my)}catch(b){(typeof console=="object")&&console.error("Twidget element not found");return}my.getTweets()},getTweets:function(){new Request.JSONP({url:"http://twitter.com/statuses/user_timeline/"+my.options.user+".json",data:{count:my.options.count},onComplete:my.procTweets.bind(my),onRequest:function(){this.fireEvent("request")}.bind(my),onCancel:function(){this.fireEvent("cancel")}.bind(my),timeout:5000}).send()},procTweets:function(h,f){if(!h[0]){return}var b;var a="";for(var d=0;d<h.length;d++){if(!h[d]||!h[d].text){break}var j=new Date(h[d].created_at);try{p=!j?"":j.timeDiffInWords()}catch(g){p=h[d].created_at}lnkfd=(typeof String.tweetify=="function")?h[d].text.tweetify():this.linkify(h[d].text);a+=this.markup(lnkfd,p)}this.showTweets(a).fireEvent("complete")},markup:function(b,a){return'<p class="tweet">'+b.replace("\n","<br />")+' <span class="when">'+a+"</span></p>"},linkify:function(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a> ').replace(/(^|\s|\(|\[)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>').replace(/(^|\s)#(\S+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>')},showTweets:function(a){$(this).set("html",a);return this}});
