function fetchPollData(contentObjectID, contentObjectAttributeID)
{
	jQuery.ajax(
		{
			type: 'GET',
			url: interfaceBaseURI + '/content/collected_info_collection',
			data:
				{
					contentobject_id: contentObjectID
				},
			success: function(jsonString)
				{
					try
					{
						response = eval('(' + jsonString + ')');

						if(response)
							buildPollGraph(contentObjectID, contentObjectAttributeID);
						else
							$('#poll-question').css('display', 'block');
					}
					catch(e)
					{
					}
				}
		}
		);
}

function buildPollGraph(contentObjectID, contentObjectAttributeID)
{
	jQuery.ajax(
		{
			type: 'GET',
			url: interfaceBaseURI + '/content/collected_info_count_list',
			data:
				{
					contentobject_id: contentObjectID,
					contentobjectattribute_id: contentObjectAttributeID
				},
			success: function(jsonString)
				{
					try
					{
						response = eval('(' + jsonString + ')');

						if(response.total_count > 0)
						{
							var resultsHTML = '';

							for(var i = 0; i < response.item_counts.length; i ++)
							{
							    percent = Math.round((parseInt(response.item_counts[i].total) / parseInt(response.total_count)) * 100);

								resultsHTML += '<div class="poll-result-item">';
								resultsHTML += '<div class="poll-result-item-text">' + response.item_counts[i].text + '</div>';
								resultsHTML += '<div class="poll-result-item-bar-container">';

								if(percent > 0)
									resultsHTML += '<div class="poll-result-item-bar" style="width: 1px"><strong>' + percent + '%</strong></div>';
								else
									resultsHTML += '<div class="poll-result-item-bar-empty"></div>';

								resultsHTML += '</div>';
								resultsHTML += '<div class="break"></div></div>';
							}

							$('#poll-results-total').append(response.total_count);
							$('#poll-results-total').css('display', 'block');

							$('#poll-results').html(resultsHTML).fadeIn('fast', function() { animateResults(); });
						}
					}
					catch(e)
					{
					}
				}
		}
		);

}

function animateResults()
{
  $(".poll-result-item-bar").each( function() {

		var percentage = $(this).text();
		$(this).css( { width: "0%" } ).animate( { width: percentage }, 'slow');

	});
}