
$(document).ready(function(){
	
	$(".email_c").click(function(){ 
		$(".draggable").remove();
		
		//------------------------------------------------------------------------------------------------------------------
		add = '<div class="enviar-msg draggable">';
		add += '<span class="enviar-email-chapeu" id="titulo">ENVIAR POR EMAIL</span><a title="Fechar" href="javascript: void(0)" onclick="$(\'.draggable\').remove();" class="fechar1">X</a>';
		add += '<form method="post" action="">';
		add += '<label>Seu nome</label>';
		if ($("input[name=nome]").val()){
			add += '<input class="forma" maxlength="300" name="nome_e" value="'+($("input[name=nome]").val())+'" id="nome_ef" ype="text"><br />';
		}else{
			add += '<input class="forma" maxlength="300" name="nome_e" id="nome_ef" value="" type="text"><br />';
		}
		add += '<label>Nome do destinatário</label>';
		add += '<input class="forma" maxlength="300" name="nome_d" id="nome_df" value="" type="text"><br />';
		add += '<label>Email do destinatário</label>';
		add += '<input class="forma" maxlength="300" name="email_d" id="email_df" value="" type="text"><br />';
		add += '<label>Comentário</label>';
		add += '<textarea rows="6" name="mensagem" id="mensagem_f"></textarea><br /><br />';
		add += '<center><input type="button" class="botao-submit1 enviar-email-ajax" value="Enviar" name="dados" /></center></form></div>';
		
		$("body").append(add);
		
		$(".draggable").Draggable({
			handle: '#titulo',
			opacity: 0.3,
			snapDistance: 10
		});
				
		position = $(this).position();
		tamanho = $(".draggable").width();
		tamanho -= $(this).width()-237;
			
		$(".draggable").css("left",position.left-tamanho);
		$(".draggable").css("top",position.top+35);
		$(".draggable").css("z-index",5);
		$(".draggable").css("position","absolute");
		
		$(".enviar-email-ajax").click(function(){
			
			var host = $("#host").attr("href");
			var nome_ee = $("#nome_ef").val();
			var nome_dd = $("#nome_df").val();
			var email_dd = $("#email_df").val();
			var mensagem_f = $("#mensagem_f").val();
			var link = document.location+" ";
	
			$.get(host+"enviar_email.php", {nome_e: nome_ee, nome_d: nome_dd, email_d: email_dd, mensagem: mensagem_f, url: link},
				function (data){
			
					$(".draggable").remove();
					$("body").append(data);
				
					$(".draggable").css("top",position.top+50);
					$(".draggable").css("left",position.left-400);
				
					$(".draggable").Draggable({
						handle: '#titulo',
						opacity: 0.3,
						snapDistance: 10
					});
				}		
			);
			
			return;
			
		});
			
	});
	
	$(".favoritoclick").click(function(){ 
		
		var host = $("#host").attr("href");
		var id_arquivo = $(this).attr("xid");
		
		$.get(host+"add_favorito.php", {id_arquivo: id_arquivo},
			function (data){
				$(".favoritoclick").html("<span>"+data+"</span>");
			}		
		);
	});
	
	
	$(".recomendeclick").click(function(){ 
		
		var host = $("#host").attr("href");
		var id_arquivo = $(this).attr("xid");
		
		$.get(host+"add_recomendacao.php", {id_arquivo: id_arquivo},
			function (data){
				$(".recomendeclick").html("<span>"+data+"</span>");
			}		
		);
	});
	
	
	$(".votarclick").rating({
		
		half: true,
		
 		callback: function(value, link){
 			
 			$("#nota strong").html(value);
    		$(".votarclick").rating("disable");
    		$(".votarclick").rating.desabilitado = true;
 			
    		var host = $("#host").attr("href");
    		var id_arquivo = $(".recomendeclick").attr("xid");
    		
 			$.get(host+"add_nota.php", {id_arquivo: id_arquivo, nota: value},
				function (data){
					var objeto = $("#nota span").get(0);
					$(objeto).html("<span class=\"red\">"+data+"</span>");
				}		
			);
 			
  		},
  		
  		focus: function(value, link){
     		if( !$(".votarclick").rating.desabilitado ){
     			$("#nota strong").html(value);
     			mostrar_nota(value);
     		}
     		
	 	}

	});
	
	var aNota = $("#nota strong").html();
	$('.votarclick').rating('selectOnly',aNota-1);

	if(aNota=='n\\a'){
		mostrar_nota(0);
	}
	
});


function mostrar_nota(value){
	
	if(value==1 || value == 2){
		$("#nota span.tipo").html("Fraco");
	}else if(value==3 || value == 4){
		$("#nota span.tipo").html("Regular");
	}else if(value==5 || value == 6){
		$("#nota span.tipo").html("Bom");
	}else if(value==7 || value == 8){
		$("#nota span.tipo").html("Muito Bom");
	}else if(value==9 || value == 10){
		$("#nota span.tipo").html("Excelente");
	}else{
		$("#nota span.tipo").html("Não avaliado");
	}
	
}
