function newEl(elName, className) {
	el = document.createElement(elName);
	el.className = className;
	return el;
}

function loadTwitter(oTweets) {
	mDiv = newEl('div','twtr-tweets');
	document.getElementById('twitter_holder').appendChild(mDiv);
	for (i = 0; i < oTweets.length; i++) {
		nDiv = newEl('div','twtr-tweet');
		tDiv = newEl('span','twtr-tweet-text');
		oTweets[i].text = oTweets[i].text.replace(/(http:[^ ]+)/g,"<a href='$1'>$1</a>")
			.replace(/>(http:\/\/[^\/]+\/)/g,">$1 ");
		tDiv.innerHTML = oTweets[i].text + ' ';
		nDiv.appendChild(tDiv);
		dDiv = newEl('a','twtr-tweet-link');
		dDiv.href = 'http://twitter.com/encs/status/'+oTweets[i].id;
		dDiv.innerHTML = simplifyDate(oTweets[i].created_at);
		nDiv.appendChild(dDiv);
		mDiv.appendChild(nDiv);
		if (mDiv.offsetHeight > 210) {
			nDiv.parentNode.removeChild(nDiv);
			break;
		}
	}
}

function simplifyDate(f) {
	var h = new Date();
	var d = new Date(f);
	if (navigator.userAgent.match(/MSIE\s([^;]*)/)) {
		d = Date.parse(f.replace(/( \+)/, " UTC$1"))
	}
	var g = h - d;
	var a = 1000,	b = a * 60,	c = b * 60,	e = c * 24,	Z = e * 7;
	if (isNaN(g) || g < 0) {return ""}
	if (g < a * 7) {return "right now"}
	if (g < b) {return Math.floor(g / a) + " seconds ago"}
	if (g < b * 2) {return "about 1 minute ago"}
	if (g < c) {return Math.floor(g / b) + " minutes ago"}
	if (g < c * 2) {return "about 1 hour ago"}
	if (g < e) {return Math.floor(g / c) + " hours ago"}
	if (g > e && g < e * 2) {return "yesterday"}
	if (g < e * 365) {return Math.floor(g / e) + " days ago"} 
	else {return "over a year ago"}
};