var trans = function(n) {
  var vals = ["keine Angabe","ungenügend","mangelhaft","ausreichend","befriedigend","gut","sehr gut"];
  return n < vals.length ? vals[n] : vals[0];
}
$(document).ready(function(){
    $("div.star-rater").each(function (e) {$("input", $(this)).hide()});
    $("div.star-rater").each(function(i) {
        var n=-1; $("input",$(this)).each(function(i) {if($(this).attr("checked")) n=i;});
        $(this).append($('<div class="star-selected" />').css("width", 25*(n+1) + "px")).append('<div class="star-hover" />');
        $("#label-"+$("input:eq(0)", $(this)).attr("name")).text(trans(n+1));
      });
    
    $("div.star-rater").each(function(i) {
        if($("input",$(this)).attr("disabled")) return;
        $(this).click(function (e) {
            var n = Math.round((e.pageX-$(this).offset().left+5)/25);
            $(".star-selected", $(this)).css("width",(n*25)+"px");
            if (n > 0) { $("input:eq(" + (n-1) + ")", $(this)).attr("checked", true);
            } else {     $("input", $(this)).attr("checked", false); }
          })
          .mousemove(function (e) {
              var n = (Math.round((e.pageX-$(this).offset().left+5)/25));
              $(".star-hover", $(this)).css("width", 25*n+"px");
              $("#label-"+$("input:eq(0)", $(this)).attr("name")).text(trans(n));
            })
          .mouseleave(function (e) {
              $(".star-hover", $(this)).css("width", "0px");
              var n=-1; $("input",$(this)).each(function(i) {if($(this).attr("checked")) n=i;});
              $("#label-"+$("input:eq(0)", $(this)).attr("name")).text(trans(n+1));
            })
          });
  });

