jQuery(function(){

  // group gallery items
  jQuery('div.gallery a').each(function(){
    jQuery(this).attr('rel', jQuery(this).parent().attr('id'));
  });
    
  // Add Fancy Classes to single items:
  jQuery('a').each(function(){
    // filter items
    if (          this.href.substr(-4).toLowerCase().indexOf('.jpg') < 0 &&
                  this.href.substr(-5).toLowerCase().indexOf('.jpeg') < 0 &&
                  this.href.substr(-4).toLowerCase().indexOf('.png') < 0 &&
                  this.href.substr(-4).toLowerCase().indexOf('.gif') < 0 &&
                  this.href.substr(-4).toLowerCase().indexOf('.bmp') < 0 &&
                  this.href.substr(-5).toLowerCase().indexOf('.wbmp') < 0 &&
                  this.href.substr(-4).toLowerCase().indexOf('.ico') < 0 &&
                  true )
    return;
    
    // shorter access path
    var $lnk = jQuery(this); 

    // Add the fancybox class
    $lnk.addClass('fancybox');
    
    // Copy the title tag from link to img
    var $img = $lnk.find('img');
    if ( $img.attr('title') == '' ) $img.attr('title', $img.attr('alt'));
    if ( $lnk.attr('title') == '' ) $lnk.attr('title', $img.attr('title'));
  });
  
  jQuery('a.fancybox')
  .unbind('click')
  .fancybox({

    cyclic         :  true,
    scrolling      : 'no',
    centerOnScroll :  true,
    overlayOpacity :  0.6,
    overlayColor   : '#99B5B8',
    titleShow      :  true,
    titlePosition  : 'inside',
    transitionIn   : 'fade',
    transitionOut  : 'none',    
    speedIn        :  300,
    speedOut       :  150,
    changeSpeed    :  300    

  });

});
