$(document).ready(function() {
	$('#feedback_vote img').click(function (){
		var arrDesc=["Non votato","Pessimo","Discreto","Medio","Buono","Ottimo!"];
		$(this).nextAll('img').attr('src','images/star_empty.jpg');
		$(this).prevAll('img').attr('src','images/star_full.jpg');
		$(this).attr('src','images/star_full.jpg');
		var val=$(this).prevAll('img').length+1;
		$(this).parent('li').find('input[type=hidden]').val(val);
		$(this).parent('li').find('span.desc').html(arrDesc[val]);
		var count=0;
		$('#feedback_vote li input[type=hidden]').each(function(i,item){
			if($(item).val()>0) count++;
		});
		if(count >= $('#feedback_vote li input[type=hidden]').length){
			$('#feedback_vote_send a').removeClass('disabled');
		}else $('#feedback_vote_send a').addClass('disabled');
	});
	$('#feedback_vote_req a').click(function (){
		$('#feedback_vote').show();
		$('#feedback_container, #feedback_vote_req').hide();
		return false;
	});
	$('#comments_vote_req a').click(function (){
		$('#comments_vote').show();
		$('#comments_container, #comments_vote_req').hide();
		return false;
	});
	$('#comments_vote textarea').keyup(function (){
		$('#comment_label').removeClass('red').html("Hai ancora "+(200-$(this).val().length)+" caratteri per il tuo commento");
		if($(this).val().length>0){
			$('#comments_vote_send a').removeClass('disabled');
			if($(this).val().length>=200){
				$('#comment_label').addClass('red').html("Hai esaurito i caratteri disponibili per questo commento");
				$(this).val($(this).val().substr(0,200));
			}
		}else $('#comments_vote_send a').addClass('disabled');
	});
	$('#feedback_vote_send a').click(function (){
		if(!$(this).hasClass('disabled')){
			var form=$('#feedback_vote_send').parent('form');
			$('#feedback_section').load(form.attr('action'),form.serialize());
		}
		return false;
	});
	$('#comments_vote_send a').click(function (){
		if(!$(this).hasClass('disabled')){
			var form=$('#comments_vote_send').parent('form');
			$('#comments_section').load(form.attr('action'),form.serialize());
		}
		return false;
	});
	$('#comments_section a.remCom').livequery("click",function (){
		$.getJSON($(this).attr("href"), {aj :1}, function(data){});
		$(this).parent().remove();
		return false;
	});

});
