$(function(){
    $(".post a.toggler").unbind();    
    $(".post a.toggler").click(function(){
        $('#'+$(this).attr('rel')).toggle(500);
        return false;
    });
    
    $(".track .toggler").unbind();
    $(".track .toggler").click(function(){
        $(this).parents(".track").find(".toggle").slideToggle(500);
        return false;
    });
    
    /*********
     *          Ratings
     *********/
    /*$(".rate .arate").each(function(){
        $(this).after("<a class=\"no_vote\" style=\"display: none;\">"+$(this).text()+"</a>");
    });*/
    
    $(document).ajaxError(function(event, request, settings){
        alert("Ошибка при запросе '" + settings.url +"'");
    });
    
    $("a.arate").unbind();
    $("a.arate").click(function(){
        var h = $(this).attr("href");
        var p = $(this).parents(".rate");
        p.ajaxComplete(function(request, settings){
            switch (gm.code){
                case "OK":
                    //$(this).find("div:first").removeClass('minus');
                    //$(this).find("div:first").removeClass('plus');
                    rate = gm.plus-gm.minus;
                    plus = (rate>=0?((rate==0)?'0':'+'+rate):rate);  
                    $(this).find("div.rating").text(plus);
                    //if (rate > 0) $(this).find("div:first").addClass('plus');
                    //if (rate < 0) $(this).find("div:first").addClass('minus');
		    
		    $(this).find("a.arate").each(function(){
			$(this).hide();
		    });
		    $(this).find("div.rating").addClass("large-rating");
		    $(this).find("div.rating").show();
		    
                    break;
                case "ERR":
                    /*$(this).find("a.arate").each(function(){
                        $(this).next("a.no_vote:first").hide();
                        $(this).show();
                    });*/
                    break;
                case "AVO":
                    break;
            }
            $(this).unbind();
        });
        
        $.getJSON(h+"?ajax", function(msg){
            gm = msg;
        });
        return false;
    });
    
    //makeTabs(".form-tabs",".form-tab-content");
});

captcha = '';

function image_reload(id) {
    if ( captcha=='' ) captcha = $("#"+id).attr('src');
    $("#"+id).attr('src',captcha+'&rnd='+Math.round(Math.random(0)*1000));
}
