function mycarousel_initCallback(carousel) {
	// Disable autoscrolling if the user clicks the prev or next button.
	 $('#carousel-next').bind('click', function() {
		carousel.startAuto(0);
		carousel.next();
		carousel.startAuto(8);
		return false;
	});

	 $('#carousel-prev').bind('click', function() {
		carousel.startAuto(0);
		carousel.prev();
		carousel.startAuto(8);
		return false;
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover( function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

function mycarousel_firstInCallback(carousel, li, index, x) {
	var t = $('#teaser-' + index);
	t.addClass('active', 1000);
	var texts = t.attr('title').split(' | ');
	$('#teaser-box-title').html(texts[0]);
	$('#teaser-box-description').html(
			texts[1].replace(/\\n/, '<br />'));
}

function mycarousel_firstOutCallback(carousel, li, index, x) {
	var t = $('#teaser-' + index);
	t.removeClass('active');
}



jQuery(document).ready( function() {
	jQuery('#teaser-box-carousel').jcarousel( {
		scroll:1,
		buttonNextHTML : null,
		buttonPrevHTML : null,
		auto: 8,
		wrap :'both',
		initCallback :mycarousel_initCallback,
		itemFirstInCallback :mycarousel_firstInCallback,
		itemFirstOutCallback :mycarousel_firstOutCallback

	});
});

