if (!window['makkintosshu']) { window['makkintosshu'] = {}; }
if (!window['makkintosshu']['twitterStatuses']) { window['makkintosshu']['twitterStatuses'] = {}; }
makkintosshu.twitterStatuses = {
	elementId: 'mtaTwitter',
	tweetCount: 5,
	filterReplies: false,
	filterRetweets: false,
	showIcon: true,
	
	// Make date parseable in IE [Jon Aquino 2007-03-29]
	// http://jonaquino.blogspot.com/2006/12/twitter-increasing-number-of-twitters.html
	fixDate: function (d) {
		var a = d.split(' ');
		var year = a.pop();
		return a.slice(0, 3).concat([year]).concat(a.slice(3)).join(' ');
	},

	relativeTime: function (time_value) {
		var parsed_date = Date.parse(time_value);
		
		var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
		var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
		
		if ( delta < 60 ) {
			return 'less than a minute ago';
		} else if ( delta < 120 ) {
			return 'about a minute ago';
		} else if ( delta < (45*60) ) {
			return (parseInt(delta / 60)).toString() + ' minutes ago';
		} else if ( delta < (90*60) ) {
			return 'about an hour ago';
		} else if ( delta < (24*60*60) ) {
			return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
		} else if ( delta < (48*60*60) ) {
			return '1 day ago';
		} else {
			return (parseInt(delta / 86400)).toString() + ' days ago';
		}
	},
	
	twitterCallback: function (obj) {
		var id = obj[0].user.id;
		var statuses_html = '';
		var isEven = false;
		var maxTweets = makkintosshu.twitterStatuses.tweetCount;
		var tweetCount = 0;
		
		if ( makkintosshu.twitterStatuses.showIcon ) {
			statuses_html += '<a href="http://twitter.com/' + obj[0].user.screen_name + '"><img src="' + obj[0].user.profile_image_url + '" alt="' + obj[0].user.name + '" /></a>' + "\n";
		}
		//statuses_html += "<ul>\n";
		
		for ( var i = 0; i < obj.length && tweetCount < maxTweets; i++ ) {
			var tweet_text = obj[i].text;
		
			if ( !makkintosshu.twitterStatuses.filterReplies || (tweet_text.match(/^@[A-Z0-9_]+/gi) == null) ) {
				tweetCount++;
    				
				tweet_text = tweet_text.replace(/((http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(\/*)(:(\d+))?([A-Z0-9_\/.?~-]*))/gi, '<a href="$1">$1</a>');
				tweet_text = tweet_text.replace(/(@([A-Z0-9_]+))/gi, '@<a class="reply" title="$2 on twitter" href="http://twitter.com/$2">$2</a>');
				tweet_text = tweet_text.replace(/(#([A-Z0-9_]+))/gi, '<a class="hashtag" href="http://twitter.com/search?q=%23$2">#$2</a>');
    				
				
				/*if ( tweetCount == 1 ) {
    					statuses_html += 'first ';
				} else if ( tweetCount == maxTweets ) {
					statuses_html += 'last';
				}
				if ( isEven ) {
					statuses_html += ' even';
				} else {
					statuses_html += ' odd';
				}
				statuses_html += '">';*/
				statuses_html += tweet_text;
				
				//statuses_html += ' <span class="when"><a href="http://twitter.com/' + obj[i].user.screen_name + '/statuses/' + obj[i].id + '">' + makkintosshu.twitterStatuses.relativeTime(makkintosshu.twitterStatuses.fixDate(obj[i].created_at)) + "</a></span></li>\n";
				
				isEven = !isEven;
			}
		}
		statuses_html += "</ul>\n";
		
		document.getElementById(makkintosshu.twitterStatuses.elementId).innerHTML = statuses_html;
	}
}

// Depricated, but kept for backwards compatibility with 0.5 and earlier... for now
var mtaTwitterStatusesFilterReplies = false;
function mtaTwitterCallback(obj) { makkintosshu.twitterStatuses.twitterCallback(obj); }


