String.prototype.truncate = function(length, appendString) {
	if(this.length > length) {
		return this.substring(0, length) + (appendString ? appendString : '');
	}
	else {
		return this;
	}
}

String.prototype.truncateWords = function(numberOfWords, appendString) {
	var words = this.split(' ');
	
	if(words.length > numberOfWords) {
		var newString = '';
		
		for(var i = 0; i < numberOfWords; i++) {
			newString += ' ' + words[i];
		}
		
		if(!appendString) {
			appendString = '';
		}
		
		return newString + appendString;
	}
	else {
		return this;
	}
}

function rearrangeTwitterStatus() {
	// Get the list item that contains the twitter status (a span and a link).
	var li = document.getElementById('twitter_update_list').getElementsByTagName('li')[0];
	var child = null;
	
	// Iterate through all of the list's child nodes.
	for(i in li.childNodes) {
		child = li.childNodes[i];
		
		if(child.nodeName) {
			// If the node is the span element then process and store the text and remove the element.
			if(child.nodeName.toLowerCase() == 'span') {
				var spanText = child.innerHTML.replace(/\s?<a.*\/a>/g,'').truncate(82, '&hellip;');
				li.removeChild(child);
			}
			
			// If the node is the link element then create a new link, give it the href, give it the
			// span text and replace the old one.
			if(child.nodeName.toLowerCase() == 'a') {
				var newLink = document.createElement('a');
				newLink.href = child.href;
				newLink.innerHTML = spanText;
				li.removeChild(child);
				li.appendChild(newLink);
				break;
			}
		}
	}
}
