	var addVoteLink = "http://www.youcabaret.it/videoShare/voteManagement/addVoteAX.action";

	function addVote (videoId, votazione, vote)
	{
	  $.get(addVoteLink+"?date="+(new Date()).getMilliseconds()+"&videoId="+videoId+"&votazioneId="+votazione+"&voto="+vote, function (data)
	  {
	      $('#votes').find('div').remove ();
	      $(data).find ('vote').each (function (i)
	      {
	    	var id = $(this).find ('id').text();
	    	var name = $(this).find ('name').text();
	    	var avgVote = $(this).find ('avgVote').text();
	    	var voters = $(this).find ('voters').text();
	        var location = $("#voteTemplate").clone();
	        if (voters != "")
	        {
		        $('#stars_'+id).remove ();
		    	
		        location.find("span").eq("0").text(name);
		        location.find("strong").eq("0").text(avgVote);
		        location.find("strong").eq("1").text(voters);
		        // Conversione in creazione oggetto img e inserimento
		        location.appendTo("#votes");
	        }
	      });
	  });
	  return false;
   }
	
	$(document).ready (function ()
	{
		var images = $(".star");
		images.each(function ()
		{
			$(this).click(function ()
			{
				var parent = $(this).parent();
				var children = parent.find(".star");
				var position = children.index(this);
				for (i = 0 ; i <= position; i++)
				{
					children.eq(i).attr("src","<s:url value="%{getText('imagesBase')}/action/red_star.png"  includeParams="none"/>");
				}
				for (i = position+1 ; i <= children.size(); i++)
				{
					children.eq(i).attr("src","<s:url value="%{getText('imagesBase')}/action/gold_star.png"  includeParams="none"/>");
				}
			});
		});
	})

