<?PHP include("config.php");
require_once("class/rating/classes/include.all.php");
include("class/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.triclub_id, gt.triclub_name, gt.triclub_address, gt.triclub_address_two, gt.triclub_city, gt.triclub_state, gt.triclub_zip, gt.triclub_email, gt.triclub_website FROM ".$prefix."TriclubsRating AS gtr RIGHT JOIN ".$prefix."Triclubs AS gt ON gt.triclub_id = gtr.triclub_id_fk GROUP BY gtr.triclub_id_fk HAVING COUNT(gtr.rating_vote) > 10 ORDER BY score DESC, votes DESC LIMIT 10");

$none = FALSE;
if (mysql_num_rows($results) == 0) {
  $none = TRUE;
}

// set the page title
$pagetitle = "Top Triathlon Clubs";

// set meta tags
$meta_keywords = "top ranked triclubs";
$meta_description = "Top ranked triathlon clubs 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 Triathlon Clubs</h1>
                <hr class="line" />
                <? include("../runshops/include_region_list.php"); ?>

                <?
                if($none == TRUE){
                  echo "<p>No running stores have been entered yet for $regionname.</p>";
                }
                ?>
                <p />

                <?
                $rating_text = 1;
                while ($row = mysql_fetch_array($results)) {
                  include("include_store.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>
