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

$results = mysql_query("SELECT COUNT(DISTINCT(gfr.rating_ip)) AS respondents, ROUND(AVG(gfr.rating_vote), 2) AS score, COUNT(gfr.rating_vote) AS votes, gf.coach_id, gf.coach_name, gf.coach_address, gf.coach_address_two, gf.coach_city, gf.coach_state, gf.coach_zip, gf.coach_phone, gf.coach_fax, gf.coach_email, gf.coach_website FROM ".$prefix."CoachesRating AS gfr RIGHT JOIN ".$prefix."Coaches AS gf ON gf.coach_id = gfr.coach_id_fk GROUP BY gfr.coach_id_fk HAVING COUNT(gfr.rating_vote) > 10 ORDER BY score DESC, votes DESC LIMIT 10") OR die(mysql_error());

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

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

// set meta tags
$meta_keywords = "top ranked triathlon coaches";
$meta_description = "Top ranked triathlon coaches 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 Coaches</h1>
                <hr class="line" />
                <? include("../runshops/include_region_list.php"); ?>
                <?
                if($none == TRUE){
                    echo "No triathlon coaches have enough votes yet.";
                }
                ?>
                <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>


