String.prototype.reverse = function(){
	splitext = this.split("");
	revertext = splitext.reverse();
	reversed = revertext.join("");
	return reversed;
}

jQuery.fn.highlight = function (text, o) {
	return this.each( function(){
		var replace = o || '<span class="highlight">$1</span>';
		$(this).html( $(this).html().replace( new RegExp('('+text+'(?![\\w\\s?&.\\/;#~%"=-]*>))', "ig"), replace) );
	});
}

jQuery.fn.autolink = function () {
	return this.each( function(){
		//var re = /([-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.,~#?&//=]*)?)/g;
		var re = /([-a-zA-Z0-9+&@#/%=~_|][-A-Z0-9+&@#/%?=~_|!:,.;]*(?:\/\/:(?:s?ptth|ptf|elif)))(?!['<\"])/gi;
		var theHtml = $(this).html();
		theHtml = theHtml.reverse();
		theHtml = theHtml.replace(re, ' >a/<$1>"$1"=ferh a<');
		theHtml = theHtml.reverse();
		$(this).html(theHtml);
	});
}

jQuery.fn.mailto = function () {
	return this.each( function() {
		var re = /(([a-z0-9*._+]){1,}\@(([a-z0-9]+[-]?){1,}[a-z0-9]+\.){1,}([a-z]{2,4}|museum)(?![\w\s?&.\/;#~%"=-]*>))/g
		$(this).html( $(this).html().replace( re, '<a href="mailto:$1">$1</a>' ) );
	});
}