$(document).ready(function(){

  $('.popular_quizzes a.more').click(function(){
    return load_more_quizzes($(this), 'popular');
  });
  $('.top_quizzes a.more').click(function(){
    return load_more_quizzes($(this), 'popular_rating');
  });
  $('.new_quizzes a.more').click(function(){
    return load_more_quizzes($(this), 'recent');
  });

});

function load_more_quizzes(link, quiz_group) {
  var take_href = link.attr('href');

  var type_match = take_href.match('/take/([a-z]+)');
  var take_type;
  if (type_match) {
    take_type = type_match[1];
  } else {
    take_type = 'all';
  }
  var page_match = take_href.match('page=([0-9]+)');
  var page = page_match[1];

  var new_take_href = take_href.replace(/page=[0-9]+/, 'page=' + (parseInt(page) + 1));

  link.parents('div.body').find('ul').load(
    $('base').attr('href') + 'take/load_quizzes/' +
      take_type + '/' + quiz_group + '/' + page,
    '',
    function(){
      link.attr('href', new_take_href);
    }
  );
  return false;
}