<?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(gfr.rating_ip)) AS respondents, ROUND(AVG(gfr.rating_vote), 2) AS score, COUNT(gfr.rating_vote) AS votes, gf.fitter_id, gf.fitter_name, gf.fitter_address, gf.fitter_address_two, gf.fitter_city, gf.fitter_state, gf.fitter_zip, gf.fitter_phone, gf.fitter_fax, gf.fitter_email, gf.fitter_website, gf.fitter_certifications, gf.fitter_fitbikes FROM ".$prefix."FittersRating AS gfr RIGHT JOIN ".$prefix."Fitters AS gf ON gf.fitter_id = gfr.fitter_id_fk GROUP BY gfr.fitter_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 Bike Fitters";

// set meta tags
$meta_keywords = "top ranked bike fitters";
$meta_description = "Top ranked bike fitters 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 Bike Fitters</h1>
                <hr class="line" />
                <? include("../runshops/include_region_list.php"); ?>

                <?
                if($none == TRUE){
                    echo "No bike fitters 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>