// JSON-P Twitter fetcher for Octopress
// (c) Brandon Mathis // MIT License
/* Sky Slavin, Ludopoli. MIT license.  * based on JavaScript Pretty Date * Copyright (c) 2008 John Resig (jquery.com) * Licensed under the MIT license.  */
function prettyDate(a){if(navigator.appName==="Microsoft Internet Explorer")return"<span>&infin;</span>";var b={just_now:" now",minute_ago:"1m",minutes_ago:"m",hour_ago:"1h",hours_ago:"h",yesterday:"1d",days_ago:"d",last_week:"1w",weeks_ago:"w"},c=new Date,d=c.getTime(),e=d+6e4,f=new Date(a),g=(e-f.getTime())/1e3,h=Math.floor(g/86400);return isNaN(h)||h<0?"<span>&infin;</span>":h===0&&(g<60&&b.just_now||g<120&&b.minute_ago||g<3600&&Math.floor(g/60)+b.minutes_ago||g<7200&&b.hour_ago||g<86400&&Math.floor(g/3600)+b.hours_ago)||h===1&&b.yesterday||h<7&&h+b.days_ago||h===7&&b.last_week||h>7&&Math.ceil(h/7)+b.weeks_ago}function linkifyTweet(a,b){a=a.replace(/(https?:\/\/)([\w\-:;?&=+.%#\/]+)/gi,'<a href="$1$2">$2</a>').replace(/(^|\W)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>').replace(/(^|\W)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>');for(var c in b)if(b[c].expanded_url!=null){var d=new RegExp(b[c].url,"g");a=a.replace(d,b[c].expanded_url);var d=new RegExp(">"+b[c].url.replace(/https?:\/\//,""),"g");a=a.replace(d,">"+b[c].display_url)}return a}function showTwitterFeed(a,b){var c=document.getElementById("tweets"),d="";for(var e in a)d+='<li><p><a href="http://twitter.com/'+b+"/status/"+a[e].id_str+'">'+prettyDate(a[e].created_at)+"</a>"+linkifyTweet(a[e].text.replace(/\n/g,"<br>"),a[e].entities.urls)+"</p>"+"</li>";c.innerHTML=d}function getTwitterFeed(a,b,c){b=parseInt(b,10),$.ajax({url:"http://api.twitter.com/1/statuses/user_timeline/"+a+".json?trim_user=true&count="+(b+20)+"&include_entities=1&exclude_replies="+(c?"0":"1")+"&callback=?",dataType:"jsonp",error:function(a){$("#tweets li.loading").addClass("error").text("Twitter's busted")},success:function(c){showTwitterFeed(c.slice(0,b),a)}})}
