/*$(function()
{
	$('.scroll-pane').jScrollPane();
});
*/
var tweets;
var fourSqData;
var mayors;
var checkIns;
var hereNow;

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function setTweets(tweetsData) {
   tweets = tweetsData;
   var resultsHtml='';
   for (loopCtrl=0;loopCtrl<tweets.length;loopCtrl++) {
	   var thisObj=tweets[loopCtrl];
	   if (typeof(thisObj.fromuser) != 'undefined') {
		   resultsHtml += '<li style="text-align:left;line-height:15px;vertical-align:middle;"><div class="tweetRow" style="text-align:left;vertical-align:middle;margin-bottom:20px;margin-top:5px;">@' + thisObj.fromuser + '<br/>' + thisObj.tweet + '</div></li>';
	   }
   }
   $(".twitterScroll").html('<ul>'+resultsHtml+'</ul>');
   $(".twitterScroll").jCarouselLite({
        auto: 8000,
        vertical: true,
        circular: true,
        visible: 6
    });
}

function setFourSq(fourSqData) {
	mayors = fourSqData.mayors;
	hereNow = fourSqData.herenow[0].herenow;
	checkIns = addCommas(fourSqData.checkins[0].checkins);
	
	$("#hereNowCount").text(hereNow);
	$("#checkInCount").text(checkIns);
	   var maxCols=1;
	   var curCol=0;
	   var resultsHtml = "";
	   for (loopCtrl=0;loopCtrl<mayors.length;loopCtrl++) {
		   var thisObj=mayors[loopCtrl];
		   if ( (thisObj.photo != '') && (thisObj.firstname != '') ) {
			   if (curCol==0) {
				   resultsHtml += '<div id="row"><div style="float:left;width:190px;height:50px;overflow:hidden;">';
			   } else {
				   resultsHtml += '<div style="float:left;width:190px;height:50px;">';
			   }
		
			   resultsHtml += '<div style="float:left;width:35px;margin:0px;"><img width=\'35\'border=\'0\' src=\'' + thisObj.photo + '\'></div><div style="vertical-align:middle;float:left;width:145px;margin-left:10px;">' + thisObj.firstname + ' ' + thisObj.lastname + ' in ' + thisObj.homecity + '</div>';  
			   if (curCol==0) {
				   resultsHtml += '</div>';
			   } else {
				   resultsHtml += '</div></div><div class="clear"></div>';
			   }						   
			   curCol++;
			   if (curCol>maxCols) {
				   curCol=0;
			   }
		   }
	   }
	   var paneapi = $('#mayors').data('jsp');
	   paneapi.getContentPane().html(resultsHtml);
	   paneapi.reinitialise();
}

function setState(fourSqState) {
	$(".hereNowState").text(fourSqState);
	Cufon.replace(".hereNowState", {fontWeight: 700});
}

