var timer1;
var top1 = 35;
var animation1Active = 0;

var timer2;
var top2 = 24;
var animation2Active = 0;

$(document).ready(function() {
	// VACATURES
	$("div.vacatures div.item:first").addClass("active");
	
	$("div.vacatures div.item").each(function( intIndex ){
		$(this).click(function() {
			document.location = $(this).find("h3 a").attr("href");
		}).css("top", top1);
		
		top1 += (intIndex == 0 ? $(this).height() : 25);
	});
	$("div.vacatures").height(top1-17);
	
	
	$("div.vacatures div.item").mouseover(function() {
		if (animation1Active == 0 && $(this).hasClass("active") == false) {
			old_active_index = $("div.vacatures div.item").index($("div.vacatures div.item.active")[0]);
			new_active_index = $("div.vacatures div.item").index(this);
			what = $(this);
			timer1 = setTimeout("showVacature(what)", 250);
		}
	}).mouseout(function() {
		clearTimeout(timer1);
	});
	
	
	// NIEUWS
	$("div.nieuws div.item:first").addClass("active");
	
	$("div.nieuws div.item").each(function( intIndex ){
		$(this).click(function() {
			document.location = $(this).find("h3 a").attr("href");
		}).css("top", top2);
		
		top2 += (intIndex == 0 ? $(this).height() : 25);
	});
	$("div.nieuws").height(top2);
	
	$("div.nieuws div.item").mouseover(function() {
		if (animation2Active == 0 && $(this).hasClass("active") == false) {
			old_active_nieuws_index = $("div.nieuws div.item").index($("div.nieuws div.item.active")[0]);
			new_active_nieuws_index = $("div.nieuws div.item").index(this);
			what = $(this);
			timer2 = setTimeout("showNieuws(what)", 250);
		}
	}).mouseout(function() {
		clearTimeout(timer2);
	});
	
});

function showVacature(obj) {
	clearTimeout(timer1);
	
	$("div.vacatures div.item.active").removeClass("active");
	$(obj).addClass("active");

	if (new_active_index > old_active_index) {
		start		= old_active_index+1;
		end			= new_active_index;
		direction	= "up";
	} else {
		start		= new_active_index+1;
		end			= old_active_index;
		direction	= "down";
	}
	
	for (i=start; i<=end; i++) {
		var obj = $("div.vacatures div.item").eq(i);
		
		newTop = parseInt(obj.css("top")) + (direction == "up" ? -155 : 155);
	
		animation1Active += 1;
		$(obj).animate({ top: newTop },500, 'easeOutCubic', function() {
			animation1Active -= 1;
		});
	}
}

function showNieuws(obj) {
	clearTimeout(timer2);

	$("div.nieuws div.item.active").removeClass("active");
	$(obj).addClass("active");

	if (new_active_nieuws_index > old_active_nieuws_index) {
		start		= old_active_nieuws_index+1;
		end			= new_active_nieuws_index;
		direction	= "up";
	} else {
		start		= new_active_nieuws_index+1;
		end			= old_active_nieuws_index;
		direction	= "down";
	}
	
	for (i=start; i<=end; i++) {
		var obj = $("div.nieuws div.item").eq(i);

		newTop = parseInt(obj.css("top")) + (direction == "up" ? -55 : 55);
		
		animation2Active += 1;
		$(obj).animate({ top: newTop },400, 'easeOutCubic', function() {
			animation2Active -= 1;
		});
	}
}
