function addActiveClass(curr, next, opts) {
  var dst_id = $(next).attr('id');
  var dst = $("#"+dst_id);
  if (dst.find('.bio').length == 0) {
    load_remote_page(dst, dst_id, '../team/');
  }
  
  $(curr).addClass('active');
 };

 function activate_slide (dst_id) {
   var dst = $('#'+dst_id);
   location.hash = dst_id;
   // Check to see if the desired item is loaded in the DOM
   // If not, then load it in
   if (dst.find('.bio').length == 0) {
    load_remote_page(dst, dst_id, './team/'); 
   }
   
   var dst_index = $('#team-slideshow > li').index(dst);
   $('#team-slideshow').cycle(dst_index);
         
   dst.siblings().removeClass('active');
   dst.addClass('active');
   
   var dst_thumb = $('#thumb-'+dst_id);
   
   var dst_list = dst_thumb.parent();
   var dst_list_index = $('#team-list > ul').index(dst_list);
   $('#team-list').cycle(dst_list_index);
   $('#team-list li.active').removeClass('active').trigger('mouseout');
   dst_thumb.addClass('active');
   // dst_thumb.siblings().removeClass('active');
   // dst_thumb.parent().siblings().children('li').removeClass('active').trigger('mouseout');
   return false;
 }
 
 function load_remote_page(dst, dst_id, path) {
   dst.load(path+dst_id, null, function() {
     $(this).find('.bio').animate({ 
             bottom: '0'
           }, 250 );
   });
 };
 
$(document).ready(function() {
  
    var cache = {};
    
    $(window).bind( 'hashchange', function(e) {
      url = $.param.fragment();
      activate_slide(url);
    });
    
    $('#team-social a').live('click', function(){
        window.open(this.href);
        return false;
    });
    
    
    // ------ Team Slideshow

    // Meet Team Slideshow
    $('#team-slideshow').cycle({
      width: '785',
      height: '399',
      fx: 'fade',
      timeout: 0,
      speed: '2000',
      cleartype: 1,
      before: onBefore,
      after: onAfter
    });

    // Team List Thumbnail View
    $('#team-list').cycle({
      width: '940',
      height: '280',
      fx: 'scrollHorz',
      timeout: 0,
      speed: '2000',
      next: 'span#next',
      prev: 'span#previous',
      easing: 'easeInOutCirc'
    });
    
    // ------ Meet Team

    // Meet Team Thumbnails
    $("#team-list li").hover(function() {
        $(this).find(".info").animate({bottom:'0'},{queue:false,duration:500});
    	}, function(){
    	  if (!$(this).hasClass('active')) {
    	    $(this).find(".info").animate({bottom:'-50px'},{queue:false,duration:500});
    	  }
    });

    $('#team-list li').click(function() {
      var dst_id_raw = $(this).attr('id');
      if (dst_id_raw.length == 0) { return false; }

      var dst_id = dst_id_raw.substr(6);
      activate_slide(dst_id);
      
      $("html:not(:animated),body:not(:animated)").animate({ scrollTop: 0}, { duration: 500, easing: 'easeInOutExpo'});
      return false;
    });
    
    $("#team-list > ul > li:eq(0), #team-list > ul > li:eq(4), #team-list > ul:nth-child(2) > li:eq(0), #team-list > ul:nth-child(2) > li:eq(4), #team-list > ul:nth-child(3) > li:eq(0), #team-list > ul:nth-child(3) > li:eq(4)").css({marginLeft: "0"});
    $("#team-list > ul > li:eq(3), #team-list > ul > li:eq(7), #team-list > ul:nth-child(2) > li:eq(3), #team-list > ul:nth-child(2) > li:eq(7), #team-list > ul:nth-child(3) > li:eq(3), #team-list > ul:nth-child(3) > li:eq(7)").css({marginRight: "0"});


    // Previous Project Button
    $('#team-previous').click(function() { 
      
      var src = $('#team-slideshow li.active');
      var dst;
            
      if ($('#team-list li.active').prev('li').length > 0) {
        dst = $('#team-list li.active').prev();
      } else {
    	  if ($('#team-list li.active').parent().prev('ul').length > 0) {
    	    dst = $('#team-list li.active').parent().prev('ul').find('li:last-child');
    	  } else {
    	    dst = $('#team-list ul:last-child li:last-child');
    	  }
    	}

	    var dst_id = dst.attr('id').substr(6);
      activate_slide(dst_id);
      
      return false;
    });

    // Next Project Button
    $('#team-next').click(function() { 
      
      var src = $('#team-slideshow li.active');
      var dst;
          
      if ($('#team-list li.active').next('li').length > 0) {
        dst = $('#team-list li.active').next();            
      } else {
        if ($('#team-list li.active').parent().next('ul').length > 0) {
    	    dst = $('#team-list li.active').parent().next('ul').find('li:first-child');
    	  } else {
    	    dst = $('#team-list ul:first-child li:first-child');
    	  }
      }
      
      dst_id = dst.attr('id').substr(6);
      activate_slide(dst_id);
      
      return false;
    });
    
});
