$(document).ready(function() {
	var aanTimer;
	var aanImg;
	var aanList = $(".aangenaam-list li");
	aanImg = $("#aangenaamimg");
	$(".aangenaam-list li").click(function() {
		if($(this).hasClass("active")) {
			return;
		} else {
			clearInterval(aanTimer);
			$(".aangenaam-list li").removeClass("active");
			p = $(this).position();
			
			aanImg.animate({"top": (p.top + 15)}, 500, function() {
				if($(this).index() <= aanList.length-1) {
					loopert();
				}
			});
			$(this).addClass("active");
			
			
			$("#theimagecontainer").cycle($(this).index());
		}
	});
	$("#theimagecontainer").cycle({
		fx: "cover,fade,scrollDown,fadeZoom,growX,scrollLeft,turnLeft,scrollUp,shuffle,slideX,toss,scrollRight,turnUp,growY,turnDown,slideY,turnRight,uncover,wipe,zoom"
	,	timeout:0
	});
	
	if($("#pic-show").length > 0) {
		$("#pic-show").cycle({fx: "cover,fade,scrollDown,fadeZoom,growX,scrollLeft,turnLeft,scrollUp,shuffle,slideX,toss,scrollRight,turnUp,growY,turnDown,slideY,turnRight,uncover,wipe,zoom",timeout:0});
		var maxPic = $(".pic-text").length;
		
		var curPic = 0;
		setInterval(function() {
			$(".pic-text").eq(curPic).fadeOut(800);
			curPic++;
			if(curPic == maxPic) {
				curPic = 0;
			}

			$(".pic-text").eq(curPic).fadeIn(800);
			$("#pic-show").cycle(curPic);
		}, 5000);
	}
	
	function loopert() {
		clearInterval(aanTimer);
		c = $(".aangenaam-list li.active").index();
		var nextItem = c + 1;
		
		if(nextItem < $(".aangenaam-list li").length) {
			p = $(".aangenaam-list li").eq(nextItem).position();
			var maxTop = p.top+15;
			aanTimer = setInterval(function() {
				t = aanImg.css("top");
				t = parseInt(t) + 1;
				if(t > maxTop) {
					t = maxTop;
					$(".aangenaam-list li").eq(nextItem).click();
				}
				aanImg.css("top", t);
			}, 49);
		}
		
	}
	
	loopert();
	
});
