function csstatsshow(num) {
  $$('div#csstatwrapper .statitem').each(function(el, ix) {
    ix < num ? el.show() : el.hide();
  });
}

Event.observe(window, 'load', function() {
  $$('img.csstatsnext').each(function(el, ix) {
    el.observe('click', function(ev) {
      var firstel = $$('div#csstatwrapper .statitem').first();
      var lastel = $$('div#csstatwrapper .statitem').last();
      lastel.insert({after: firstel});
      csstatsshow(1);
    });
  });
  $$('img.csstatsprev').each(function(el, ix) {
    el.observe('click', function(ev) {
      var firstel = $$('div#csstatwrapper .statitem').first();
      var lastel = $$('div#csstatwrapper .statitem').last();
      firstel.insert({before: lastel});
      csstatsshow(1);
    });
  });
  csstatsshow(1);
});