if (Drupal.jsEnabled) {
  $(window).load(function() {
    // Duplicate the exploreNav to create the "sel" version
    $('#exploreNav').clone().attr('id', 'exploreNavsel').insertAfter('#exploreNav')
      .find('li').addClass('sel');

    // Set up our animation sets
    var sets = [
      $('#exploreAnimate #exploreNavsel .explore, #exploreAnimate #text .explore, #exploreAnimate #photos .explore'),
      $('#exploreAnimate #exploreNavsel .theatre, #exploreAnimate #text .theatre, #exploreAnimate #photos .theatre'),
      $('#exploreAnimate #exploreNavsel .instructionalmusic, #exploreAnimate #text .instructionalmusic, #exploreAnimate #photos .instructionalmusic'),
      $('#exploreAnimate #exploreNavsel .vocalmusic, #exploreAnimate #text .vocalmusic, #exploreAnimate #photos .vocalmusic'),
      $('#exploreAnimate #exploreNavsel .dance-cheer, #exploreAnimate #text .dance-cheer, #exploreAnimate #photos .dance-cheer'),
	  $('#exploreAnimate #exploreNavsel .speech-debate, #exploreAnimate #text .speech-debate, #exploreAnimate #photos .speech-debate'),
	  $('#exploreAnimate #exploreNavsel .activities, #exploreAnimate #text .activities, #exploreAnimate #photos .activities')
    ];
  
    var speed = 1000;
    var pause = 3000;
    
    var shown = 0;
    var crossFade = function() {
      var next = (shown + 1) % (sets.length);
      sets[shown].fadeOut(speed);
      sets[next].fadeIn(speed);
      shown = next;
    };
    
    if (Drupal.settings.ima.is_front) {
      var looper = setInterval(crossFade, pause);
    }
    else {
      var classLabel = Drupal.settings.ima.selected_tab;
      $('#exploreAnimate #exploreNavsel li, #exploreAnimate #text li, #exploreAnimate #photos li').not('.' + classLabel).hide();
      var set = $('#exploreAnimate #exploreNavsel .' + classLabel + ', #exploreAnimate #text .' + classLabel + ', #exploreAnimate #photos .' + classLabel).show();
    }
    
    // And now also add the hover effect which terminates the rotation.
    $('#exploreNav a, #exploreAnimate #static li').hover(function() {
      // On hover.
      if (Drupal.settings.ima.is_front) {
        clearInterval(looper);
      }
      if ($(this).is('li')) {
        var classLabel = $(this).attr('class');
      }
      else {
        var classLabel = $(this).parent().attr('class');
      }
      $('#exploreAnimate #exploreNavsel li, #exploreAnimate #text li, #exploreAnimate #photos li').not('.' + classLabel).hide();
      var set = $('#exploreAnimate #exploreNavsel .' + classLabel + ', #exploreAnimate #text .' + classLabel + ', #exploreAnimate #photos .' + classLabel).show();
    }, function() {
      // On un-hover.
    });
  });
}
