$(function(){
  // Pre-load CSS hover images
  new Image().src = '/images/common/menu.bg.middle.hover.png';
  new Image().src = '/images/common/menu.bg.left.hover.png';
  new Image().src = '/images/common/menu.bg.right.hover.png';
  new Image().src = '/images/common/menu.icon.cart.hover.png';
  
  // Activate footer tooltips
  $('body[class!="home"] div.footer ul.menu-bar li a').qtip({
    position: { adjust: { y: -10 }, corner: { target: 'topMiddle', tooltip: 'bottomMiddle' } },
    show: { delay: 0, when: 'mouseover' },
    hide: { delay: 0, when: 'mouseout' },
    style: { border: { radius: 3, width: 1 }, name: 'dark', textAlign: 'center', tip: 'bottomMiddle' }
  });
  
  // Activate cart tooltips
  $('div.cart-content a[title]').qtip({
    position: { adjust: { y: 4 }, corner: { target: 'bottomMiddle', tooltip: 'topMiddle' } },
    show: { delay: 0, when: 'mouseover' },
    hide: { delay: 0, when: 'mouseout' },
    style: { border: { radius: 3, width: 1 }, name: 'dark', textAlign: 'center', tip: 'topMiddle' }
  });
  
  // Allow form confirmations to disappear
  $('div.form-confirmation').click(function(){
    $(this).hide('blind', function(){ $(this).remove(); });
  });
  
  // Allow form validation errors to disappear
  $('ul.error_list li').click(function(){
    var $target = $(this).is(':only-child') ? $(this).parent() : $(this);
    $target.hide('blind', function(){ $(this).remove(); });
  });
  
  // Activate zoomable image links
  $('a.fancybox.zoom')
  .fancybox({ titleShow: true, hideOnContentClick: true })
  .children('img')
    .qtip({
      content: { text: 'Click to enlarge' },
      position: { corner: { target: 'topLeft', tooltip: 'bottomLeft' } },
      show: { delay: 0, when: 'mouseover' },
      hide: { delay: 0, when: 'mouseout' },
      style: { border: { radius: 3, width: 1 }, name: 'dark', textAlign: 'center', tip: 'bottomMiddle' }
    });
});