/**
 * @note Application level jQuery and/or javascript code
 */
$(document).ready(function() {
  var animSpeed = 300;
  /**
   * Code for the pop-up submenu under Destinations
   */
  var showMenu = true; // boolean for menu state
  // $('#nav-destinations .submenu').prepend('<div class="submenu-arrow" />');
  $('#nav-destinations a').not('.submenu a').click(function(e) {
    e.preventDefault();
    if(showMenu) {
      $('#nav-destinations .submenu').fadeIn(animSpeed);
      showMenu = false;
    } else {
      $('#nav-destinations .submenu').fadeOut(animSpeed);
      showMenu = true;
    }
  });
  // clicking anywhere on the document closes the pop-up
  $(document).click(function(e) {
    $('#nav-destinations .submenu').fadeOut(animSpeed);
    showMenu = true;
  });
  // stop the propagation of the document.click() event above for #nav items
  $('#nav').unbind('click').click( function(e) {
    e.stopPropagation();
  });
  
  /**
   * Destinations list effects
   */
  var destinations = '#destination-list li a';
  var destinationImgs = destinations + ' img';
  var startOpacity = 0.72;
  var endOpacity = 1;
  $(destinationImgs).css({
    opacity: startOpacity
  });
  $(destinations).mouseover(function(e) {
    $(this).children('img').stop().animate({
      opacity: endOpacity
    }, animSpeed);
  });
  $(destinations).mouseout(function(e) {
    $(this).children('img').stop().animate({
      opacity: startOpacity
    }, animSpeed);
  });
  
  $('#destination-list ul li:nth-child(even)').addClass('last');
});
