var the_carousel;
var video_playing = false;
$(document).ready ( function() {
	$('.bloc-multinoticia ul.rotatiu').each(function(){
		$(this).jcarousel({
	        auto: 6,
			scroll: 1,
	        wrap: 'both',
			buttonNextHTML: null,
	        buttonPrevHTML: null,
	        initCallback: multinotis_initCallback,
			itemVisibleInCallback: {
				onAfterAnimation:  multinotis_itemVisibleInCallbackAfterAnimation
			}
	    });
	});
});
function multinotis_initCallback(carousel){
	the_carousel = carousel;
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		if (!video_playing) carousel.startAuto();
	});

	$('.multinotis-pager li a').click(function(e) {
		carousel.scroll($.jcarousel.intval($(this).text()));
		carousel.startAuto(0);
		return false;
	});

	$('.multinotis-pager .bt-prev').click(function(e) {
		carousel.prev();
		carousel.startAuto(0);
		return false;
	});
	$('.multinotis-pager .bt-next').click(function(e) {
		carousel.next();
		carousel.startAuto(0);
		return false;
	});
}
function multinotis_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
    $('.multinotis-pager li').each(function(i) {
		$(this).removeClass('current');
		if (i == (idx-1)) $(this).addClass('current');
	});
};

/* Communication between JS and AS */
function getFlashMovie(movieName) {
	return document.getElementById(movieName);
}
function commWithAS() {
	try {
		getFlashMovie('multinotisvp').doSomething();
	}catch (err){
		//alert(err);
	}
}
function videoStateChanged(as_param_str){
	switch (as_param_str){
		case 'playing':
			video_playing = true;
			the_carousel.stopAuto();
			break;
		case 'paused':
			video_playing = false;
			break;
		case 'stopped':
			video_playing = false;
			the_carousel.startAuto();
			break;
		default:
		
	}
	return true;
}
/* ------------------------------- */

