$(function() {
	
	// Ask for last clicked list item
	$.post("http://arievanboxel.nl/portal/cgi/store.php", {type: 'last'}, function(xml) {
		setLastClickedListItem( $("last", xml).text() );
	});
					
	// CLICK HANDLERS ///////////////////////////////////////////////////////////////////////////////////////////////////
	
	// Give user possibility to see background image
	$('h2').click(function() {
		$(this).next().animate({
		    "height": "toggle",
		    "opacity": "toggle"
		},
		{
		   duration: 'short'
		});
	});

	// Store clicked item name (has to be unique though)	
	$('li > a').click(function(e) {
	 	// Load target after data is posted  
	 	e.preventDefault();
	 	var target = this.href;
	 	$.post("http://arievanboxel.nl/portal/cgi/store.php", {type: 'last', value: $(this).parent().text() }, function(xml) {
	 		setLastClickedListItem( $("last", xml).text() );
			window.location.href = target;
	 	});
	});

});

function setLastClickedListItem( value ) {
	$("li").removeClass("lastClicked");
	$("li").filter(function() {
	  return $.trim( $(this).text() ) == $.trim(value);
	}).addClass("lastClicked");	
}