jQuery(document).ready( function($) {
  $('#navigation>ul>li').not('.current_page_item, .current_page_parent, .current_page_ancestor').each( function() {
    var $prev = $(this).prev();
    if ( $prev.length > 0 ) {
      $(this).css({zIndex: $(this).prev().css('z-index')-1});
    }
  })
  .hover( function() {
      $(this).css({zIndex: 20});
    },
    function() {
      var $prev = $(this).prev();
      if ( $prev.length > 0 ) {
        $(this).css({zIndex: $(this).prev().css('z-index')-1});
      } else {
        $(this).css({zIndex: 10});
      }
    }
  );
  $('#navigation li:has(ul)').addClass('expanded');
  
  $('.linkbar').parents('#content').css({borderTop: 'none', paddingTop: 0});
  
  
  var rotation_timeout = null;
  var rotate_images = function( $element, delay ) {
    var transition = 1500;
    
    var $next = $element.next();
    if ( $next.length < 1 ) {
      $next = $element.siblings(':first-child');
    }
    if ( $next.length > 0 ) {
      $element.fadeOut(transition);
      $next.fadeIn(transition, function() {
        rotation_timeout = setTimeout( function(){
          rotate_images($next, delay);
        }, delay );
      });
    }
  }
  if ( $('.rotating-images li').length > 1 ) {
    var first = $('.rotating-images li:first-child img').get(0);
    if ( first.complete ) {
      setTimeout( function() { 
        rotation_timeout = rotate_images($('.rotating-images li:first-child'),8000);
      }, 8000);
    } else {
      first.onload = function() {
        setTimeout( function() { 
          rotation_timeout = rotate_images($('.rotating-images li:first-child'),8000);
        }, 8000);
      }
    }
  }
  
});