﻿(function() {
  var $ = jQuery;

  $(window).load(function() {
    $('.content').fadeIn('slow');  
  });

  document.write("<style>.content{display: none;}</style>");

  jQuery(function($){
    $('.content *').preloadBackgroundImages();

    if($(document.body).attr('class').split(/ /).length == 1) 
      $('.sub:visible').hide().slideDown('slow');
    
    $('.header-menu > li > a').click(function() {
      var sub = $('.sub-wrapper:visible');
      var location = $(this).attr('href');

      sub.slideUp(function() {
        window.location = location;
      });
      
      if(sub.length) return false;
    });
  });
 
  $.fn.preloadBackgroundImages = function() {
    return this.each(function(which, node) {
      var bg = $(node).css('background-image');
      if(bg != 'none') 
        $('<img style="visibility: hidden;">')
          .attr('src', bg.replace(/url\(|\)/g, ''))
          .appendTo(document.body);
    });
  }
})();