var currentComment=0;

function answerComment(cid, t){
    
    var commentId=cid;
    $('#answer_'+currentComment).slideUp(500,function(){
        forceOperaRepaintComments();
        $('#answer_'+currentComment).children().appendTo($('#answer_'+commentId));
        $('.comment_id').val(commentId);
        currentComment=commentId;
        $('#answer_'+commentId).slideDown(500);
        forceOperaRepaintComments();
    });
    if (t != null) return true;
    return false;
}
function doLogout($cb){
    $.ajax({
        url: '?xaction=ajaxLogout',
        dataType: 'html',
        type: 'GET',
        success: function(data){
            if ($cb!=null) eval($cb);
        }
    });
}
function removeComment(cid){
    var commentId=cid;
    $('.removeComment').css('display','none');
    $('#remove_'+commentId).slideDown(500);
    return false;
}
$(function(){
    $(".captcha-reload").click(function(){
        var hash = new Date().getTime();
        $(".captcha").attr("src","/file/img.php?"+hash);
        return false;
    });
    $(":radio[name=auth]").change(function(){
        var authType=$(":radio[name=auth]").filter(":checked").val();
        if (currentAuth==''){
            currentAuth=authType;
            $('#answer_auth_'+authType).slideDown(500);
            forceOperaRepaintComments();
        } else {
            $('#answer_auth_'+currentAuth).slideUp(500,function(){
                currentAuth=authType;
                $('#answer_auth_'+authType).slideDown(500);
                forceOperaRepaintComments();forceOperaRepaintComments();
            });
        }
    });
    openid.init('openid_identifier');
    $.metadata.setType("attr", "validate");
    $("#form_auth_fxclub").validate();
    $("#form_auth_none").validate();
    $("#form_auth_vkontakte").validate();
    $("#form_auth_facebook").validate();
    $("#form_auth_openid").validate();
    $("a[rel^=comment_attaches_]").each(function(){
        $(this).fancybox({
            'transitionIn'		: 'elastic',
            'transitionOut'		: 'elastic',
            'titleShow'		: false
        });
    });
});

function forceOperaRepaintComments() {
   if (window.opera) {
        var bs = document.body.style;
        bs.position = 'relative';
        setTimeout(function() {
            bs.position = 'static';
        }, 1);
    }
}
