// JavaScript Document
$(document).ready(function() {
	i = 1;
	getTopTwitters();
	$('#twitBox').hide();
});
function text2xml(s) {
	var x, ie = /msie/i.test(navigator.userAgent);
	try{
		var p = ie? new ActiveXObject("Microsoft.XMLDOM") : new DOMParser();
		p.async = false;
	}catch(e){
		throw new Error("XML Parser could not be instantiated")
	};
	try{
		if(ie) x = p.loadXML(s)? p : false;
		else x = p.parseFromString(s, "text/xml");
	}catch(e){
		throw new Error("Error parsing XML string")
	};
	return x;
}
function getTopTwitters() {
	$.post('lib/getTopTwitters.php',{ }, function(xml) {
		setTopTwitters(xml);
	});
}
function setTopTwitters(xml) {
	xml = text2xml(xml);
	arr = jQuery.makeArray($("user",xml));
	$(arr).each( function(id) {
		entry = $(arr).get(id);
		i = (i+1)%2;
		$("#topUsers_bdy").prepend("<div class='twitter"+i+" new'>"+
								"<table>"+
									"<tr>"+
										"<td class='tpImage' rowspan='2'><img height='75%' width='75%' src='"+$("profile_image_url",entry).text()+"'></td>"+
<!--										"<td class='tAuthor'><a href='userprofile.php?user="+$("screen_name",entry).text()+"'>"+$("screen_name",entry).text()+"</a></td>"+-->
										"<td class='tAuthor'>"+
										"<a href='http://twitter.com/"+
										$("screen_name",entry).text()+
										"'>"+
										$("screen_name",entry).text()+
										"</a></td>"+
									"</tr>"+
									"<tr>"+
										"<td class='tDate'>"+$("followers",entry).text()+" followers</td>"+
									"</tr>"+
								"</table>"+
							  "</div>");
		$("#topUsers_bdy > div.new").slideDown("slow", function() {$(this).removeClass("new")} ).show();
	});
}