//
var socialINT = null;
$(function () {
	getSocialPosts();
	socialINT = setInterval('getSocialPosts();', 20000);
});

function getSocialPosts() {
	$.getJSON('/index.php/frontend/stream_ajax/live', function(data) {
		clearInterval(socialINT);
		if(!$("#social-posts ul").length) {
			$("#social-posts").html("<ul></ul>");
			/*jQuery("#social-posts ul").jcarousel({
				wrap: 'circular',
				auto: 5,
				scroll: 1,
				initCallback: mycarousel_initCallback,
				vertical: true,
				animation: 'slow'
			});*/
		}
		
		for(var id in data) {
			var d = data[id];
			if(!$("#social-posts ul #" + id).length) {
				$("#social-posts ul").prepend('<li><div id="' + id + '"><div class="date"><img src="' + d['icon'] + '" alt="" />' + d['date'] + '</div>' + d['message'] + ' <a href="' + d['url'] + '" target="_blank">@' + d['name'] + '</a></div></li>');
			}
		}
		
		socialINT = setInterval('getSocialPosts();', 20000);
	});
}

function mycarousel_initCallback(carousel) {	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};
