var meetObj = {
   '2010' : {
      fw_b : 'MSC/B vs. Fairwood/B, Tuesday, June 15th, at FW'
     ,fw_a : 'MSC/A vs. Fairwood/A, Thursday, June 17th, at MSC'
     ,mibc_b : 'MSC/B vs. MI Beach Club/B, Tuesday, June 22th, at MSC'
     ,mibc_a : 'MSC/A vs. MI Beach Club/A, Thursday, June 25th, at MIBC'
     ,eb_b : 'MSC/B vs. Edgebrook/B, Tuesday, June 29, at EB'
     ,eb_a : 'MSC/A vs. Edgebrook/A, Thursday, July 1, at MSC'
     ,rh_b : 'MSC/B vs. Rolling Hills/B, Tuesday, July 6, at RH'
     ,rh_a : 'MSC/A vs. Rolling Hills/A, Thursday, July 8, at MSC'
     ,nh_a : 'MSC/A vs. Newport Hills/A, Tuesday, July 13, at MSC'
     ,nh_b : 'MSC/B vs. Newport Hills/B, Thursday, July 15, at NH'
     ,b_champs: 'B-Division Championships, Saturday, July 17th, at NH'
     ,'sr_prelims.pdf': 'Senior Prelims, Monday July 19th, at MIBC'
     ,'jr_girls.pdf': 'Junior Girls Prelims, Tuesday July 20th, at NH'
     ,jr_boys:  'Junior Boys Prelims, Wednesday July 21st, at Samena'
     ,a_champs: "League Championships, Saturday, July 24th, at KCAC"
   },
   '2009' : {
     nh_b : "MSC/B vs. Newport Hills/B, Tuesday, June 16th, at NH"
     ,nh_a : "MSC/A vs. Newport Hills/A, Thursday, June 18th, at MSC"
     ,eb_b : "MSC/B vs. Edgebrook/B, Tuesday, June 23rd, at MSC"
     ,eb_a : "MSC/A vs. Edgebrook/A, Thursday, June 25th, at EB"
     ,rh_b : "MSC/B vs. Rolling Hills/B, Tuesday, June 30th, at MSC"
     ,rh_a : "MSC/A vs. Rolling Hills/A, Thursday, July 2nd, at RH"
     ,mibc_b : "MSC/B vs. MI Beach Club/B, Tuesday, July 7th, at MIBC"
     ,mibc_a : "MSC/A vs. MI Beach Club/A, Thursday, July 9th, at MSC"
     ,micc_a : "MSC/A vs. MI Country Club/A, Tuesday, July 14th, at MICC"
     ,b_champs : "B-Division Championships, Saturday, July 18th, at NH"
     ,a_sr : "Senior Boys and Girls A-Champs, Monday, July 20th, at MIBC"
   }
  ,'2008' : {
    mibc_b : "MSC/B vs. MI Beach Club/B, Tuesday, June 17th, at MSC"
    ,mibc_a : "MSC/A vs. MI Beach Club/A, Thursday, June 19th, at MIBC"
    ,micc_b : "MSC/B vs. MI Country Club/B, Tuesday, June 24th, at MICC"
    ,micc_a : "MSC/A vs. MI Country Club/A, Thursday, June 26th, at MSC"
    ,nh_b   : "MSC/B vs. Newport Hills/B, Tuesday, July 1st, at MSC"
    ,nh_a   : "MSC/A vs. Newport Hills/A, Thursday, July 3rd, at Newport Hills"
    ,eb_b   : "MSC/B vs. Edgebrook/B, Tuesday, July 8th, at Edgebrook"
    ,eb_a   : "MSC/B vs. Edgebrook/B, Tuesday, July 10th, at Edgebrook"
    ,sam_a  : "MSC/A vs. Samena/A, Tuesday, July 15th, at MSC"
    ,sam_b  : "MSC/B vs. Samena/B, Thursday, July 17th, at Samena"
    ,b_champs:"B-Division Championships, Saturday, July 19th, at Newport Hills"
    ,JrGirls:"Junior Girls Prelims, Monday, July 21st, at Edgebrook"
    ,JrBoys : "Junior Boys Prelims, Tuesday, July 22nd, at Samena"
    ,a_champs : "League Championships, Saturday, July 26th, at KCAC"
  }
  ,'2007' : {
    sam_a  : "MSC/A vs. Samena/A, Tuesday, June 12th, at MSC"
    ,sam_b  : "MSC/B vs. Samena/B, Thursday, June 14th, at Samena"
    ,nh_b   : "MSC/B vs. Newport Hills/B, Tuesday, June 19th, at Newport Hills"
    ,nh_a   : "MSC/A vs. Newport Hills/A, Thursday, June 21st, at MSC"
    ,mibc_b : "MSC/B vs. MI Beach Club/B, Tuesday, June 26th, at MIBC"
    ,mibc_a : "MSC/A vs. MI Beach Club/A, Thursday, June 28th, at MSC"
    ,eb_b   : "MSC/B vs. Edgebrook/B, Tuesday, July 3rd, at MSC"
    ,eb_a   : "MSC/A vs. Edgebrook/A, Thursday, July 5th, at Edgebrook"
    ,micc_a : "MSC/A vs. MICC/A, Tuesday, July 10th, at MICC"
    ,micc_a : "MSC/B vs. MICC/B, Thursday, July 12th, at MSC"
    ,b_champs : "Division Championships, Saturday, July 14th, at Newport Hills"
    ,sr_prelims: "Senior Prelims, Monday, July 16th, at MICC"
    ,jr_boys: "Junior Boys Prelims, Tuesday, July 17th, at MIBC"
    ,jr_girls: "Junior Girls Prelims, Wednesday, July 18th, at Fairwood"
    ,a_champs: "League Championships, Saturday, July 21st, at KCAC"
  }
}
function showRes(s) {
  var si = s.selectedIndex,optVal,resFrame,meetname,fullmeet,year,meet;
  if (si >= 0) {
    if (s.options[si].disabled) return;
    optVal = s.options[si].value;
    if (optVal.length == 0) return;
    if (resFrame = document.getElementById('resframe')) {
      var src = 'meetresults/' + optVal;
      if (!/\./.test(optVal)) src += '.html';
      resFrame.src = src;
    }
    if (meetname = document.getElementById('meetname')) {
      while(meetname.lastChild) meetname.removeChild(meetname.lastChild);
      fullmeet = optVal.split('/');
      year = fullmeet[0];
      meet = fullmeet[1];
      meetname.appendChild(document.createTextNode(year + ': ' + meetObj[year][meet]));
    }
  }
}

