$ = jQuery;
maxPageSize = 100;
function getTwitterCount(tag, page)
{
	page = page ? page : 1;
	//	console.log("checking tag=%s and page=%i", tag, page);
	$.getScript("http://search.twitter.com/search.json?q="+encodeURIComponent("#"+tag)+"&callback=showCount&rpp="+maxPageSize+"&page="+page);
}

function showCount(o)
{
	var page = o.page;
	var count = o.results.length;
	var tag = o.query.substring(3);
	
	//-- Animate from the beginning of the current page until the current count
	var pageStart = (page - 1) * maxPageSize;
	var pageEnd = pageStart + count;
	animateNumber($("#con_"+tag)[0], pageStart, pageEnd, 1000);	
	
	//-- If this page is full, fetch another one
	if (count == maxPageSize)
		setTimeout(function(){ getTwitterCount(tag, page + 1) }, 0);
}

function animateNumber(div, from, to, time)
{
	div.innerHTML = to + ((to != 1) ? " votes" : " vote");
}