var timer;
var timer_pauze	= 2000;
var sub_start	= 7;
var sub_end		= 159;

$(document).ready(function() {
	$("#nav").after("<div class=\"subs\"><ul></ul></div>");
	
	// is er een active sub nodig?
	setActiveSubs();
	
	$("#nav > li").each(function( intIndex ){
		$(this).mouseover(function() {
			clearTimeout(timer);
			var parent_obj = $(this);
			
			if ($("#navigatie div.subs ul").html() != parent_obj.find("ul").html()) {
				$("#navigatie div.subs ul").stop().animate( {left: sub_start}, 150, function( intIndex ){
						   
					$(this).attr("class", parent_obj.find("ul").attr("id")).html(parent_obj.find("ul").html());
					setTopPositionSubs(parent_obj);
					$(this).animate( {left: sub_end}, 150);
				});
			}
			
		}).mouseout(function() {
			timer = setTimeout("setActiveSubs()", timer_pauze);					  
		});
	});
	
	$("#navigatie div.subs ul").mouseover(function() {
		clearTimeout(timer);					   
	}).mouseout(function() {
		timer = setTimeout("setActiveSubs()", timer_pauze);						  
	});
});

function setTopPositionSubs(active_obj) {
	var offset_nav	= $("#navigatie").offset();
	var offset_obj	= active_obj.offset();
	var new_top		= offset_obj.top - offset_nav.top-1;
	
	overlap = (offset_obj.top + $("#navigatie div.subs ul").height() + 7) - (offset_nav.top + $("#navigatie").height()-7);

	if(overlap > 0) {
		$("#navigatie div.subs ul").css("top", new_top-overlap-1);
	} else {
		$("#navigatie div.subs ul").css("top", new_top);
	}
	
}

function setActiveSubs() {
	if ($("#nav > li.active").size() > 0) {
		$("#navigatie div.subs ul").stop().animate( {left: sub_start}, 150, function( intIndex ){		   
			$(this).attr("class", $("#nav li.active ul").attr("id")).html($("#nav li.active ul").html());
			setTopPositionSubs($("#nav > li.active"));
			$(this).animate( {left: sub_end}, 150);
		});
	} else {
		$("#navigatie div.subs ul").stop().animate( {left: sub_start}, 150);
	}
}


function showOpleiding() {
	$("#inschrijving").hide();
	$("#overoog").hide();
	$("#managementlogin").hide();
	$("#opleiding").toggle();
}

function showManagement() {
	$("#inschrijving").hide();
	$("#overoog").hide();
	$("#managementlogin").toggle();
	$("#opleiding").hide();
}

function showOverOog() {
	$("#inschrijving").hide();
	$("#overoog").toggle();
	$("#managementlogin").hide();
	$("#opleiding").hide();
}

function showInschrijving() {
	$("#inschrijving").toggle();
	$("#overoog").hide();
	$("#managementlogin").hide();
	$("#opleiding").hide();
}
