<?PHP include("config.php");
require_once("rating/classes/include.all.php");
include("rating/int.to.words.php");

$results = mysql_query("SELECT COUNT(DISTINCT(gtr.rating_ip)) AS respondents, ROUND(AVG(gtr.rating_vote), 2) AS score, COUNT(gtr.rating_vote) AS votes, gt.onetype, gt.twotype, gt.threetype, gt.oneunit, gt.twounit, gt.threeunit, gt.name, gt.nametag, gt.statetag, gt.swim, gt.bike, gt.run, gt.city, gt.state, gt.uid, UNIX_TIMESTAMP(gt.date) as foo FROM gforum_TriathlonsRating AS gtr INNER JOIN gforum_Triathlons AS gt ON gt.date > '".$min_date."' AND gt.valid = 1 AND gtr.rating_triathlon_id = gt.uid GROUP BY gtr.rating_triathlon_id HAVING COUNT(gtr.rating_vote) > 50 ORDER BY score DESC, respondents DESC LIMIT 10");

// set the page title
$pagetitle = "Top Races";

// set meta tags
$meta_keywords = "top ranked triathlons";
$meta_description = "Top ranked triathlons and duathlons based on rankings submitted by the user.";
?>

<? include("include_common_head.php"); ?>

<body class="listings">
  <? include($common_path . "/ads/ad_wallpaper.html"); ?>

  <div class="container">
    <? include($common_path . "/templates/include_header.php"); ?>
    <div class="main">
      <div class="contentwrapper clearfix">
        <? include("include_breadcrumb.php"); ?>

        <section class="section listings section-has-widgets section-static remove-sidebar">
          <div class="sidebar-b">
            <?  $selected_item = 'top'; ?>
            <? include("include_sidebar.php"); ?>
          </div>

          <div class="content content-has-widgets">
            <div class="grid">

              <div class="clearfix">
                <h1>Top Ranked Triathlons</h1>
                <hr class="line" />
                <? include("../runshops/include_region_list.php"); ?>
                <?
                if($none == TRUE){
                  echo "<p>No triathlons have been entered yet.</p>";
                }
                ?>
                <p />

                <?
                $rating_text = 1;
                while ($row = mysql_fetch_array($results)) {
                  include("include_race.php");
                } ?>

              </div><!-- end col-2/3 -->

            </div><!-- end grid -->
          </div><!-- end content -->
        </section>

      </div><!-- end contentwrapper -->
    </div> <!-- end main -->

  <? include($common_path . "/templates/include_footer.php") ?>
  </div> <!-- container  -->
</body>
<? include($common_path . "/templates/include_global_js.php") ?>
</html>
