$(function(){$('.corner').corner();});
/*********** Star Avaliations Plus Version 2.3.8.74.9.6.4.12*******************/
$(document).ready(function(){
	$('.star').mouseover(function(){
		var id = ".star[id=" + $(this).attr('id') + ']';
		var pos = $(this).attr('star');
		if( pos != 0 ){
			$(id).each(function (i) {
				$(this).removeClass("off");
		        $(this).removeClass("half");
		        $(this).removeClass("full");
		        if ( $(this).attr("star") <= pos ) {
	        	  $(this).addClass("full");
		        }else{
					$(this).addClass("off");
				}
		    })
	    }
    })
    .mouseout(function() {
		var id = ".star[id=" + $(this).attr('id') + ']';
		var pos = $(this).attr('star');
		if( pos != 0 ){
			var full = true;
			$(id).each(function (i) {
				$(this).removeClass("off");
			    $(this).removeClass("half");
			    $(this).removeClass("full");
			    if ( full ) {
			    	if( $(this).attr("vote") == "half" || $(this).attr("vote") == "full"  ){
						full = false;
						$(this).addClass( $(this).attr("vote") );
					}else
		    			$(this).addClass( "full" );
			    }else{
					$(this).addClass("off");
				}
			})
		}
    });

	$('.star').click(function() {
		var pos = $(this).attr('star');
		if( pos != 0 ){
			var id_prod = $(this).attr('id');
			var id = ".star[id=" + id_prod + ']';
			$.post("/voto.php", { voto: pos, id_produto: id_prod  }, function(data){
				if( data == "true" ){
					$(id).each(function (i) {
						$(this).attr("star", 0 );
					})
					$('[prod=' + id_prod + ']').fadeTo('slow', 0.55);
				}else{
					alert( 'Erro: Tente novamente' );
				}
			} );
	    }
	});
});
/************* Comments Alpha Plus Code Version 24,69,12,74,2,11 **************/
function showComment(){
	$(".commentBox").slideToggle("slow");
}
function comenta(){
	$.post("/comenta.php", { nome: $("#nome").val(), email: $("#email").val(), comentario: $("#comentario").val(), id_produto: $("#id_produto").val() }, function(data){
		if( data != 'false' ){
			$(".commentBox").animate( { opacity: 0 }, "slow", function(){
				$(".commentBox").html("<h3>Comentário realizado com sucesso!</h3>");
				$("#click_comment").fadeTo( "slow", 0);
				$( '.tableComments' ).prepend(data);
				$(".commentBox").animate( { opacity: 1 }, "slow" ).animate( { opacity: 0 }, 7000, function(){
					$(this).remove();
					$("#click_comment").remove();
				} );	
			} );
			
			
		}
	});
}
function excluirComentario( id ){
	if( confirm( 'Deseja realmente remover o comentário?') ){
		$.post( '/comenta.php', { cmt: id }, function(data){
			if( data == 'true' ){
				$("#comment-" + id ).addClass( 'red' );
			}else{
				alert( 'Não foi possível remover o comentario!\nTente se logar novamente!');
			}
		} );
		
	}
}
