<!--

var timezone = '';
var total;
var memdata = '';
var twitList = new Array();
var moreList = new Array();

// process the twitter feed
function birdFeed(memdata,zone,total,feeds) {
	timezone = zone/3600;

	var usErs = memdata.split("^");
	for (var i=0;i<usErs.length;i++) {
		var data = eval('(' + usErs[i] + ')');
		for (var k=0;k<data.length;k++) {
			var item = data[k];


			// what to do for the most recent status update from each user
			if (k==0) {

				if (total == 1)	{
					var divdisplay = 'block';
					var collexp = '';
				} else {
					var divdisplay = 'none';
					var collexp = 'coll';
				}

				// friendly time and date
				var realtime = goodTime(item.created_at);
				var bigtime = bigUp(item.created_at);

				// create new object array with most recent post info
				var twitterer = new Array();
				twitterer.time = bigtime;
				twitterer.text = "<li id='"+item.user['id']+"'><span id='colexp-"+item.user['id']+"'><a id='link-"+item.user['id']+"' class='"+collexp+"' href='javascript:showRecent("+item.user['id']+")' title='Expand This' style='border-bottom:0px;'></a></span><b>"+item.user['name']+"</b> <a href='http://twitter.com/"+item.user['screen_name']+"' target='_new' style='border-bottom:0px;'><img src='images/twitter.jpg' style='height:auto;width:auto;float:none;' /></a> <span id='twit-time'>"+realtime+"</span> "+hashtags(prototype.string.autolink(item.text))+" </li><div id='more-"+item.user['id']+"' style='display:"+divdisplay+"'></div>";

				// add object array to the recent status update array
				twitList[twitList.length] = twitterer;

			// what to do for the next 5 status updates
			} else if (k<6) {

				// friendly time and date
				var realtime = goodTime(item.created_at);

				// create new object array with post info
				var twitterer = new Array();
				twitterer.user = item.user['id'];
				twitterer.text = "<li class='twit-child'><span id='twit-time'>"+realtime+"</span> "+hashtags(prototype.string.autolink(item.text))+"</li>";

				// add object array to an array of the previous status updates
				moreList[moreList.length] = twitterer;

			}
		}
	}

	// set 'twitter' and 'twitter-list' properties
	var t = document.getElementById("twitter");
	var tl = document.getElementById("twitter-list");
	var c = t.parentNode;
	var h = c.parentNode.style.height;
	var w = c.parentNode.offsetWidth;
	var nh = h.substring(0,3);
	t.style.height = (nh-75)+"px";
	tl.style.width = (w-60)+"px";

	// output to website when all users have been loaded
	if(total == twitList.length) {
		outputFeed(total,feeds);
	}
}

// output all data to the webpage
function outputFeed(total,feeds){
	if (total >feeds) total = feeds;
	$("#status").hide();
	twitList.sort(sortByTime);
	twitList.reverse();
	for (i=0;i<total;i++) {
		if (twitList[i].text) {
			$("#twitter-list ul").append(twitList[i].text);
			if (i<(total-1)){
				$("#twitter-list ul").append("<hr />");
			}
		}
	}
	for (k=0;k<moreList.length;k++)	{
		var userdiv = document.getElementById("more-"+moreList[k].user);
		if (userdiv) {
			$(userdiv).append(moreList[k].text);
		}
	}
}

// sort array by 'time' property
function sortByTime(a, b) {
    var x = parseInt(a.time);
    var y = parseInt(b.time);
		return x - y;
}

// recognize hash tags and '@usernames' in a tweet and link them up!
function hashtags(tweet) {
	var newtweet = "";
	var hashfound = "FALSE"
	var word = "";
	var hash = "";
	var endword = "FALSE";
	for (i=0;i<tweet.length;i++) {
		var thischar = tweet.substr(i,1);
		if (hashfound == "TRUE") {
			word = word + thischar;
			if (thischar == " " || thischar == "." || thischar == ":" )	{
				word = word.substr(0,word.length);
				newtweet = newtweet+word.substr(0,word.length-1)+ "'>" +hash+word.substr(0,word.length-1)+ "</a>" +thischar+ " ";
				word = "";
				hash = "";
				hashfound = "FALSE";
			} else if (i == (tweet.length-1)) {
				newtweet = newtweet+word.substr(0,word.length)+ "'>" +hash+word.substr(0,word.length)+ "</a>";
				word = "";
				hash = "";
				hashfound = "FALSE";
				endword = "TRUE";
			}
		}
		else if (thischar == "#" || (thischar == "@" && tweet.substr((i+1),1)!=" ")) {
			var goahead = "FALSE";
			if (i==0) {
				goahead = "TRUE";
			} else if (tweet.substr((i-1),1)==" ") {
				goahead = "TRUE";
			}
			if (goahead == "TRUE")	{
				if (thischar == "#") {
					newtweet = newtweet + "<a target='_new' href='http://hashtags.org/tag/";
				} else if (thischar =="@") {
					newtweet = newtweet + "<a target='_new' href='http://twitter.com/";
				}
				hash = thischar;
				hashfound = "TRUE";
			}
		}
		if (hashfound == "FALSE" && endword == "FALSE") {
			newtweet = newtweet + thischar;
		}
	}
	return newtweet;
}

