function EP2_Starbox()
{
  var divs = $$('div.starbox').select(function(e){ return e.id.charAt(0) != 'I' });
	if (divs.length == 0) { return; }
	var make_rate_cb = function(rid) {
    return function(element, memo) {
			var info_id = 'I' + memo.identity;
			if ($(info_id)) {
        new Starbox(info_id, memo.average, {color: '#434D9C', total: memo.total, locked: true});
      }
      new Ajax.Request('/rating.php', {parameters: {rating: memo.rated, id: rid}});
		}
  }
	var cb_init_boxes = function(response) {
	  var boxes = response.responseText.evalJSON();
		boxes.each(function(b) {
		var info_id = 'I' + b.id;
		if ($(info_id)) {
			new Starbox(info_id, b.avg, {color: '#434D9C', total: b.total, locked: true});
		}
    var cb_rate = make_rate_cb(b.id);
		new Starbox(b.id, b.avg, {color: '#434D9C', total: b.total, onRate: cb_rate, indicator: '#{total} Bewertungen'});
		});
	}
	var ids = divs.collect(function(e){return e.id}).join(',');
	new Ajax.Request('/rating.php', {parameters: {id: ids}, onSuccess: cb_init_boxes});
}

Event.observe(window, 'load', EP2_Starbox); 

