function showStats(file) {
  jQuery('#' + file).show();
  jQuery('#msgs').hide();
  jQuery.ajax({
	 url: 'http://www.mlbtw.net/stats/' + file + '_s.php',
  	 type: 'GET',
	 error: function(xhr) {
	    alert('Ajax Error!');
	 },
         success: function(response) {
	    jQuery('#' + file).html(response);

	    if(file != 'time' && jQuery('#' + file + ' tbody tr').size() == 0) {
	       jQuery('#' + file).hide();
	    }

	    if(file == 'batters') {
	      if(jQuery('#pitchers tbody tr').size() == 0 && jQuery('#batters tbody tr').size() == 0) {
                jQuery('#msgs').html('<h3>今日目前無人出賽<h3>');
                jQuery('#msgs').show();
              }
            }
	 }
	 });
}

function showAll() {
  showStats('time');
  showStats('pitchers');
  showStats('batters');
}

jQuery(document).ready(function(e){
  showAll();

  setInterval(function() {
    showAll();
  }, 1000*60*5);
});
