Cufon.replace('h1:not(body.russian h1, body.chinese h1, body.hindi h1 ), h2, #body h3, h4, h5, h6, .quote blockquote p, dl.hero-panel dd strong, a.rss-logo, blockquote p, #wide_slot_0.open-day strong, #wide_slot_1.open-day strong, #wide_slot_2.open-day strong, .component.upcoming-events-list.wide ul li a, .component.upcoming-events-list.small ul li a:not(body.events_list .component.upcoming-events-list.small ul li a, body.event_page .component.upcoming-events-list.small ul li a)', {
  hover: 'true',
  fontFamily: 'Helvetica Neue LT Std'
});




// Used for converting div contents into an Object
var hero_panelContents = [];
var hero_panelTransition;

$(document).ready(function () {
  
  
  $('body.outreach #content .component h2').css("font-size","2.4em");
  $('body.outreach #content .quote blockquote p').css("font-size","2.4em");
  
  Cufon.replace('body.outreach #content #related.component h2, body.outreach #content #in-this-section.component h2, body.outreach #content #also-of-interest.component h2, body.outreach #content blockquote p, body.outreach #content .component.open-day h2, body.outreach #content .component.latest-content h2, body.outreach #content .component.general-content h2, body.outreach #content .component.gallery h2, body.outreach #content .component.archive h2, body.outreach #content .component.download h2, , body.outreach #content .component.comments h2:first-child', { 
    hover: 'true',
    fontFamily: 'Headline One'
  });
  

  $('body#the-college-virtual-tour #body').append('<div id="flash-vt"><div id="virtual-tour"><p>In order to view this content you will need the flash plugin. If you would like to do so then you can download the plugin from <a href="http://www.adobe.com/products/flashplayer/" title="Download Flash Player">Adobe</a>.</p></div></div>');

  $('a.lightbox').fancybox({
      'padding'        : 20,
      'autoScale'      : true,
      'transitionIn'    : 'elastic',
      'transitionOut'    : 'elastic',
      'title'          : false,
      'width'        : 680,
      'height'        : 495,
      'centerOnScroll'   : true
  });

  // quote lightbox
  $('div.component.quote').each(function(){
    // make a copy of the quote element
    // so that lightbox does not remove it
    // from the page
    mini_me = $(this).clone(true);
    mini_me.attr('id',$(this).attr('id') + '_clone');
    mini_me.addClass('clone');
    $(this).find('.quote-body').hide();
    mini_me.hide();
    $(this).after(mini_me);
  });
  $('div.component.quote:not(.clone)').click(function(){
    $.fancybox({
      'href'           : '#' + $(this).attr('id') + '_clone',
      'padding'        : 20,
      'autoScale'      : true,
      'transitionIn'   : 'elastic',
      'transitionOut'  : 'elastic',
      'title'          : false,
      'centerOnScroll' : true,
      'autoDimensions' : true,
      'onStart'        : function(selectedArray){ $($(selectedArray).first().attr('href')).show(); },
      'onClosed'        : function(selectedArray){ $($(selectedArray).first().attr('href')).hide(); }
    });
  });

  // Video Lightbox
  var videoUrl = 'video=' + escape($('a.lightboxVideo').attr('href')) + '&standalone=true';

  $('a.lightboxVideo').fancybox(

  {
      'padding'        : 20,
      'autoScale'      : true,
      'transitionIn'   : 'elastic',
      'transitionOut'  : 'elastic',
      'title'          : false,
      'titleShow'    : false,
      'width'        : 700,
      'height'        : 400,
      'type'            : 'swf',

    'swf': {
         'allowFullScreen'  : true,
         'flashvars'     : videoUrl,
         wmode: 'transparent'
     },

    'href'      : '/flash/video.swf',
      'centerOnScroll'   : true
  });

  $('form.search input[type=text]').click(
    function() {
      if (this.value == "Enter keyword(s) here") {
        this.value = '';
      }
    }
  );

  $('form.search input[type=text]').blur(
    function() {
      if (this.value == '') {
        this.value = "Enter keyword(s) here";
      }
    }
  );

  $('form.default-values').each(function(){
    $(this).find('input[type=text], textarea').each(function(){
      $(this).focus(function(){
        e=$(this);
        if(e.val()==this.defaultValue){
          e.val('');
          e.removeClass('default-value');
        }
      });
      $(this).blur(function(){
        e=$(this);
        if(e.val()==''){
          e.addClass('default-value');
          e.val(this.defaultValue);
        }
      });
    });
  });



  // Carousel for Small Slots (Open Days)
    $(".small.single.open-day .carousel").each(function(index, gallery) {
        gallery = $(gallery);
        if (gallery.find('li').length > 1) {
          gallery.before("<a class='carousel-back'>Backward</a>");
          gallery.after("<a class='carousel-forward'>Forward</a>");

          gallery.jCarouselLite({
            btnNext: gallery.next(".carousel-forward"),
            btnPrev: gallery.prev(".carousel-back"),
            visible: 1
          });
        }
      });
      
      // Carousel for Small Slots (Gallery )
        $(".small.single.gallery .carousel").each(function(index, gallery) {
            gallery = $(gallery);
            if (gallery.find('li').length > 1) {
              gallery.before("<a class='carousel-back'>Backward</a>");
              gallery.after("<a class='carousel-forward'>Forward</a>");

              gallery.jCarouselLite({
                btnNext: gallery.next(".carousel-forward"),
                btnPrev: gallery.prev(".carousel-back"),
                visible: 1,
                auto: 2000,
                speed: 500
              });
            }
          });
      
      
      
  // Carousel for Double Slots (Open Days Only)
    $(".small.double.open-day .carousel").each(function(index, gallery) {
        gallery = $(gallery);
        if (gallery.find('li').length > 2) {
          gallery.before("<a class='carousel-back'>Backward</a>");
          gallery.after("<a class='carousel-forward'>Forward</a>");

          gallery.jCarouselLite({
            btnNext: gallery.next(".carousel-forward"),
            btnPrev: gallery.prev(".carousel-back"),
            visible: 2
          });
        }
      });
      
  // Carousel for Double Slots (Gallery Only)
    $(".small.double.gallery .carousel").each(function(index, gallery) {
      gallery = $(gallery);
      if (gallery.find('li').length > 3) {
        gallery.before("<a class='carousel-back'>Backward</a>");
        gallery.after("<a class='carousel-forward'>Forward</a>");
    
        gallery.jCarouselLite({
          btnNext: gallery.next(".carousel-forward"),
          btnPrev: gallery.prev(".carousel-back"),
          visible: 3
        });
      }
    });
    

    // Carousel for Wide Slots (Gallery Only)
    if ( $('body').hasClass('page_b') ) {

      // Carousel for Wide Slots on Page B Template (Gallery Only)
          $(".page_b .wide.gallery.widget .carousel").each(function(index, gallery) {
            gallery = $(gallery);
            if (gallery.find('li').length > 5) {
              gallery.before("<a class='carousel-back page_b'>Backward</a>");
              gallery.after("<a class='carousel-forward page_b'>Forward</a>");

              gallery.jCarouselLite({
                btnNext: gallery.next(".carousel-forward.page_b"),
                btnPrev: gallery.prev(".carousel-back.page_b"),
                visible: 5
              });
            }
          });
      
      } else {
        
        // Carousel for Wide Slots (Gallery Only)
            $(".wide.gallery.widget .carousel").each(function(index, gallery) {
              gallery = $(gallery);
              if (gallery.find('li').length > 3) {
                gallery.before("<a class='carousel-back page_b'>Backward</a>");
                gallery.after("<a class='carousel-forward page_b'>Forward</a>");
                $('.component.gallery.widget .carousel-wrap').css("width","332px");
                $('.component.gallery.widget .carousel-wrap').css("padding","0 64px");    

                gallery.jCarouselLite({
                  btnNext: gallery.next(".carousel-forward.page_b"),
                  btnPrev: gallery.prev(".carousel-back.page_b"),
                  visible: 3
                });
              }
            });


    }; // end of if

  
// Carousel for Wide Slots (Events Only)

$('.component.upcoming-events-list.wide ul li a').css("display","block");
$('.component.upcoming-events-list.wide ul li a').css("height","35px");

    $(".component.upcoming-events-list.wide .carousel").each(function(index, gallery) {
      gallery = $(gallery);
      if (gallery.find('li').length > 2) {
        gallery.before("<a class='carousel-back page_b'>Backward</a>");
        gallery.after("<a class='carousel-forward page_b'>Forward</a>");

        gallery.jCarouselLite({
          btnNext: gallery.next(".carousel-forward.page_b"),
          btnPrev: gallery.prev(".carousel-back.page_b"),
          visible: 2
        });
      }
    });
    
// Carousel for small Slots (Events Only)

if ( $('body').hasClass('events_list') || $('body').hasClass('event_page') ) {
  
  } else {
    
    $('.component.upcoming-events-list.small ul li a').css("display","block");
    $('.component.upcoming-events-list.small ul li a').css("height","35px");
    
  $(".component.upcoming-events-list.small.single .carousel").each(function(index, gallery) {
    gallery = $(gallery);
    if (gallery.find('li').length > 1) {
      gallery.before("<a class='carousel-back page_b'>Backward</a>");
      gallery.after("<a class='carousel-forward page_b'>Forward</a>");

      gallery.jCarouselLite({
        btnNext: gallery.next(".carousel-forward.page_b"),
        btnPrev: gallery.prev(".carousel-back.page_b"),
        visible: 1
      });
    }
  });
  
} // end if event page

if ( $('body').hasClass('events_list') || $('body').hasClass('event_page') ) {
  
  } else {
    
  $(".component.upcoming-events-list.small.double .carousel").each(function(index, gallery) {
    gallery = $(gallery);
    if (gallery.find('li').length > 2) {
      gallery.before("<a class='carousel-back page_b'>Backward</a>");
      gallery.after("<a class='carousel-forward page_b'>Forward</a>");

      gallery.jCarouselLite({
        btnNext: gallery.next(".carousel-forward.page_b"),
        btnPrev: gallery.prev(".carousel-back.page_b"),
        visible: 2
      });
    }
  });
  
} // end if event page









        
    

    //  Bits and Bobs

    $('#body a.lightbox, .gallery a.lightbox').prepend('<span class="magnify" title="Click to view Full Size"></span>');
    $('#content #body .video a.lightboxVideo').prepend('<span class="play" title="Click to play the video"></span>');
    $("tbody tr:odd").css("background-color", "#0b0b08");
    $("blockquote p:last").addClass("last");
    $('#content #body ol li, #content #body ul li').wrapInner('<span></span>');
    $("#breadcrumbs li").css("white-space", "nowrap");    

  // Flash hero banner
  //----------------------------------
  // Create an Object that flash understands
  var definitions = $('#main_slot_0 dl dd');
  var definitionstitle = $('#main_slot_0 dl dt');

  $('#main_slot_0 dl dt').each(function(index,title){
    title = $(title);
    def = $(definitions[index]);
    defTitle = $(definitionstitle[index]);

    slide = {'thumb':title.find('img').first().attr('src'),
        'title':def.find('strong').first().text(),
        'link':defTitle.find('a').first().attr('href'),
        'target':defTitle.find('a').first().attr('target'),
        'strap':def.find('p').first().text(),
        'video_thumbnail':def.find('img').first().attr('src')
        };

    hero_panelContents.push(slide);
  });

  // add transition type to last entry of array - time is against me!
  hero_panelTransition = $('#main_slot_0 dl').hasClass('fancy');

  // Banner SWFObject
  var currentBodyId = $('body').attr('id');
  var outreachBodyClass = $('body').hasClass('outreach');

	
  var attributes = {};
  var flashvars = {
            bodyID:currentBodyId
          };

  var params =   {
            wmode:'transparent',
            id:'flash_banner',
            AllowScriptAccess: 'always',
            allowNetworking: 'all',
            allowFullScreen: 'true'
          };


	if(outreachBodyClass){
		swfobject.embedSWF(
		            "/flash/outreach_loader.swf",
		            "main_slot_0",
		            "100%",
		            "100%",
		            "9.0.0",
		            "/flash/expressInstall.swf",
		            flashvars,
		            params,
		            attributes
		            );
	}

  var currentHeroClass = $('#main_slot_0').attr('class');
  if(currentHeroClass == "component hero-panel" && !outreachBodyClass){
  swfobject.embedSWF(
            "/flash/rac_loader.swf",
            "main_slot_0",
            "100%",
            "100%",
            "9.0.0",
            "/flash/expressInstall.swf",
            flashvars,
            params,
            attributes
            );
  }


  // Virtual tour SWFObject
  var attributes = {};
  var flashvars = {};
  var params =   {wmode:'transparent'};

  swfobject.embedSWF(
            "/flash/virtual-tour/vt_loader.swf",
            "virtual-tour",
            "100%",
            "100%",
            "9.0.0",
            "/flash/expressInstall.swf",
            flashvars,
            params,
            attributes
            );


  $('#booking_referer').change(function(){
    element = $(this);
    booking_section = element.closest('form').find('#booking_referer_other_section');
    
    if(element.val() == 'Other'){
      booking_section.show();
    }else{
      booking_section.hide();
      booking_section.find('input#booking_referer_other').val('');
    }
  });
  $('#booking_referer').trigger('change');

}); // end of document dom ready event

// Called from Flash to retreive above Object
function sendDiv () {
  return hero_panelContents;
}

function sendTransition () {
  return hero_panelTransition;
}




var fadeout_timeout;
var fadein_timeout;
$(document).ready(function(){
  
  $('#nav-node-tree-root > li, #footer-nav-node-tree-root > li').each(function(index) {
      if($(this).children().size() == 2) {
        
        $(this).hoverIntent({
          over: fadeIn,
          timeout: 0,
          out: fadeOut
        });
        
      }  // close if
    }); // close each
    
 
    // Breadcrumbs
    jQuery("#breadCrumb0").jBreadCrumb();
       
}); // close document.ready
  
  
    function fadeIn(){
      if(fadeout_timeout != null)
        clearTimeout(fadeout_timeout);
      
      fadein_timeout= setTimeout(function(){ $('div.overlay').css({'display':'block'}).fadeTo(200,0.8); }, 50);
    };

    function fadeOut(){
      if(fadein_timeout != null)
        clearTimeout(fadein_timeout);

      fadeout_timeout= setTimeout(function(){ $('div.overlay').fadeTo(200, 0, function(){
        $(this).css({'opacity':0});
        $(this).css({'display':'none'});
      }); }, 200);
    }
