var anim_content = ["&#9658;","&#9660;","&#9668;","&#9650;"];
var anim_control = 0;

function startAnim(anim){
	if (anim_control > 3){anim_control = 0;}
	anim.html(anim_content[anim_control]);
	anim_control++;
}

function viewComment(id,fokey,skin) {
  var link = $("#comment"+id+"link");
  var open = $("#comment"+id+"open");
  var anim = $("#anim"+id);

  if (open.html() == "") {
		var animId = 0;
		animId = setInterval (function(){startAnim(anim)}, 250);
		var url='/gen.pl?p=comments:view&fokey='+fokey;
		if(skin)url='/gen.pl?p=comments:view&fokey='+fokey+'&skin='+skin;
		$.ajax({
			type:'GET',
			url:url,
			success:function(data){
				open.html(data);
				link.hide();
				open.show();
				
				clearInterval (animId);
				anim_control = 0;
				anim.html("&#9658;");
			}
		});

  }else{
		link.hide();
		open.show();
  }
}

function closeComment(id) {
	$("#comment"+id+"open").hide();
	$("#comment"+id+"link").show();
}

function moderateComment(fokey){
	var TimeStamp = new Date().getTime();
	jConfirm('Aguarde, por favor...', 'pontuar comentário');
	$('#popup_cancel').hide();
	$('#popup_ok').hide();
	$('#popup_cancel').val('   Fechar   ');
	$('#popup_ok').val('   OK   ');
	
	$.ajax({
		type:'GET',
		url:'/gen.pl?p=moderate&fokey='+fokey+'&ts='+TimeStamp,
   	success:function(data){
   		$('#popup_message').html(data);
   		$('#popup_cancel').show();
		}
	});
}

function voteComment(fokey,reason){
	var TimeStamp = new Date().getTime();
	$("#popup_cancel").trigger('click');
	jAlert('A enviar...', 'pontuar comentário');
	$('#popup_ok').hide();
	$.ajax({
		type:'GET',
		url:'/gen.pl?p=moderate&fokey='+fokey+'&op=moderate&reason='+reason+'&ts='+TimeStamp,
   	success:function(data){
   		$('#popup_message').html(data);
   		$('#popup_ok').show();
		}
	});
}

function markAbuse(fokey){
	var TimeStamp = new Date().getTime();
	jConfirm('Aguarde, por favor...', 'reportar abusivo',function(clickedok) { clickedok?voteCommentAbuse(fokey,'suspect'):null;  } );
	$('#popup_cancel').hide();
	$.ajax({
		type:'GET',
		url:'/gen.pl?p=abuse&fokey='+fokey+'&ts='+TimeStamp,
   	success:function(data){
			$('#popup_message').html(data);
			$('#popup_cancel').show();
		}
	});
}

function voteCommentAbuse(fokey,reason){
	var TimeStamp = new Date().getTime();
	$("#popup_cancel").trigger('click');
	jAlert('A enviar...', 'reportar abusivo');
	$('#popup_ok').hide();
	$.ajax({
		type:'GET',
		url:'/gen.pl?p=abuse&fokey='+fokey+'&op=mark&abusive='+reason+'&ts='+TimeStamp,
   	success:function(data){
   		$('#popup_message').html(data);
   		$('#popup_ok').show();
		}
	});
}
