

/*	James

	File:		Format JS
	Author:		James Brannon

	-------------------------------------------------------------------------------------------------------------------- */
	
	String.prototype.parseURL = function() {
		return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
			return '<a href="'+url+'" target="_blank">'+url+'</a>';
		});
	};
	String.prototype.parseUsername = function() {
		return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
			var orig = u,
				username = u.replace("@","");
			return '<a href="http://twitter.com/'+username+'" target="_blank" title="'+orig+'">'+orig+'</a>';
		});
	};
	String.prototype.parseHashtag = function() {
		return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) {
			var orig = t,
				tag = t.replace("#","%23");
					return '<a href="http://search.twitter.com/search?q='+tag+'" target="_blank" title="'+orig+'">'+orig+'</a>';
		});
	};
	String.prototype.urlencode = function() {
		return this.replace( / /g, '%20' ).replace( /:/g, '%3a' ).replace( /\//g, '%2f' ).replace( /#/g, '%23' );
	};
	
	String.prototype.truncate = function(limit,link) {
		return this.substring(0, limit).split(" ").slice(0, -1).join(" ") + "...";
	};
	String.prototype.noImages = function(){
		return this.replace(/<img(.*?)\/>/g,'').replace(/<br\/>/g,'').replace(/<em>/g,'').replace(/<\/em>/g,'');
	};
	String.prototype.strip = function(){
		return this.replace(/ /g,'').replace('(','').replace(')','').toLowerCase();
	};
	String.prototype.emtolink = function(){
		return this.replace(/#+<em>+[A-Za-z0-9-_]+<\/em>/g, function(t) {
			var tag = t.replace("#","").replace(/<em>/g,'').replace(/<\/em>/g,'')
				return "<a rel=\"nofollow\" target=\"_blank\" href=\"http://search.twitter.com/search?q=%23"+tag+"\" title=\"#"+tag+"\" class=\" \">#"+tag+"</a>"
		}).replace(/@+<em>+[A-Za-z0-9-_]+<\/em>/g, function(t) {
			var tag = t.replace("@","").replace(/<em>/g,'').replace(/<\/em>/g,'')
				return "<a rel=\"nofollow\" target=\"_blank\" href=\"http://search.twitter.com/search?q=%40"+tag+"\" title=\"@"+tag+"\" class=\" \">@"+tag+"</a>"
		});
	}
