/*
 * jTwitter 1.1.1 - Twitter API abstraction plugin for jQuery
 * Copyright (c) 2009 jQuery Howto
 * Licensed under the GPL license:
 *   http://www.gnu.org/licenses/gpl.html
 * Plugin + Author URL:
 *   http://jquery-howto.blogspot.com
 */
(function(b){b.extend({jTwitter:function(d,a,c){if(!(d=="undefined"||a=="undefined")){if(b.isFunction(a)){c=a;a=5}b.getJSON("http://twitter.com/status/user_timeline/"+d+".json?count="+a+"&callback=?",function(e){b.isFunction(c)&&c.call(this,e)})}}})})(jQuery);

/* SUPPORT FUNCTIONS ADDED FOR PARSING */
String.prototype.linkTweetURL = function( )  
{
  var returning = this.value;
  var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
  returning = this.replace( regexp, "<a href=\"$1\">$1</a>" );
  return returning;
}

String.prototype.linkTweetUser = function( )  
{
  var returning = this.value;
  var regexp = /[\@]+([A-Za-z0-9-_]+)/gi;
  returning = this.replace(regexp,"<a href=\"http://twitter.com/$1\">@$1</a>");
  return returning;
}

String.prototype.linkTweetHash = function( ) 
{
  var returning = this.value;
  var regexp = / [\#]+([A-Za-z0-9-_]+)/gi;
  returning = this.replace(regexp, ' <a href="http://search.twitter.com/search?q=&tag=$1&lang=all">#$1</a>');
  return returning;
}

String.prototype.capTweetAwesome = function( ) 
{
  var returning = this.value;
  returning = this.replace(/(a|A)wesome/gi, 'AWESOME');
  return returning;
}

String.prototype.capTweetEpic = function( ) 
{
  var returning = this.value;
  returning = this.replace(/(e|E)pic/gi, 'EPIC');
  return returning;
}

String.prototype.makeTweetHeart = function( ) 
{
  var returning = this.value;
  returning = this.replace(/[&lt;]+[3]/gi, "<tt class='heart'>&#x2665;</tt>");
  return returning;
}

function relative_time( time_value, current_time ) 
{
   var dp = time_value.split(" ");
   var ds = dp[0]+', '+dp[1]+' '+dp[2]+', '+dp[5]+' '+dp[3];
   var parsed_date = Date.parse( ds );
   parsed_date = parsed_date + ( 3600 * 5 );
   var delta = parseInt( ( ( current_time - parsed_date ) / 1000 ) + ( 3600 * 5 ) );
   if(delta < 60) {
      return 'less than a minute ago';
   } else if(delta < 120) {
      return 'about a minute ago';
   } else if(delta < (45*60)) {
      return (parseInt(delta / 60)).toString() + ' minutes ago';
   } else if(delta < (90*60)) {
      return 'about an hour ago';
   } else if(delta < (24*60*60)) {
      return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
   } else if(delta < (48*60*60)) {
      return '1 day ago';
   } else {
      return (parseInt(delta / 86400)).toString() + ' days ago';
   }
}

   