(function ($) {
  $(document).ready(function() {
    //------------------------------------------------------------------------
    // EXHIBITONS                                                            
    //------------------------------------------------------------------------
    // Hide all exhibition details that aren't set to be open.
    $('.node-exhibition-toggle:not(.node-exhibition-toggle-open) .exhibition-details').hide();

    // Open and close exhibition details on click.
    $('.node-exhibition-toggle h2 span').click(function() {
      var exhibition = $(this).parents('.node-exhibition-toggle:first');
      exhibition.find('.exhibition-details').slideToggle('fast');
      $(this).toggleClass('open');
      exhibition.toggleClass('node-exhibition-toggle-open');
    });
    
    //------------------------------------------------------------------------
    // ARTWORK                                                            
    //------------------------------------------------------------------------
    $('.view-artists .views-view-grid a img').hover(
      function() {
        var artist = $(this).parent().attr("href");
        artist = 'a[href=' + artist + ']';
        $(artist).addClass("sel");
        $(this).fadeTo("fast", 0.5); // TODO : Use Drupal.settings.artwork_image.fade_to
      },
      function() {
        var artist_href = $(this).parent().attr("href");
        artist = '#side a[href=' + artist_href + ']';
        $(artist).removeClass('sel');
        $(this).fadeTo("fast", 1.0, function() {
          artist = 'a[href=' + artist_href + ']';
          $(artist).removeClass("sel");        
        });
      }
    );
    
    
    $('#side .view-artists ul.menu a, #side .view-stockroom ul.menu a').hover(
        function() {
          var artwork = $(this).attr("href");
          artwork = 'a[href=' + artwork + ']';
          $(artwork).find('img').fadeTo("fast", 0.5);
          $(artwork).addClass("sel");
          $(this).addClass('sel');
        },
        function() {
          $(this).removeClass('sel');
          var artwork = $(this).attr("href");
          artwork = 'a[href=' + artwork + ']';
          $(artwork).find('img').fadeTo("fast", 1.0, function() {
            $(artwork).removeClass("sel");
          });
        }
      );    
  });
}(jQuery));;
/*
Tested with http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js
in FF Mac, Safari Mac, Chrome Mac, Opera Mac, FF PC, IE 7 and 8, IE 6 works with css hack on LIs _width:3px;
Requirements: Menu structure has to be <ul><li><a...
<ul> must have a class or id
*/  

/* PAD LIs EVENLY */    
(function($){  
  $.fn.limenupadding = function(options) {  
  var opts = $.extend({
  exclude: 0 // exclude from calculation for end caps: positive interger
  },options);
  if(opts.exclude > 0 ){
    var exclude = opts.exclude;
  }
  var lisTotalWidth = 0;  
  var ulWidth = ((this).width() - exclude); /* exclude is adjustment amount. Used here to subtract end caps */
  var liCount = $((this).children()).size()
  $((this).children()).each(function() {
    lisTotalWidth += $(this).width();
  }); 
  var difference = ulWidth - lisTotalWidth;
  if (difference < 0 ) {
    return;
//   alert ("Total width of menu items in '" + $(this).attr('class') + "' exceeds available space. Use fewer menu items, use shorter labels, or make menu wider.");
  }
  var paddingLRraw = (difference/(liCount - 1))/2;
  var paddingLRfloor = Math.round(paddingLRraw);
  /* distribute computed padding across all LIs */
  $((this).children().children()).css({'padding-left': paddingLRfloor});
  $((this).children().children()).css({'padding-right': paddingLRfloor});
  $(this).css('margin-left', (0 - paddingLRfloor));
  $(this).css('margin-right', (0 - paddingLRfloor));
  };  
})(jQuery); ;
(function ($) {
  $(document).ready(function () {
    $('body').addClass('has-js');
    $('#nav ul.menu').limenupadding({'exclude' : 16});
  });
}(jQuery));;

