$(document).ready(function() {
	$('ul.main-navigation').superfish({
		autoArrows: false,
		delay: 0
	});

	$('.advanced-search').hide();
	$('.search input').focus(function() {
		$('.advanced-search').show();
	});
	$('.advanced-search .close').click(function() {
		$('.advanced-search').hide();
	});
  
  $('.login-container .close').click(function() {
    $('.login-container').hide();
    return false;
  });
  
  // User Login button pops up modal
  $(".login-button").overlay({
    closeOnClick: false,
    expose: {
      color: 'white',
      opacity: 0.8,
      closeOnClick: false
    },
    start: {
      absolute: false,
      top: 'center',
      left: 'center'},
    finish: {
      absolute: false,
      top: 'center',
      left: 'center'},
    onLoad: function() {
      $("#header-login").focus();
    }
  });
  
  // Links that require login load the overlay if not logged in
  // forwardPage is changed to the link's href
  oldForwardPage = $("#forwardPage").val();
  api = $("#login-container").overlay({
    api: true,
    closeOnClick: false,
    expose: {
      color: 'white',
      opacity: 0.8,
      closeOnClick: false},
    finish: {
      absolute: false,
      top: 'center',
      left: 'center'},
    onClose: function() {
      $("#forwardPage").val(oldForwardPage);
    },
    onLoad: function() {
      $("#header-login").focus();
    }
  });
  
  $("a.login-required").click(function() {
      if(!loggedIn) {
        $("#forwardPage").val($(this).attr("href"));
        api.load();
        return false;
      }
      else {
        return true;
      }
    });
  
  $("#header-login,#header-password").keydown(function(e) {
    if(e.keyCode == 13) {
      document['HeaderLoginForm'].submit();
    }
  });
  
  // display text that goes away when you click in the search box
  $('#q').example("Search Accredited Activites");
  
  // contact form tool tips
  $('form.contact-form :input').tooltip({
    position: ['center','right'],
    offset: [10, 10],
    opacity: 0.8
  });

	$('a#registration_form_button[rel]').overlay({
		closeOnClick: false,
		expose: {
			color: 'white',
			opacity: 0.8,
			closeOnClick: false
		}
	});

});