jQuery.fn.reverse=Array.prototype.reverse;
String.prototype.links=function() {
    return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g,
    function(a) {
        return '<a href="' + a + '" target="_new">' + a + '</a>';
    });
};
String.prototype.user=function() {
    return this.replace(/[@]+[A-Za-z0-9-_]+/g,
    function(b) {
        var username = b.replace("@","")
        return '<a href="http://twitter.com/' + username + '" target="_new">' + b + '</a>';
    });
};
String.prototype.hashtags=function() {
    return this.replace(/[#]+[A-Za-z0-9-_]+/g,
    function(c) {
        var hashtag=c.replace("#","")
        return '<a href="http://search.twitter.com/search?q='+hashtag+'" target="_new">' + c + '</a>';
    });
};

function getTweets(elem) {
    elem=jQuery(elem);
	var url="http://search.twitter.com/search.json?q=ehxspring&from=&rpp=25&since_id="+last_id+"&callback=?";
	jQuery.getJSON(url,function(json) {
    	jQuery(json.results).reverse().each(function() { 
    	    if(jQuery('#tw_'+this.id).length==0) { 
    	        var posted= new Date(this.created_at); 
    	        var tweet='<div class="tweet" id="tw_'+this.id +'">'+
    	        			'<div class="status"><a href="http://twitter.com/'+this.from_user+'" target="_new"> '+this.from_user+'</a> ' +
							this.text.links().user().hashtags()+' ' +dateFormat(posted, "h:MM TT mmm dS, yyyy")+'</div>' 
							'</div>';
    	        
				if (last_id < this.id) { 
    	        	last_id=this.id;
    	        }
    	        elem.prepend(tweet);
				
    	        jQuery('#tw_'+this.id).hide();
    	        jQuery('#tw_'+this.id+':not(".blockedTweet")').fadeIn('slow');
             	jQuery('#twitter-feed').jScrollPane({showArrows:true});
    	    }
    	});
	});
timeout = setTimeout(function(){getTweets(elem)},ttl_timeoutSpeed);
return(false);
}


jQuery(document).ready(function(){
    jQuery('#twitter-feed').each(function() {
		last_id = 0;
    	ttl_timeoutSpeed = 10000;
        getTweets(this);
});
    
jQuery(document).ready(function(){
    jQuery('#twitter-feed').jScrollPane({showArrows:true});
});     
  
  
reinitialiseScrollPane = function()
	{
		jQuery('#twitter-feed').jScrollPane();
	}
});
