$(document).ready(function() {
	
  jQuery('#associate-sponsors').jcarousel({
	        auto: 0,
	        scroll: 1
   });

  if ($('#news').length>0) {   
     jQuery('#news-thumb').jcarousel({
	        auto: 8,
	        scroll: 1,
	        wrap: 'circular',
	        initCallback: mycarousel_initCallback,
	        itemFirstOutCallback: mycarousel_itemFirstOutCallback,
	        itemFirstInCallback:  mycarousel_itemFirstInCallback
	    });
	
   }

   if ($('#garage').length>0) {   
     jQuery('#garage-thumbs ul').jcarousel({
	        auto: 0,
	        scroll: 1
	    });
	
	$("#garage-slideshow").tabs();

   }


   if ($('.driver-tabs').length>0) {   
      $(".driver-tabs").tabs().tabs("rotate", 4000, true);
   }

   $('#news-thumb a').click(function() { 
	 $('.news').removeClass('newactive');
     var newsid= $(this).attr("href");
     $(newsid).addClass('newactive');
   
  });

  
	var timer1 = new Date("January 28, 2011 01:15:00");
	var timer2 = new Date("February 19, 2011 12:00:00");
	
	
	$('#countdown1').countdown({until: timer1, compact: true, format: 'DHMS',
	    description: ''});
	
	$('#countdown2').countdown({until: timer2, compact: true, format: 'DHMS',
		    description: ''});
   
   if (screen.width<=1305)  { $('body').removeClass('.over'); } else  {$('body').addClass('.over');}

	//CUFON

	Cufon.replace('ul#main-nav li span', {	hover: true	});
	Cufon('a.t', {hover: {color: '#FFFFFF'}});
	//Cufon.replace('.dropdown li', {hover: true,fontFamily: 'Swiss911 XCm BT'});
	Cufon.replace('#news h2'); 
	Cufon.replace('#categories h2'); 
	Cufon.replace('#categories a.link'); 
	Cufon.replace('#series .details .num', { fontFamily: 'Swiss911 XCm BT' }); 
	Cufon.replace('#events h3', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('#series h3.event-name', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('#categories a.link', { hover: {color: '#FFFFFF'} });
	Cufon.replace('#categories span.link', { hover: {color: '#FFFFFF'} });
	Cufon.replace('#events .countdown span', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('#events .countdown .date em'); 
	Cufon.replace('.test', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('#events .time em', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('#events ul.links-events a'); 
	Cufon.replace('#modules h4');
	
	
	Cufon.replace('#single-post h1');
	Cufon.replace('#single-post h2');
	Cufon.replace('a.button', {	hover: true	});
	Cufon('a.button', {hover: {color: '#CBCCCE'}});
	Cufon.replace('#single-post h2 a', {	hover: true	});
	Cufon('#single-post h2 a', {hover: {color: '#CBCCCE'}});
	Cufon.replace('#single-post .date');
	Cufon.replace('.page-nav a');
	Cufon.replace('.address p');
	Cufon.replace('ul.links li a', {	hover: true	});
	Cufon('ul.links li a', {hover: {color: '#CBCCCE'}});
	Cufon.replace('ul.links li span', {	hover: true	});
	Cufon('ul.links li span', {hover: {color: '#CBCCCE'}});
	Cufon.replace('#garage h2', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('#driver-details h2', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('#driver-details h3');
	Cufon.replace('ul.list-ourdrivers li h2', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('table.table-eventschedule tr th');
	Cufon.replace('.eventdate span', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('.eventdate em');
	Cufon.replace('table.table-eventschedule .track');
	Cufon.replace('table.table-eventschedule td.col-driver', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('table.table-eventschedule .col-start', { fontFamily: 'Swiss911 XCm BT' });
	Cufon.replace('table.table-eventschedule .col-finish', { fontFamily: 'Swiss911 XCm BT' });

  $('.news-details p').condense({
              condensedLength: 140,
              moreText: '',
              lessText: '',
              ellipsis: " ..."
              });

});

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        //carousel.startAuto();
    });
};


function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
 	 var newsid;
      newsid = $(item).contents('a').attr('href');
     $(newsid).removeClass('active');
};


function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
  	 var newsid;
      newsid = $(item).contents('a').attr('href');
      
     $(newsid).addClass('active');
};

/* Main Navigation hover for IE6 
-------------------------------------*/
sfHover = function() {
var sfEls = document.getElementById("main-nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


