jQuery(document).ready( function($) {
  initNavigation();

  var subnav = $('ul.nav li ul li.active ul');
  if (subnav) {
    subnav.prependTo('#subnav');
    var actPos = $('ul.nav li ul li.active').position();
    if (actPos != null) {
      var headerHeight = $('#header').outerHeight(true);
      $('#subnav').css('margin-top', actPos.top - headerHeight + 3);
    }
  }

  $('ul.nav li ul li ul').remove();

  var numImages = $('#faded img').size();

  if (numImages > 1) {
    $("#faded").faded({
      speed: 200, // sets animation speed.
      crossfade: true, // crossfades content.
      autoheight: 400, // auto adjust height.
      bigtarget: true, // click content for next.
      pagination: false, // "pagination", // sets true and class name for pagination. set to false to disable this feature.
      autopagination: false // set to true to auto generate pagination.
    });

    // Custom Init!...
    setTimeout( function() {
      var imgHeight = $('#faded img:eq(0)').outerHeight();
      $('#faded').children(":nth-child(1)").height(400);
    },600);
    
  } else if (numImages == 0) {
    $('#faded').remove();
  } else {
    $('#faded .next, #faded .prev').remove();
    $('#faded a').click(function(event){event.preventDefault()}).css('cursor','default');
  }

  if ($('#detailContent').html().length > 16) {
    // Overlay
    $('a[rel]').overlay({
      mask: {
        color: '#ebecff',
        loadSpeed: 500,
        opacity: 0.8
      },
      top: 150
    });
  } else {
    $('a[rel=#details]').remove();
  }
});
