$(document).ready(function() { 
    $("#accordion .item h5 a").click(function() {
        
        $(this).toggleClass("a").parent().parent().find('.cont').slideToggle(200);
        if ($(this).is('.a')) $(this).text('Свернуть рубрику');
        else $(this).text('Развернуть рубрику');
        
        return false;
    }); 
    
    $(".l_s button").click(function(){
        var ID_a = $(this).attr('data');
        var b = $(this);
        
        if (ID_a!=0) { 
            b.css('background','url(/images/butg.png) no-repeat');        
            if (!$(this).is('.active')) {
                $(this).addClass('active');
                
                $(".secret-c").remove();
                $(this).parent('div').prepend('<div class=\"secret-c\">Защитный код<img src="/body/no_spam/securimage_show.php?sid=' + Math.random()+'"><input type=\"text\" maxlength=\"4\" id=\"code\" value=\"\"></div>');
                $(".secret-c input#code").focus();
            }
            else {            
                if ($(".secret-c input#code").val().length!=4) $(".secret-c img").attr('src','/body/no_spam/securimage_show.php?sid=' + Math.random()); 
                else {
                    $.get("/body/includes/library/voice.php?people="+ID_a+'&code='+$(".secret-c input#code").val(), function(data){
                        if (data==0) {
                            $(".secret-c").remove();
                            b.removeClass('active').css('background','url(/images/buts.png) no-repeat');
                            b.attr('data',0);
                        }
                        else if (data==2) {
                            $(".secret-c").remove();
                            b.removeClass('active').css('background','url(/images/butno.png) no-repeat');
                            b.attr('data',0);
                        }
                        else {
                            $(".secret-c img").attr('src','/body/no_spam/securimage_show.php?sid=' + Math.random());                         
                            $(".secret-c input#code").val('').focus();
                        }
                    });                
                }
            }
        }                             
    });
    
    if ($(".img_box a").length!=0) $(".img_box a").tooltip({track: true, delay: 0, showURL: false, showBody: "–", fade: 250});                           
    
    $("a.remove_comment").click(function(){
        $.get('/body/includes/library/remove.php?id='+$(this).attr('id').substring(5));
        $(this).parent().parent().remove();
        return false;
    });
});

