Cufon.replace('h2, p.h2B, div.story h2, div.doc-info h3, div.story h4, div#newsSB dl dt, #masthead h1, #alignBot h2, #alignBot h4, #content h3, #contentWide h3, #portfolio dl dd.bd-blue, #portfolio dl dd.bd-purple, #portfolio dl dd.bd-green, #portfolio dl dd.bd-violet, #portfolio dl dd.bd-brown, #portfolio dl dd.bd-red, #portfolio dl dd.bd-orange' , {
  fontFamily: 'Avenir 55' ,
  hover: true
});
Cufon.replace('#bluebutton, #pinkbutton, #content h4.subtitle, #content div.box h4.bd-blue, #content div.box h4.bd-green, #content div.box h4.bd-red, #content div.box h4.bd-orange, #content h4, #contentWide h4, ul#nav > li > a, #slideshow li a, div#moreInfos ul li h1, div#moreInfos ul li p, div#moreInfos ul li a, #slideshow li h1, #content ul.pastClasses a, #content ul.joinClass a, .orangeList h2, .blueList h2, .redList h2, #tout_rss_feed h4, #content .leadbox h3, #fellowsLearnMore span, .fellowsLearnMore span' , {
  fontFamily: 'Avenir 55' ,
  hover: true
});

$(document).ready(function() {

  //Get the current url anchor
  var video = jQuery.url.param('v');

  if(!video){
    if($('.videoplayer-fellows').length > 0){
      video = "6t1aXkYglpQ"; //If there is no url anchor
    }
    else if($('.videoplayer-become').length > 0){
      video = "--gSKA6ViGQ"; //Some other video
    }    
    else if($('.videoplayer-placement').length > 0){
      video = "rRH5y8kv3Jo"; //Some other video
    }    
  }

  //Setup the youtube video player
  swfobject.embedSWF("http://www.youtube.com/v/"+video+"?enablejsapi=1&playerapiid=videoplayer&rel=0",
    "videoplayer", "550", "332", "8", null, null, {
      allowScriptAccess: "always",
      wmode:"transparent"
    }, {
      id: "videoplayer"
    });


  //Sets up the correct video
  $("#videoList a").each(function(){
    jQuery.url.setUrl($(this).attr('href'));

  });

  $(".videoBox").click(function(){
    
    var videoUrl = $(this).find("a").attr("href");
    $("#videoList .selected").removeClass("selected");
    $(this).addClass("selected");

    var ytplayer = $("#videoplayer").get(0);

    ytplayer.loadVideoByUrl(videoUrl);
    ytplayer.playVideo();

    return false;

  });

  $('a.playPopup').colorbox({
    iframe:true,
    innerWidth:550,
    innerHeight:332
  });

  //Make entire Fellowship Year item clickable
  $("#content ul.fellowshipYear li").click(function(){
    window.location=$(this).find("a").attr("href");
    return false;
  });


  $("#slideshow li").click(function(){
    window.location=$(this).find("a").attr("href");
    return false;
  });

  $('.nav_container').addClass('toplevel');
										 
  //homepage slideshow script is on the homepage template in order for the slideshow nav to load before the rest of the page

  $("div#moreInfos ul li").click(function(){
    window.location=$(this).find("a").attr("href");
    return false;
  });

  $('#nav li ul li:last-child').addClass('last');
	
  $('#nav li ul').mouseover( function() {
    prevTag = $(this).prev('a');

    if(!$(prevTag).hasClass('selected')){
      $(prevTag).attr('class', 'selected hover');
    }
  });

  $('#nav li ul').mouseout( function() {
    prevTag = $(this).prev('a');

    if($(prevTag).hasClass('hover')){
      $(prevTag).removeAttr('class');
    }
  });

  $('#nav ul ul').parent().addClass('secondLev');

  $('#staff').change(function (){
    location.href = $(this).attr('value');
  });
  

  $('.docsbar .trigger a').click(function () {
    $('#Documents').slideToggle(500);
    if($(this).hasClass('selected')){
      $(this).removeClass('selected');
    }else{
      $(this).addClass('selected');
    }

    return false;
  });

  $('.vidbar .trigger a').click(function () {
    $('#Videos').slideToggle(500);

    if($(this).hasClass('selected')){
      $(this).removeClass('selected');
    }else{
      $(this).addClass('selected');
    }
    
    return false;
  });

  $('.photosbar .trigger a').click(function () {
    $('#Photos').slideToggle(500);

    if($(this).hasClass('selected')){
      $(this).removeClass('selected');
    }else{
      $(this).addClass('selected');
    }
    
    return false;
  });

  $('.storiesbar .trigger a').click(function () {
    $('#Stories').slideToggle(500);

    if($(this).hasClass('selected')){
      $(this).removeClass('selected');
    }else{
      $(this).addClass('selected');
    }

    return false;
  });

  evenHeight();

//alert($('#spotlight dl:first').outerHeight());
  
});

function evenHeight(){
  dl = $('#spotlight dl');

  maxHeight = 0;

  for(i=0; i<dl.length; i++){
    if(maxHeight < $(dl[i]).height()){
      maxHeight = $(dl[i]).height();
    }
  };

  for(i=0; i<dl.length; i++){
    $(dl[i]).css('height', maxHeight+'px');
  };

//alert(maxHeight);
};


$(window).load(function(){  
		$('.tout_feed_content').cycle({
				fx: 'scrollHorz',
				speed: 700,
				timeout: 7000,
				next: '#tout_rss_feed li#scrollRight',
				prev: '#tout_rss_feed li#scrollLeft'
		});

});