// show the user's recent status updates
function showRecent(e) {
	o = document.getElementById("more-"+e);
	o.style.display = 'block';
	hs = document.getElementById("link-"+e);
	$(hs).attr("class","exp");
	ce = document.getElementById("colexp-"+e);
	ce.innerHTML = "<a id='link-"+e+"' class='exp' href='javascript:hideRecent("+e+")' style='border-bottom:0px'>&nbsp;</a>";
}

// hide the recent status updates
function hideRecent(e) {
	ne = "more-"+e;
	o = document.getElementById(ne);
	o.style.display = 'none';
	hs = document.getElementById("link-"+e);
	$(hs).attr("class","coll");
	ce = document.getElementById("colexp-"+e);
	ce.innerHTML = "<a id='link-"+e+"' class='coll' href='javascript:showRecent("+e+")' style='border-bottom:0px'>&nbsp;</a>";
}

// create friendly time and date strings
function goodTime(timestring) {
	var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	var days = [31,28,31,30,31,30,31,31,30,31,30,31];
	var createsplit = timestring.split(" ");
	var timesplit = createsplit[3].split(":");
	var hours = parseInt(timesplit[0])+timezone; //
	var day = createsplit[2];
	var month = createsplit[1];
	if (hours <=0)	{
		hours = hours+24;
		day = String(createsplit[2]-1);
		if (day == "0")	{
			for (i=0;i<months.length;i++)	{
				if (month == months[i])	{
					if (month == "Jan") {
						month = "Dec";
						day = days[0];
					} else {
						month = months[i-1];
						day = days[i-1];
					}
				}
			}
		}

	}
	if (hours >12) {
		var time = hours-12+":"+timesplit[1]+"pm";
	} else if (hours==12) {
		var time = hours+":"+timesplit[1]+"pm";
	}else {
		var time = hours+":"+timesplit[1]+"am";
	}

	/*if (day.substr(0,1)=="0") {
		day = day.substr(1,1);
	}*/

	var date = month+" "+day;
	var timedate = date+" "+time;

	return timedate;
}

// create a number representation of the time, like unix timestamp
function bigUp(timestring) {
	var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	var newsplit = timestring.split(" ");
	var timesplit = newsplit[3].split(":");
	var years = newsplit[5];
	var month = newsplit[1];
	var hours = parseInt(timesplit[0])+timezone+1; // the "+1" is for daylight savings time
	var day = newsplit[2];
	var mins = parseInt(timesplit[1]);

	for (i=0;i<months.length;i++)	{
		if (month == months[i]) {
			var monthInt = i+1;
		}
	}

	return parseInt((years*3600*24*30*12)+(monthInt*3600*24*30)+(day*3600*24)+(hours*3600)+(mins*60));
}

////////////////////////
// AUTOLINK FUNCTIONS //
////////////////////////

var prototype = {};
prototype.string = {};

prototype.string.autolink = function (string, options){
    if(!options) options = {};
    if(!options.limit) options.limit = 20;
    if(!options.tagFill) options.tagFill = '';

    var regex = /((http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi;

    string = string.replace(regex, function(value){
        //value = value.toLowerCase();
        var m = value.match(/^([a-z]+:\/\/)/);
        var nice;
        var url;

        if(m)
        {
            nice = value.replace(m[1],'');
            url = value;
        }
        else
        {
            nice = value;
            url = 'http://' + nice;
        }

				var end = url.substr(-1);
				if (end == ")")	{
					url = url.substring(0,url.length-1);
					nice = nice.substring(0,nice.length-1);
				}

				if (end == ".")	{
					url = url.substring(0,url.length-1);
					nice = nice.substring(0,nice.length-1);
				}


        return '<a href="' + url + '"' + (options.tagFill != '' ? (' ' + options.tagFill) : '')+ '>' + prototype.string.autolinkLabel(nice, options.limit) + '</a>';
    });

    return string;
};


prototype.string.autolinkLabel = function (text, limit){

    if (!limit){ return text; }

    if (text.length > limit){
        return text.substr(0, limit - 3) + '...';
    }

    return text;
};

-->