function hideSlideshowCaption() {
  $(".slideshow-caption").fadeOut();
}

function updateSlideshowCaption() {
  var href = $(this).find("a").attr("href");
  var title = $(this).find("img").attr("alt");
  var outputstring = "<a href='" + href + "'>" + title + "</a>";
  $(".slideshow-caption").html(outputstring);
  $(".slideshow-caption").fadeIn();
}

/* this snippet for tracking outbound links */
function recordOutboundLink(link, category, action, label) {
  // _gat._getTrackerByName()._trackEvent(category, action);
  _gaq.push(['_trackEvent', category, action, label]);
  setTimeout('document.location = "' + link.href + '"', 100);
}


$(document).ready(function() {
  $('.slideshow').cycle({
    fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    before: hideSlideshowCaption,
    after: updateSlideshowCaption
  });				

   $('.slideshow-controls a.prev').click(function() {
     $("ul.slideshow").cycle("pause");
     $("ul.slideshow").cycle("prev");
     return false;
   });
  
   $('.slideshow-controls a.next').click(function() {
     $("ul.slideshow").cycle("pause");
     $("ul.slideshow").cycle("next");
     return false;
   });

   /* open links with this class in a popup window */

   $('a.popup').click(function() {
     window.open(this.href);
     return false;
   });
   
   $(".lightbox").fancybox();
   
   // track a download
   $("a.tracked-download").click(function() {
     recordOutboundLink(this, 'Downloaded file', $(this).attr("href"));
     return false; // the function then forwards the user agent on.
   });

   // track an outbound link
   $("a.tracked-outbound").click(function() {
     recordOutboundLink(this, 'Outbound link', "Click", $(this).attr("href"));
     return false; // the function then forwards the user agent on.
   });

});

