$(document).ready(function(){
	
	var activeSlideIndex = 0;
	$('#carouselNav a:eq('+ activeSlideIndex +')').addClass('active');
	
	$('#carousel').easyAccordion({ 
	   autoStart: true,
	   slideInterval: 5000,
	   slideNum: false
	}).bind("slideChanged", function(){
		activeSlideIndex = ($(this).findActiveSlide()) - 1;
		updateNav();
	});	

	$('#carouselNav a').click(function(){
		//find the navIndex of the clicked nav button
		var navIndex = $('#carouselNav a').index(this);
		if(navIndex !== activeSlideIndex){
			updateNav();
			$('#carousel dt:eq('+ navIndex +')').trigger('click');
		}else{
			//do nothing
		}
	});

	function updateNav(){
		$('#carouselNav').find('.active').removeClass('active');
		$('#carouselNav a:eq('+ activeSlideIndex +')').addClass('active');
	}

	//add 'selected' class to parent of selected subnav
	$('ul.subnav li.selected').each(function(){
		$(this).parent().parent().addClass('selected');
		
		//set right column image
		var link = $(this).find('a').attr('href');
		var newValue = link.replace('.html','');
		$('#rc-bg').addClass(newValue);
	});
	
	
	//Hover Intent
	var hoverConfig = {
     	over: subNavOn, // function = onMouseOver callback (REQUIRED)    
     	timeout: 400, // number = milliseconds delay before onMouseOut    
     	out: subNavOff // function = onMouseOut callback (REQUIRED)  	
	}
	$('#top-nav li').hoverIntent(hoverConfig);	

	function subNavOn(){
		$(this).find('.subnav').fadeIn(200);
	}
	function subNavOff(){
		$(this).find('.subnav').fadeOut(50);
	}
	
	// embeds media in the following regions
	$("#video").acsMediaEmbed({videoWidth:'234px', videoHeight:'156px', carriageReturn:false });
	
});

