rules_rating = {

    init: function() {

        $(".xvotaciones .votos_txt_vota .votos_estrella a.voto1").live("click", function() { return rules_rating.do_vote($(this), 1); });
        $(".xvotaciones .votos_txt_vota .votos_estrella a.voto2").live("click", function() { return rules_rating.do_vote($(this), 2); });
        $(".xvotaciones .votos_txt_vota .votos_estrella a.voto3").live("click", function() { return rules_rating.do_vote($(this), 3); });
        $(".xvotaciones .votos_txt_vota .votos_estrella a.voto4").live("click", function() { return rules_rating.do_vote($(this), 4); });
        $(".xvotaciones .votos_txt_vota .votos_estrella a.voto5").live("click", function() { return rules_rating.do_vote($(this), 5); });
    },

    do_vote: function(what, vot) {
        var hr = what.attr("href");
        $.get("/ratingvote.ashx", { id: hr, voto: vot }, rules_rating.callback);
        return false;
    },
    callback: function(data, text) {
        var t = data.split("|");

        if (t[0] == '0') {
            var idnota = t[1];
            var votos = t[2];

            $(".bt" + idnota + "n .votos_estrella").hide();
            $(".bt" + idnota + "n .ImgInactivo").each(function() { $(this).attr("src", "/im/" + votos + ".0v" + $(this).attr("prmColor") + ".gif"); });
            $(".bt" + idnota + "n .PanInactivo").show();
            $(".bt" + idnota + "n .PanActivo").hide();
            $(".bt" + idnota + "n .ImgActivo").hide();

        }
        else if (t[0] == '1') {
            var idnota = t[1];
            var votos = t[2];
            var ttotal = t[3];
            var tvotos = t[4];


            $(".bt" + idnota + "n .votos_estrella").hide();
            $(".bt" + idnota + "n .ImgInactivo").each(function() { $(this).attr("src", "/im/" + votos + ".0v" + $(this).attr("prmColor") + ".gif"); });
            $(".bt" + idnota + "n .PanInactivo").show();
            $(".bt" + idnota + "n .PanActivo").hide();
            $(".bt" + idnota + "n .ImgActivo").hide();

            $(".bt" + idnota + "n .votos_resultados img").each(function() { if (!$(this).hasClass("nocambiar")) { $(this).attr("src", "/im/" + ttotal + $(this).attr("prmColor") + ".gif"); } });

            $(".bt" + idnota + "n .votos_resultados span").each(function() { $(this).html("<span class='tvot'>" + tvotos + "</span> votos"); });

        }
        else
        { }
    }
}

$(document).ready(rules_rating.init);

