// lightbox image view
$(function() {
    $('#gallery a.image').lightBox();
});

// show gallery thumbnails
$(function() {

  // position all thumbnails in center their containers
  $('#gallery > li > div > a.image, #gallery_index > li > div > a.image').each(function(i) {
     var imgWidth = $(this).children('img').width();
     var imgHeight = $(this).children('img').height();
     $(this)
//      .css('margin-top', (-imgHeight/2)+'px')
//      .css('margin-left', (-imgWidth/2)+'px')
   });
   
  // show thumbnails one by one
  var nbItems = $('#gallery > li > div > a.image, #gallery_index > li > div > a.image').size();
  var item = $('#gallery > li > div > a.image, #gallery_index > li > div > a.image');
  $(item).animate({opacity: 0.7}, 100)
  $(item).hide();
  function outer(){
    var a = 0;
    function inner(){
      if (a >= nbItems)
      {
        $(item).show();
      }
      a++;
      $(item).eq(a-1).fadeIn(400, function(){fader();});
    }
    return inner;
  }
  var fader = outer();
  fader();
  
  // hover effect on thumbnails
  $('#gallery > li > div > a.image, #gallery_index > li > div > a.image')
    .bind('mouseenter', function(){ jQuery(this).animate({'opacity' : 1}, 350);})
    .bind('mouseleave', function(){ jQuery(this).animate({'opacity' : 0.7}, 350);});
    
  // hover effect on gallery index - show description background
  $('#gallery_index > li > a.description > span.highlight').hide();
  $('#gallery_index > li > div > a.image, #gallery_index > li')
    .bind('mouseenter', function(){ jQuery(this).find('a > span.highlight').fadeIn(700)})
    .bind('mouseleave', function(){ jQuery(this).find('a > span.highlight').fadeOut(700)})
    
});

