function carousel_itemVisibleInCallback(carousel, item, i, state, evt) {
	var idx = carousel.index(i, carousel_itemList.length);
	carousel.add(i, carousel_getItemHTML(carousel_itemList[idx - 1]));
}

function carousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
	carousel.remove(i);
}

function carousel_getItemHTML(item) {
	video = "";
	if(item.video) {
		video = '<img src="images/teaser/teaser_thumb_playermask.png" class="teaservideomask" />';
	}
	return '<div class="scrollerteaser">'+video+'<img src="'+item.url+'" /><b>'+item.title+'</b>'+item.subtitle+'</div>';
}

var active1 = 0;
var active2 = 0;
var active3 = 0;
var stprev = 0;
function current_active(carousel, item, i, state, evt) {
	var max = carousel_itemList.length;
	if(state == "init") {
		if(active1 == 0) {
			active1 = i;
		} else {
			if(active2 == 0) {
				active2 = i;
			} else {
				if(active3 == 0) {
					active3 = i;
				}
			}
		}
	}
	if(state == "next") {
		active1 = active1 + 1;
		active2 = active2 + 1; // Mitte
		active3 = active3 + 1;
		if(active1 > max) { active1 = 1; }
		if(active2 > max) { active2 = 1; }
		if(active3 > max) { active3 = 1; }
	}
	if(state == "prev") {
		active1 = active1 - 1;
		active2 = active2 - 1; // Mitte
		active3 = active3 - 1;
		if(active1 < 1) { active1 = max; }
		if(active2 < 1) { active2 = max; }
		if(active3 < 1) { active3 = max; }
	}

	if(active1 > 0 && active2 > 0 && active3 > 0) {
		if(stprev != 0) { $("#teaserimg"+stprev).fadeTo(750, 0).css("z-index", "10"); }
		$("#teaserimg"+active2).fadeTo(500, 1, function() { $(this).css("filter", ""); }).css("z-index", "100");
		//Cufon.replace('.scrollerteaser b');
		stprev = active2;
	}
}

function carousel_initCallback(carousel) {
	jQuery('.jcarousel-list li').live('click', function() {
		carousel.scroll(jQuery(this).attr('jcarouselindex')-1);
		carousel.startAuto(0);
		return false;
	});

	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});
}

function initTeaser(carousel, teaser) {
	jQuery("#"+carousel).jcarousel({
		// Changed from 8 to 0 to stop the auto advance - KN 07/15/2011
		auto: 6,
		wrap: 'circular',
		scroll: 1,
		initCallback: carousel_initCallback,
		itemVisibleInCallback: {
			onBeforeAnimation: carousel_itemVisibleInCallback,
			onAfterAnimation: current_active
		},
		itemVisibleOutCallback: {onAfterAnimation: carousel_itemVisibleOutCallback}
	});
	// Teaser
	$("#"+teaser+" > div").each(function(i) {
		if(i == 1) { // Zweites Bild!
			$(this).attr("id", "teaserimg"+(i+1)).css("z-index", "100");
		} else {
			$(this).attr("id", "teaserimg"+(i+1)).fadeTo(1, 0).show().css("z-index", "10");
		}
	});
	$("#"+teaser+" > div > h1").each(function() {
		pos = "lines"+($("br", $(this)).size()+1);
		$(this).html("<span>"+($(this).html().replace(/<br>/gi, "</span><br /><span>"))+"</span>").addClass(pos);
	});
	$("#"+teaser+" > div > p").each(function() {
		$(this).html("<span>"+($(this).html().replace(/<br>/gi, "</span><br /><span>"))+"</span>");
	});
}

function initTeaser_noslide(teaser) {
	$("#"+teaser+" h1").each(function() {
		pos = "lines"+($("br", $(this)).size()+1);
//		$(this).html("<span>"+($(this).html().replace(/<br>/gi, "</span><br /><span>"))+"</span>").addClass(pos);
		$(this).addClass(pos);
	});
}



