$(document).ready(function() {
  $('#subscription .text').focus(function() {
    if (!$(this).hasClass('cleared')) this.value = '';
    $(this).addClass('cleared');
  })
  
  $.fn.fancybox.defaults.path = '/javascripts/fancybox/';
  $.fn.fancybox.defaults.speed = 250;
  $('.fbox').fancybox();
  setTimeout(hideFlashes, 10000);
  
  $("li.button").hover(function() {
      $(this).addClass('highlighted');
    }, function() {
      $(this).removeClass('highlighted');
    })
  .click(function(e){
    $("#notice").hide()
    $(".section").hide().removeClass('selected')
    $(".button").removeClass('selected')
    $(this).addClass('selected')
    
    if ($(this).hasClass('subscribers')) {
      $('#subscriber_count').show();
    } else if ($(this).hasClass('foods')) {
      $('#foods').show();
    } else if ($(this).hasClass('specials')) {
      $('#admin_lunch').show();      
    } else if ($(this).hasClass('email')) {
      $('#email').show();      
    } else if ($(this).hasClass('settings')) {
      $('#settings').show();
    }
  })
  // load the initial via the URL anchor
  var l = document.location.href.split('#');
  if (l.length > 1) {
    $("li.button." + l[1]).click();
    $("#notice").show()
  }

})

function hideFlashes() {
  $('p#notice, p#error').fadeOut(2000)
}
