  function sidebar_change(num,h3,caption) {
	$('#sidebar_thumb').attr('src','/images/sidebar_expand/'+num+'_thumb.jpg');
	if (!$('#sidebar-image').hasClass("on")) {
		$('#sidebar_expanded').attr('src', '/images/sidebar_expand/'+num+'.jpg');
		$('#sidebar_thumb').attr('alt', num);
		$('#sidebar_info_h3').html(h3);
		$('#sidebar_info_p').html(caption);
	}
  }
  

$(document).ready(function() {
   jQuery.event.add(window, "load", resizeFrame);
   jQuery.event.add(window, "resize", resizeFrame);

 
    //Cufon
    Cufon.replace('#slideshow h2');
	Cufon.replace('#recent-news h3');
	Cufon.replace('#sidebar-image .info h3');
	Cufon.replace('ul.tabs-multimedia li a', {hover:true});
	Cufon.replace('a.link-archive', {hover:true});
    Cufon.replace('.title');
	Cufon.replace('#header-events h2', { fontFamily: 'TitilliumText14L' });
	Cufon.replace('#logo ul li');
	Cufon.replace('ul#main-nav li a', {hover:true,textShadow: ' #000 1px 1px'});
	Cufon.replace('#title h2');
	Cufon.replace('#title h3');
	Cufon.replace('#title-sub h4');
    Cufon.replace('#intro h3');
	Cufon.replace('#twitter h4 span');
	Cufon.replace('ul.list-connect li  span');
	Cufon.replace('p.view-all a', {hover:true});
	Cufon.replace('ul.list-news h3 a', {hover:true});
    Cufon.replace('h3.news-sub', { fontFamily: 'TitilliumText14L' });
	Cufon.replace('p.date', { fontFamily: 'TitilliumText14L' });


	//color schedule rows
	$('.table-schedules tr.expandable').hover(function(){$(this).addClass('red');}, function(){$(this).removeClass('red');});
	
   //expand logo
  $('a#link-drivers').click(function() {
    $('#list-drivers').slideToggle('slow', function() { });
	$(this).toggleClass("deactivate");
  });
  
     //expand image
  $('#sidebar-image img, #sidebar-image a').click(function() {
	$(this).parent().parent().toggleClass("on");
  });
  
   if ($('#header-events .wrapper').length > 0) {
   	$('#header-events .wrapper').after('<div id="dot-events" class="dots clearfix">').cycle({
   		fx: 'none',
   		speed: 500,
   		timeout: 5000,
   		pager: '#dot-events',
   		cleartypeNoBg: true
   	});
   }
   
if ($('#twitter ul').length > 0) {
	$('#twitter ul').after('<div id="dot-twitter" class="dots-dark clearfix">').cycle({
		fx: 'none',
		speed: 500,
		timeout: 3500,
		pager: '#dot-twitter',
		cleartypeNoBg: true
	});
}
  
/*
  if ($('#twitter').length>0) { 
   
      $(function(){
	      $("#twitter").tweet({
	        join_text: "auto",
	        username: ["rcrracing"],
	        avatar_size: 48,
	        count: 5,
			refresh_interval: 10,
	        loading_text: "loading tweets..."
	    });
  	});	
	
  }
  
  */
  
  if ($('#video-photos').length>0) { 
   
   	$('#video-photos .video-wrapper').after('<div id="dot-videos" class="dots clearfix">').cycle({
	        fx:     'none',
	        speed:  500,
	        timeout: 0,
	        pager:  '#dot-videos',
			cleartypeNoBg:true
	 });
	 
	 $('#video-photos .photo-wrapper').after('<div id="dot-photos" class="dots clearfix">').cycle({
	        fx:     'none',
	        speed:  500,
	        timeout: 0,
	        pager:  '#dot-photos',
			cleartypeNoBg:true
	 });
	
  }
  
  if ($('#multimedia-video').length>0) { 
   
   	$('#more-videos ul').after('<div id="dot-videos" class="dots clearfix">').cycle({
	        fx:     'none',
	        speed:  500,
	        timeout: 7000,
	        pager:  '#dot-videos',
			cleartypeNoBg:true
	 });
	 
	$('#multimedia-photos ul').after('<div id="dot-gallery" class="dots clearfix">').cycle({
	        fx:     'none',
	        speed:  500,
	        timeout: 0,
	        pager:  '#dot-gallery',
			cleartypeNoBg:true
	 });
	 
  }
  

	if ($('#list-sponsors')) {
		jQuery('#list-sponsors').jcarousel({
			auto: 2,
			wrap: 'circular',
			scroll: 1
		});
	}

  if ($('#slideshow-wrapper').length > 0) {
	jQuery("#slideshow-wrapper").jcarousel({
		scroll: 1,
		initCallback: mycarousel_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
			buttonNextHTML: null,
			buttonPrevHTML: null,
			itemFirstInCallback: mycarousel_itemFirstInCallback,
			itemFirstOutCallback: mycarousel_itemFirstOutCallback,
			auto: 4,
			wrap: 'both'
		
		});
	}
  


  
  // lightbox for photos in gallery
   $("ul.list-photo-thumb a").fancybox();
   
  
 // lightbox for video 
  $(".zoom").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

}); //close $(document).ready()

//onload and resize
function resizeFrame() 
{
    var x = $(window).width();
  if (x < 1020){
    $("body").addClass("minwidth");

  } else{
    $('body').removeClass('minwidth');
  }
	
}

// callback for jcarouse -- slideshow
  function mycarousel_initCallback(carousel) {


    jQuery('#next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#prev').bind('click', function() {
        carousel.prev();
        return false;
    });
  };
  
  //remove / place shadow on active item
  function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
    $(item).addClass('active');
	Cufon.refresh();
  };

  
  function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
    $(item).removeClass('active');
  };







