// Setup carousel controls
var spotlightCarousel;
function spotlight_carousel_initCallback(carousel) {
	spotlightCarousel = carousel;
	jQuery('.spotlight-tabs ul li').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        carousel.startAuto(0);
		return false;
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	jQuery('#wimgo-spotlight').hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

// Highlight active nav item
function highlight(carousel, obejctli,liindex,listate){
	jQuery('.spotlight-tabs ul li:nth-child('+ liindex +')').addClass("selected");
};
function removehighlight(carousel, obejctli,liindex,listate){
	jQuery('.spotlight-tabs ul li:nth-child('+ liindex +')').removeClass("selected");
};

// Make youtube player talk to jcarousel
function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
	ytplayer.addEventListener("onStateChange", "ytStatus");
};

function ytStatus(newState) {
	if (newState == "1") { spotlightCarousel.startAuto(0); } // Playing
	else if (newState == "2") { spotlightCarousel.startAuto(10); } // Paused
	else if (newState == "0") { spotlightCarousel.startAuto(10); } // End
};


// Ride the carousel...
jQuery(document).ready(function() {
	jQuery('#spotlight-carousel').jcarousel({
		vertical: true,
		auto: 10,
		scroll: 1,
		wrap: 'last',
		initCallback: spotlight_carousel_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		itemVisibleInCallback: {onBeforeAnimation: highlight},
		itemVisibleOutCallback: {onBeforeAnimation: removehighlight}
	});
	$('.spotlight-tabs ul li:last-child').addClass('last');
});

