var animation,teaserTotalCount;

var step = 800;

var counter = 0;

function leftClickHandler(){
	window.clearInterval(keepMoving);
	moveLeft();
}

function rightClickHandler(){
	window.clearInterval(keepMoving);
	moveRight();
}


function createAnimation(){
	animation = new Fx.Tween($('carousel'), {duration: 800});
}



var teaser = {};

function initTeaser(){
	
	for(var i = 0;i<teaserTotalCount;i++){
		if($('teaser_' + i))teaser[i] = $('teaser_' + i).innerHTML;
	}
	$('teaser_1').innerHTML = teaser[0];
	$('carousel').style.marginLeft = '-800px';
}


var currentTeaser = 0;

var isStart = true;

function moveLeft(){
	if(isStart)initTeaser();
	nextTeaser = getNextTeaser('left');
	$('teaser_1').innerHTML = teaser[currentTeaser];
	$('teaser_2').innerHTML = teaser[nextTeaser];
	$('carousel').style.marginLeft = '-800px';
	animation.start('margin-left',-1600);
	currentTeaser = nextTeaser;
	isStart = false;
}

function moveRight(){
	if(isStart)initTeaser();
	nextTeaser = getNextTeaser('right');
	$('teaser_1').innerHTML = teaser[currentTeaser];
	$('teaser_0').innerHTML = teaser[nextTeaser];
	$('carousel').style.marginLeft = '-800px';
	animation.start('margin-left',0);
	currentTeaser = nextTeaser;
	isStart = false;
}

function getNextTeaser(dir){
	if(dir == 'left'){
		nextTeaser = currentTeaser + 1;
		if(nextTeaser == teaserTotalCount)nextTeaser = 0;
	}
	else{
		nextTeaser = currentTeaser - 1;
		if(nextTeaser < 0)nextTeaser = teaserTotalCount - 1;
	}
	return nextTeaser;
}

