$(document).ready(function() {
  
  $('.with-js .form-row label').click(function() {
    $(this).css('display', 'none');
    var inputBox = $(this).parent().find('input');
    inputBox.val('');
    inputBox.addClass('with-label');
    inputBox.focus();
    inputBox.blur(function() {
      if ($(this).val() == '')
      {
        $(this).parent().find('label').css('display', 'block');
      }
    });
  });
  
  $('.with-js .form-row input').focus(function() {
    if ($(this).parent().has('label')) {
      var label = $(this).parent().find('label');
      label.css('display','none');
    }
  });
  
  $('.with-js .form-row input').blur(function() {
    if ($(this).val() == '')
    {
      $(this).parent().find('label').css('display', 'block');
    }
  });
 
  $('#account-bar ul ul').css('visibility','hidden');
  // 
  // $('#league-switcher').click(function() {
  //   $('#league-switcher ul').toggle();
  // });
  
  // $(document).click(function() {
  //   $('#league-switcher ul').hide();
  // });
  
  var timeout    = 200;
  var closetimer = 0;
  var abarmenuitem = 0;

  function abar_open()
  {  
    abar_canceltimer();
    abar_close();
    abarmenuitem = $(this).find('ul').css('visibility', 'visible');
  }

  function abar_close()
  {  
    if (abarmenuitem) abarmenuitem.css('visibility', 'hidden');
  }

  function abar_timer()
  {  
    closetimer = window.setTimeout(abar_close, timeout);
  }

  function abar_canceltimer()
  {  
    if (closetimer) {
      window.clearTimeout(closetimer);
      closetimer = null;
    }
  }

  $('#account-bar .account-bar-item').bind('mouseover', abar_open)
  $('#account-bar .account-bar-item').bind('mouseout',  abar_timer)

  $(document).click = abar_close;
  
});