function fillRes(sel) {
  var opt,ostring,oval;

  function addOption(sel,opt,group) {
    try {
      sel.add(opt);                 // try IE way first; the sucker won't catch!
    } catch(e) {
      try {
        var x = sel.add(opt,null);  // standard: add to the select
        if (group) {
          sel.removeChild(opt);     // if this worked, then remove it and
          group.appendChild(opt);   // add it to the optgroup
        }
      } catch(e) {};
    }
  }

  while(sel.firstChild) sel.removeChild(sel.firstChild);
  opt = document.createElement('option');
  opt.text = '[Select a meet]';
  opt.value = '';
  opt.selected = true;
  addOption(sel,opt,null);
  for (var year in meetObj) {
    var meets = meetObj[year];
    var group = sel.appendChild(document.createElement('optgroup'));
    group.label = year;
    for (var meet in meets) {
      ostring = meets[meet];
      ostring = ostring.slice(0,ostring.indexOf(','));
      ostring = ostring.replace(/^MSC\/[AB] vs./,'');
      opt = document.createElement('option');
      opt.text = ostring;
      opt.value = year + '/' + meet;
      opt.selected = false;
      addOption(sel,opt,group);
    }
  }
}
jQuery(document).ready(function() {
  var res;
  jQuery('#swimTabs li').eq(0).after(' <li><a href="#swimMeetResults">Meet Results<\/a><\/li>');
  jQuery('#swimMeetResults').html('<div id="meetform">Choose a meet: <select id="res" onchange="showRes(this)"><\/select><span id="meetname"><\/span><iframe id="resframe" width="100%" height="500" src=""><\/iframe><\/div>');
  res = document.getElementById('res');
  fillRes(res);
  window.swimRectabs = Tabs('#swimRecTabs','stRecTab');
  window.swimtabs = Tabs('#swimTabs','stTab');
  jQuery('a.bmagic').click(function() {
    alert('B-Champs relays that better these times receive no B-Champs points, and are automatically entered in A-Champs.');
  });

  jQuery('#jw,#jwit').each(function() {
    var addrs = {
      jw : ['joan.wold','comcast.net'],
      jwit : ['witman3','msn.com']
    }
    if (this.id in addrs)
      this.href = 'mailto' + ':' + addrs[this.id][0] + '@' + addrs[this.id][1];
  });
  jQuery('#mscrecords td').each(function() {
    var jQt = jQuery(this),
        txt = jQt.html();
    if (txt.match(/\b2009\b/)) {
      jQt.addClass('new');
      jQt.prev('td').addClass('new');
      jQt.prev('td').prev('td').addClass('new');
    }
  });
  jQuery('#swimteam a[rel=swimBDQTimes]').click(function() {
    jQuery(swimtabs[6]).trigger('click');
    jQuery(swimRectabs[2]).trigger('click');
  });
  jQuery('#swimParentGuide a[rel=swimGlossary]').click(function() {
    jQuery(swimtabs[5]).trigger('click');
  });
  jQuery('#mlrecords td:contains("MSC")').parent().find('td').css('color','red');
  jQuery('#mlrecords td:contains("2009")').parent().find('td').addClass('new');
  curMenu('#teamBtn','#team_swimBtn');
  breadCrumbs([['teams','../'],['swim']]);
});

