﻿$(document).ready(function() {
    // Cycle images 
    $(".cycle").cycle({
      fx: "fade",
      speed: 2500,
      timeout: 15000,
      prev: ".prev",
      next: ".next",
      startingSlide: (Math.floor(Math.random() * $("img", this).length) + 1)
    });

    // Add "fancy" slide down/up action to profile blurbs in the team section.
    // Do this by toggling "+" or "-" buttons.
    $(".profile").click(function() {
	    var jElement = $(this);
	    
	    if (jElement.hasClass("more")) {
          $(".blurb", $(this).parent()).slideDown("fast", function() {
            // Send the profile section to top of screen if blurb runs off viewport
            var fold = $(window).height() + $(window).scrollTop();
            if (fold <= $(this).offset().top + $(this).height()) {
              $.scrollTo($("a[name]", $(this).parent()), 800);
            }
          });
          
          jElement.removeClass("more");
          jElement.addClass("less");
        } else {
	      $(".blurb", jElement.parent()).slideUp("fast");        
          jElement.removeClass("less");
          jElement.addClass("more");
        }
      });
      
    // Track Donate Now button clicks using Analytics Javascript API.
    $(".donate-button").click(function() {
      if (!window["pageTracker"]) {
        return;
      }
      
      var jAnchor = $(this);
      var action = jAnchor.attr("id") ? jAnchor.attr("id") : "inPageButton";
      pageTracker._trackEvent(
          "DonateNowButtonClick",
          action,
          window.location.href);
    });
});