var lock = new Array(3);
var ProduktStartLast = new Array(3);
var AngebotsIntervall = new Array(3);
var goToNext;
var noClick = 1;


function startAngebote()
{
	lock['0'] = 0;
	changeAngebot('0');
	AngebotsIntervall[0] = window.setInterval("changeAngebot(0);", 5000);
	lock['1'] = 0;
	moveAngebot(ProductEnd[0],ProductEnd[1],1);
	window.setTimeout("changeAngebot('1');", 500);
	window.setTimeout("startSecondBox();", 500);
	
	lock['2'] = 0;
	moveAngebot(ProductEnd[1],ProductEnd[2],2);
	
	window.setTimeout("changeAngebot('2');", 1000);
	window.setTimeout("startThirdBox();", 1000);
	window.setTimeout("noClick = 0;", 1700);

}


function startAngeboteSmall()
{
	lock['0'] = 0;
	changeAngebot('0');
	AngebotsIntervall[0] = window.setInterval("changeAngebot(0);", 5000);
	lock['1'] = 0;
	moveAngebotSmall(ProductEnd[0],ProductEnd[1],1);
	window.setTimeout("changeAngebot('1');", 500);
	window.setTimeout("startSecondBox();", 500);
	
	lock['2'] = 0;
	moveAngebotSmall(ProductEnd[1],ProductEnd[2],2);
	
	window.setTimeout("changeAngebot('2');", 1000);
	window.setTimeout("startThirdBox();", 1000);
	window.setTimeout("noClick = 0;", 1700);

}


function startAngeboteRechts()
{
	lock['0'] = 0;
	changeAngebot('0');
	AngebotsIntervall[0] = window.setInterval("changeAngebot(0);", 5000);
	window.setTimeout("noClick = 0;", 1700);
}



function startSecondBox()
{
	AngebotsIntervall[1] = window.setInterval('changeAngebot(1);', 5000);
}

function startThirdBox()
{
	AngebotsIntervall[2] = window.setInterval('changeAngebot(2);', 5000);
}



function moveAngebot(start,end,id)
{
	for(i = start+1; i <= end;i++)
	{
		if(document.getElementById("angebotteaser"+i))
			document.getElementById("angebotteaser"+i).style.left = 200* id +"px";
	}
}

function moveAngebotSmall(start,end,id)
{
	for(i = start+1; i <= end;i++)
	{
		if(document.getElementById("angebotteaser"+i))
			document.getElementById("angebotteaser"+i).style.left = 136* id +"px";
	}
}

function restartAngebote(i)
{
	var Position;
	if  (i <= ProductEnd[0])
		Position = 0;
	else if (i <= ProductEnd[1])
		Position = 1;
	else Position = 2;

	lock[Position] = 0;
}



function stopAngebote(i)
{
	var Position;
	if  (i <= ProductEnd[0])
		Position = 0;
	else if (i <= ProductEnd[1])
		Position = 1;
	else Position = 2;

	
	lock[Position] = 1;
}


function changeAngebot(i)
{

	if (lock[i] != 1)
	{
		ProduktStartLast[i] = ProductStart[i] - 1
		ProductStart[i] += 1;
		if (ProductStart[i] > ProductEnd[i])
			ProductStart[i] = 1 + i*ProductCountPart;
		ProductStart2[i] = ProductStart[i] + 1;
		if (ProductStart2[i] > ProductEnd[i])
			ProductStart2[i] = 1 + i*ProductCountPart;
		
		loopAngebot(i, ProductStart2[i], ProductStart[i]);
	}
}


function loopAngebot(i,showid,hideid)
{

	$("#angebotteaser" + hideid).animate({
			opacity: 0
	}, 1000, function() {
		$("#angebotteaser" + hideid).css("display", "none");
	});

	$("#angebotteaser" + showid).css("display", "block");
	$("#angebotteaser" + showid).animate({
			opacity: 1
	}, 1000);
}


function moveNextSmall()
{

	if (noClick == 0)
	{
		noClick = 1;
		for (var i = 0; i <= 2; i++)
		{

			window.clearInterval(AngebotsIntervall[i]);

		}
		startAngeboteSmall();
		window.setTimeout("noClick = 0;", 1700);
	}

}

function moveNext()
{
	if (noClick == 0)
	{
		noClick = 1;
		for (var i = 0; i <= 2; i++)
		{

			window.clearInterval(AngebotsIntervall[i]);

		}
		startAngebote();
		window.setTimeout("noClick = 0;", 1700);
	}
}


function moveLast()
{
	if (noClick == 0)
	{
		noClick = 1;
		for (var i = 0; i <= 2; i++)
		{
			
			window.clearInterval(AngebotsIntervall[i]);
			loopAngebot(i,ProductStart[i],ProductStart2[i]);	
			ProductStart2[i] = ProductStart[i];
			

				if (ProductStart[i] == i*ProductCountPart + 1)
					ProductStart[i] = ProductEnd[i];
				else
					ProductStart[i] -=1;

		}

		AngebotsIntervall[0] = window.setInterval("changeAngebot(0);", 5000);
		window.setTimeout("startSecondBox();", 500);
		window.setTimeout("startThirdBox();", 1000);
		window.setTimeout("noClick = 0;", 1000);
	}
}


