<?php
  $menuSystem = array(
    'Sort' => array(
       'Recent' => 'Recent', 
       'TopRated' => 'Top Rated'),
    'Season' => array(
       'All' => 'All', 
       '2015' => '2015',
       '2014' => '2014', 
       '2013' => '2013', 
       '2012' => '2012', 
       '2011' => '2011'),
    'Team' => array(
       'All' => 'All', 
       'Eastern' => array(
         'Atlantic' => array(
           'BOS' => 'BAL',
           'BKN' => 'BOS',
           'NYK' => 'NYY',
           'PHI' => 'TB',
           'TOR' => 'TOR'),
         'Central' => array(
           'CHI' => 'CLE',
           'CLE' => 'CIN',
           'DET' => 'CLE',
           'IND' => 'KC',
           'MIL' => 'MIN'),
         'Southeast' => array(
           'ATL' => 'HOU',
           'CHA' => 'LAA',
           'MIA' => 'OAK',
           'ORL' => 'SEA',
           'WAS' => 'TEX')),
       'Western' => array(
         'Northwest' => array(
           'DEN' => 'ATL',
           'MIN' => 'MIA',
           'OKC' => 'NYM',
           'POR' => 'PHI',
           'UTA' => 'WSH'),
         'Pacific' => array(
           'GSW' => 'CHC',
           'LAC' => 'CIN',
           'LAL' => 'MIL',
           'PHX' => 'PIT',
           'SAC' => 'STL'),
         'Southwest' => array(
           'DAL' => 'ARI',
           'HOU' => 'COL',
           'MEM' => 'LAD',
           'NOP' => 'SD',
           'SAS' => 'SF'))),
     'MinRating' => array(
       '00' => '<img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '05' => '<img src="Large50.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '10' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '15' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="Large50.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '20' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '25' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="Large50.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '30' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '35' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="Large50.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '40' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '45' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="Large50.png" style="width: 12px; height: 12px;">',
       '50' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">'),
     'PassFail' => array(
       'Off' => 'Off',
       '10' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '15' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="Large50.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '20' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '25' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="Large50.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '30' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '35' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="Large50.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">',
       '40' => '<img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeFull.png" style="width: 12px; height: 12px;">
                <img src="LargeEmpty.png" style="width: 12px; height: 12px;">')
    );

  function GenerateURL($param, $newvalue)
  {
    $ret = 'basketball.php';
    $sep = '?';
    
    $newGet = $_GET;
    $newGet[$param] = $newvalue;
    
    if($param != 'IDX' && $param != 'PassFail')
      $newGet['IDX'] = '0';

    global $isMobile;
    if($isMobile &&
      ($newGet['Team'] == 'Eastern' ||
       $newGet['Team'] == 'Western' ||
       $newGet['Team'] == 'Atlantic' ||
       $newGet['Team'] == 'Central' ||
       $newGet['Team'] == 'Southeast' ||
       $newGet['Team'] == 'Northwest' ||
       $newGet['Team'] == 'Pacific' ||
       $newGet['Team'] == 'Southwest'))
    {
      return '#';
    }
    
    foreach($newGet as $key => $value)
    {
      $ret = $ret . $sep . $key . '=' . $value;
      $sep = "&";
    }
    
    return $ret;
  }

  function CleanGetVars()
  {
    global $menuSystem;

    if(!array_key_exists('PassFail', $_GET) && array_key_exists('LastBasketballPassFail', $_COOKIE))
      $_GET['PassFail'] = $_COOKIE['LastBasketballPassFail'];

    //Remove any GET keys we don't understand
    foreach($_GET as $key => $value)
    {
      if(!array_key_exists($key, $menuSystem) && $key != 'IDX')
      {
        unset($_GET[$key]);
      }
    }
    
    foreach($menuSystem as $key => $value)
    {
      if(array_key_exists($key, $_GET))
      {
        //We know we have a valid key name, but need to verify that we have a valid value
      }
      else
      {
        list($k, $v) = each($value);
        $_GET[$key] = $k;
      }
    }
      
    if(!array_key_exists('IDX', $_GET))
    {
      $_GET['IDX'] = '0';
    }
  }

  function Printable($name)
  {
    switch($name)
    {
      case 'Sort':
        return 'Sort: ' . Printable($_GET['Sort']);
      case 'Season':
        return 'Season: ' . Printable($_GET['Season']);
      case 'Team':
        return 'Team: ' . AltPrintable($_GET['Team']);
      case 'MinRating':
        return 'Min Rating: ' . Printable($_GET['MinRating']);
      case 'PassFail':
        return 'Pass/Fail: ' . Printable($_GET['PassFail']);
        
      case 'TopRated':
        return 'Top Rated';
        
      case '2015':
        return '2015-16';
      case '2014':
        return '2014-15';
      case '2013':
        return '2013-14';
      case '2012':
        return '2012-13';
      case '2011':
        return '2011-12';
 
      case '00':
         return   '<img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '05':
         return   '<img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '10':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '15':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '20':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '25':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '30':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '35':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '40':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '45':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">';
      case '50':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">';
    }

    return $name;
  }
  
  function AltPrintable($name)
  {
    switch($name)
    {
    }
    return Printable($name);
  }






  CleanGetVars();
  if(!$isMobile)
  {
    print "<div class=submenu>\n";
    print "  <ul>\n";
  
    foreach($menuSystem as $key1 => $value1)
    {
      if($key1 == 'PassFail')
        //print "    <li style=\"margin-left: 130px;\">\n";
        print "    <li style=\"position: absolute; left: 640px; width: 150px;\">\n";
      else
        print "    <li>\n";
      print "      <a href=\"#\">" . Printable($key1) . "</a>\n";
      print "      <ul>\n";
      foreach($value1 as $key2 => $value2)
      {
        print "        <li>\n";
        if( $key2 == '00' ||
            $key2 == '05' ||
            $key2 == '10' ||
            $key2 == '15' ||
            $key2 == '20' ||
            $key2 == '25' ||
            $key2 == '30' ||
            $key2 == '35' ||
            $key2 == '40' ||
            $key2 == '45' ||
            $key2 == '50')
          print "          <a href=\"" . GenerateURL($key1, $key2) . "\" class=\"stars\">" . Printable($key2) . "</a>\n";
        else
          print "          <a href=\"" . GenerateURL($key1, $key2) . "\">" . Printable($key2) . "</a>\n";

        if(is_array($value2))
        {
          print "<ul>\n";
          foreach($value2 as $key3 => $value3)
          {
            print "<li>\n";
            print "<a href=\"" . GenerateURL($key1, $key3) . "\">" . Printable($key3) . "</a>\n";

            if(is_array($value3))
            {
              print "<ul>\n";
              foreach($value3 as $key4 => $value4)
              {
                print "<li>\n";
                print "<a href=\"" . GenerateURL($key1, $key4) . "\">" . Printable($key4) . "</a>\n";
                print "</li>\n";
              }
              print "</ul>\n";
            }

            print "</li>\n";
          }
          print "</ul>\n";
        }
        print "        </li>\n";
      }
      print "      </ul>\n";
      print "    </li>\n";
    }
  
    print "  </ul>\n";
    print "</div>";
  }
?>