$(function() {
	addNewsShowHideToggle();
	autoToggleNews();
});
function addNewsShowHideToggle() {
	$('.content ul.showhide a, .content .box h2.greenTitleContent a').click(function() {
	var box = $(this).parents('.box');
		var content = $('div.expandable', box);
		var link = $('ul.showhide a', box);
		var linkText = $('.linkText', link);

		$(".newsSummaryShort", box).toggle();

		if(content.hasClass('hidden')) {
			content.removeClass('hidden');
			link.addClass('open');
			linkText.html('Verberg');
			link.attr("title","Verberg bericht");
		} else {
			content.addClass('hidden');
			link.removeClass('open');
			linkText.html('Bekijk');
			link.attr("title", "Bekijk bericht");
		}
	});
}
function autoToggleNews() {
	// Get the document location
	var docLocation = document.location.toString();

	// Check for anchor
	if (docLocation.match('#')) {
	  	// Get the anchor value
	  	var anchorName = '#' + docLocation.split('#')[1];

	  	// Open the news item matching the anchor
	  	var newsItem = $(anchorName + ' ul.showhide a');

		// Check if the item exists
	  	if(newsItem.length != 0) {
	  		// Item exists, trigger the click action
	  		newsItem.click();
	  	} else {
	  		// Item does not exists, open the first news item
	  		$('div.box:first ul.showhide a').click();
	  	}
	} else {
		// No anchor, open the first news item
		// $('div.box:first ul.showhide a').click();
	}
}
function toggleNews(newsItemId) {
  	// Open the news item matching the anchor
  	var newsItem = $('#' + newsItemId + ' ul.showhide a');

  	// Check if the item exists
  	if(newsItem.length != 0) {
  		// Item exists, trigger the click action
  		newsItem.click();
  	}
}
