$(document).ready(function(){

	// add a close button to the contact form
	$("#contact fieldset").after("<a id=\"close\" class=\"close\" title=\"sluiten\">sluiten</a>");
	
	// check if the contact form needs to be hidden or soft scroll to its id
	hash = window.location.hash;
	if ( hash === "#contact" ) {
		$("html,body").animate( { scrollTop: $("#contact").offset().top }, 1000, function(){
				$("#bericht").focus();
		});
	} else {
		$("#contact").hide();
	}
	
	// make the close button close the contact form, suppress default behaviour
	$("#close").click(function(){
		$("#contact").slideUp("slow", function(){
			$("html,body").animate( { scrollTop: 0 }, 1000 );
		});
		return false;
	});
	
	// make the a.open link open the contact form and scroll to it, then give the first field focus, suppress default behaviour
	$("a#contact-link").click(function(){
		$("#contact").slideDown("slow", function(){
			$("html,body").animate( { scrollTop: $("#contact").offset().top }, 1000, function(){
				$("#bericht").focus();
			});
		});
		return false;
	});
	

	$("a.keyword").click(function(){
		var begrip_url = $(this).attr("href").split("#")[1];
		var begrip = $(this).attr("title");
		
		$("body").append('<div id="overlay"><dl></dl><a class=\"close\" title=\"sluiten\">sluiten</a></div>');
		$("#overlay").fadeTo(0,0);
		$("#overlay dl").load("begrippen.html #"+begrip_url+"+dd", function(){
			$(this).prepend('<dt>'+begrip+'</dt>');
		});
		$("#overlay").fadeTo(500, 1).focus().click(function(){
			$(this).fadeOut(500, function(){
				$(this).remove();
			});
		});
		
		return false;
	})
	
});
