// Load Preload Images Plugin Right Away
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

$(window).load(function() {

  $('#cycler').cycle({
    timeout: 8000,
    before: function(current,next) {
      var nextid = $(next).attr('id').split('-');
      nextid = nextid[nextid.length-1];
      
      var currentid = $(current).attr('id').split('-');
      currentid = currentid[currentid.length-1];
      
      $('#cycler-note-'+currentid).fadeOut();
      $('#cycler-note-'+nextid).stop().css('display','block').show("slide",{ direction: "right" }, 800);
    }
  });
  $('.cycler-note .note').hover(function() {
    $('a',this).addClass('hover');
  },function() {
    $('a',this).removeClass('hover');  
  });
  $('.cycler-note .note').click(function() {
    href = $('.readmore a',this).attr('href');
    window.location = href;
  });
});

jQuery.preLoadImages(
  "/_images/26",
  "/_images/home-btn.da40-sprite.png",
  "/_images/home-btn.da42-sprite.png",
  "/_images/home-btn.da50-sprite.png",
  "/_images/home-btn.djet-sprite.png"
);

$(document).ready(function() {
  
  // Cufon
  Cufon.replace('.note h2', { fontFamily: 'Helvetica Neue Medium' });
  
  
  $('#home-aircraft-buttons li').hover(function() {
    
    $li = $(this);
    $li.css('margin','0px');    
    
    $a = $('a',this);
    $a.css('backgroundPosition','bottom');
    
    // Animate note
    $('.note',this)
      .stop()
      .css({
        'display':'block',
        'backgroundColor':'transparent'})
      .animate({
        opacity: 1,
        'filter':'none'
        });
        
    $li.css('margin','0px');
    
  },function() {
    
    $li = $(this);
    $li.css('margin','0px');
    $a = $('a',this);
    $a.css('backgroundPosition','top');
    
    // Animate note
    $('.note',this)
      .stop()
      .animate(
        { opacity: 0, 'filter': 'none' },
        200,
        function() {
          $(this).css('display','none');
        });
        
    $li.css('margin','0px');
  });
  
  $('#home-aircraft-buttons li').click(function() {
    href = $('a',this).attr('href');
    window.location = href;
  });
  
});
