// JavaScript Document
var pagepfad = "http://aufwind.steaff.de";

$(document).ready(function() {
	$("body").ready(function() {
		animate(-1);
	});
	
	$("#teaser1").mouseenter(function() {
		enterTeaser("#teaser1");
		$("#link1").css("text-decoration", "underline");
	});
	$("#teaser1").mouseleave(function() {
		leaveTeaser("#teaser1");
		$("#link1").css("text-decoration", "none");
	});
	$("#teaser2").mouseenter(function() {
		enterTeaser("#teaser2");
		$("#link2").css("text-decoration", "underline");
	});
	$("#teaser2").mouseleave(function() {
		leaveTeaser("#teaser2");
		$("#link2").css("text-decoration", "none");
	});
	$("#teaser3").mouseenter(function() {
		enterTeaser("#teaser3");
		$("#link3").css("text-decoration", "underline");
	});
	$("#teaser3").mouseleave(function() {
		leaveTeaser("#teaser3");
		$("#link3").css("text-decoration", "none");
	});
	$("#teaser4").mouseenter(function() {
		enterTeaser("#teaser4");
		$("#link4").css("text-decoration", "underline");
	});
	$("#teaser4").mouseleave(function() {
		leaveTeaser("#teaser4");
		$("#link4").css("text-decoration", "none");
	});
});

function enterTeaser(id) {
		$(id + " > .smallTeaserContent").css("background-image", "none");
		$(id + " > .smallTeaserTop").css("background-image", "none");
		$(id + " > .smallTeaserBottom").css("background-image", "none");
		$(id + " > .smallTeaserContent").css("background-image", "url(ressourcen/images/content/index/indexTeaserBGhover.png)");
		$(id + " > .smallTeaserTop").css("background-image", "url(ressourcen/images/content/index/indexTeaserTophover.png)");
		$(id + " > .smallTeaserBottom").css("background-image", "url(ressourcen/images/content/index/indexTeaserBottomhover.png)");
}

function leaveTeaser(id) {
		$(id + " > .smallTeaserContent").css("background-image", "none");
		$(id + " > .smallTeaserTop").css("background-image", "none");
		$(id + " > .smallTeaserBottom").css("background-image", "none");
		$(id + " > .smallTeaserContent").css("background-image", "url(ressourcen/images/content/index/indexTeaserBG.png)");
		$(id + " > .smallTeaserTop").css("background-image", "url(ressourcen/images/content/index/indexTeaserTop.png)");
		$(id + " > .smallTeaserBottom").css("background-image", "url(ressourcen/images/content/index/indexTeaserBottom.png)");
}


//Animation
$(document).ready(function() {
	$("body").ready(function() {
		$("#mainTeaserBackground").mouseenter( function() {
			clearTimeout(timeout);
			runAnimation = 0;
		});
		$("#mainTeaserBackground").mouseleave( function() {
			i = status + 1;
			if (i > 2) {
				i = 0;
			}
			timeout = setTimeout("animate(" + i + ")", 1000);
			runAnimation = 1;
		});
		$("#statusCircle1").mouseenter(function() {
			clearTimeout(timeout);
			runAnimation = 0;
			if (status != 0) {
				animateSlide(0)
			}
			status = 0;
		});
		$("#statusCircle2").mouseenter(function() {
			clearTimeout(timeout);
			runAnimation = 0;
			if (status != 1) {
				animateSlide(1)
			}
			status = 1;
		});
		$("#statusCircle3").mouseenter(function() {
			clearTimeout(timeout);
			runAnimation = 0;
			if (status != 2) {
				animateSlide(2)
			}
			status = 2;
		});
		/*$("#statusCircle1").mouseleave(function() {
			timeout = setTimeout("animate(1)", 1000);
			runAnimation = 1;
		});
		$("#statusCircle2").mouseleave(function() {
			timeout = setTimeout("animate(2)", 1000);
			runAnimation = 1;
		});
		$("#statusCircle3").mouseleave(function() {
			timeout = setTimeout("animate(0)", 1000);
			runAnimation = 1;
		});*/
	});
});

var runAnimation = 1;
var timeout;
var status = 0;
var gettolast = 0;

function animate(i) {
	if (i <= -1) {
		//$("#mainTeaserBackgroundtemp").css("background-image", "url(ressourcen/images/content/index/animation/headline1_img.jpg)");
		$("#mainTeaserBackground").css("background-image", "url(ressourcen/images/content/index/animation/background.jpg)");
		$("#mainTeaserBackground").css("background-position", "-962px");
		$("#statusCircle1").css("background-image", "url(ressourcen/images/content/index/teaserkreisaktive.png)");
		status = 0;
		i = 1;
	} else {
		animateSlide(i);
		status = i;
		i++;
		if (i > 2) {
			i = 0;
		}
	}
	if (runAnimation == 1) {
		timeout = setTimeout("animate(" + i + ")", 5000);
	}
}

function animateSlide(i) {
	if (i == 0) {
		$("#indexMainTeaserLink").attr("href", "index.php?action=mission")
		if (gettolast == 0 || status == 1) {
			$("#mainTeaserBackground").animate({backgroundPosition: "-962px"}, 1000);
		} else {
			$("#mainTeaserBackground").animate({backgroundPosition: "-3848px"}, 1000, 
				function() {
					$("#mainTeaserBackground").css("background-position", "-962px");
				});
		}
	} else if (i == 1) {
		$("#indexMainTeaserLink").attr("href", "index.php?action=projekte")
		$("#mainTeaserBackground").animate({backgroundPosition: "-1924px"}, 1000);
	} else if (i == 2) {
		$("#indexMainTeaserLink").attr("href", "index.php?action=gemeinsamAktiv")
		if (status == 1) {
			$("#mainTeaserBackground").animate({backgroundPosition: "-2886px"}, 1000);
		} else if (status == 0) {
			$("#mainTeaserBackground").animate({backgroundPosition: "0px"}, 1000, 
			function() {
				$("#mainTeaserBackground").css("background-position", "-2886px");
			});
		}
		gettolast=1;
	}
		y = i + 1;
		var bildpfad = "url(ressourcen/images/content/index/animation/headline" + y + "_img.jpg)";
		/*$("#mainTeaserBackground").stop();
		$("#mainTeaserBackgroundtemp").stop();
		$("#mainTeaserBackgroundtemp").css("background-position", "0px 0px");
		$("#mainTeaserBackground").css("background-position", "960px 0px");
		$("#mainTeaserBackground").animate({backgroundPosition: "-=960px"}, 1000, 
			function() {$("#mainTeaserBackgroundtemp").css("background-image", bildpfad);});
		$("#mainTeaserBackgroundtemp").animate({backgroundPosition: "-=960px"}, 1000);
		
		$("#mainTeaserBackground").css("background-image", bildpfad);*/
		for(var j = 1; j <= 3; j++) {
			$("#statusCircle" + j).css("background-image", "url(ressourcen/images/content/index/teaserkreisinaktive.png)");
		}
		$("#statusCircle" + y).css("background-image", "url(ressourcen/images/content/index/teaserkreisaktive.png)");
}
