
Cufon.replace('h1,h2', { fontFamily: 'CA BND Web Bold' });
Cufon.replace('.article .title', { fontFamily: 'Pea Posey' });

jQuery(function($) {

  // Fancybox the flickr photo thumbs
  $("#flickr_photos li a").add('.section.photos li a').fancybox({
    overlayColor: '#000000',
    overlayOpacity: .8,
    zoomSpeedIn: 400,
    zoomSpeedOut: 300,
    zoomSpeedChange: 250
  });
    
  if($('body').hasClass('home')) {
    // Fancybox the videos
    $('#videos a').fancybox({
      overlayColor: '#000000',
      overlayOpacity: .8,
      zoomSpeedIn: 400,
      zoomSpeedOut: 300,
      zoomSpeedChange: 250,
      frameWidth: 640,
      frameHeight: 505,
      hideOnContentClick: false
    });
    // setup ul.tabs to work as tabs for each div directly under div.panes 
    $("#featured_news ul.tabs").tabs("#featured_news .panes > .article", {
      effect: 'fade', 
      fadeOutSpeed: 'slow',
      event: 'mouseover',
      initialIndex: 3,
      rotate: true
    }).slideshow({ interval: 3000 });
    $("#featured_news ul.tabs").tabs().play();
  }
  
  if($('body').hasClass('albums')) {
  
    // Fancybox the lyrics  
    $('#songs a.lyrics').fancybox({
      overlayColor: '#000000',
      overlayOpacity: .4
    });
    
    // Find the index of the current album and use as the initial offset for the carousel
    // TODO: multiple albums containing the same (ie. "Argus" and "Argus 'Then Again Live'"
    albumTitle = $('.article.single h1').text();
    albumLI = $("#albums_carousel li img[alt='" + albumTitle + "']").parents('li');
    albumIndex = $('#albums_carousel li').index(albumLI);
    
    // Setup the carousel
    $('#albums_carousel').jcarousel({
      scroll: 5,
      start: albumIndex+1
    });
    
    // Grid/Carousel Switcher
    $('#view-grid').click(function() {
      var $cont = $('#albums_carousel_container');
      var $ul = $cont.find('ul');
      $cont.addClass('grid');
      var gridHeight = $ul.height() + 40;
      carouselStartLeft = $ul.css('left');
      $ul.css('left','0');
      $cont.animate({ height: gridHeight }, 500);
      $('#sidebar .single_photo').animate({ marginTop: '-45px' }, 500);
      $('.jcarousel-prev', $cont).add('.jcarousel-next', $cont).hide();
      $(this).hide();
      $('#view-carousel').show();
      return false;
    });
    $('#albums_options #view-carousel').click(function() {
      var $cont = $('#albums_carousel_container');
      var $ul = $cont.find('ul');
      var gridHeight = '120';
      $('#sidebar .single_photo').animate({ marginTop: '-201px' }, 500);
      $cont.animate({ height: gridHeight }, 500, function() {
        $('.jcarousel-prev', $cont).add('.jcarousel-next', $cont).show();
        if(carouselStartLeft) $ul.css('left',carouselStartLeft);
        $cont.removeClass('grid');
        $('#view-carousel').hide();
        $('#view-grid').show();
      });
      return false;
    });    
    
  }
  
});