/**
 * Script care ia locatia, apeleaza api-ul ubervu si scoate toate reactiile
 * pentru url-ul curent.
 * Poate fi embedded in post
 * (c) Alex Eftimie 2008-10-31
 */

$(document).ready( function () {
	var location = window.location;

	var api_url = 'http://api.ubervu.com/services/rest/';
	api_url += '?format=json&method=ubervu.conversations.getReactions&api_key=75lipcae6usvurv9yi1rj4stat66q5dn&url='; 
	api_url += location;

	$.get('/pdz/test/get.php?url=' + escape(api_url),
		function (text) {
		  text = text.substring(text.indexOf('{'));
		  json = eval('('+text+')');
		  $('#reactions').html(format_output(json.conversation.reaction));
		  }
		 );
	});

function format_output(data)
{
	var itemList = '';
	for (i = 0; i < data.length; i ++) {
		if (data[i].platform != 'wordpress')
		itemList += '<h4 id="heading-' + i + '">' +
				  '<a href="' + data[i].url + '">' + 
				  data[i].authorname + '</a> on '+ data[i].platform +'</h4>' +
				  '<p>' + data[i]._content + '</p>';
	}
	if (itemList != '')
		itemList = '<h3>Reactions</h3>' + itemList + '<small style="float:right">powered by <a href="http://www.ubervu.com/">uberVU</a></small>';
	
	return itemList; 
}
