$(document).ready(function() {
	if ($('#picture_container').length > 0) {
		var flashvars = {fvConfigXmlUrl:"/index.php?type=800", fvCacheConfig:"true"};
		var params = {};
		var attributes = {};
		swfobject.embedSWF(
			"/fileadmin/templates/2009/flash/photocontainer.swf?r=$Rev: 58168 $", 
			"picture_container", 
			"100%", 
			"100%", 
			"9.0.0.0",
			"/fileadmin/templates/2009/flash/expressInstall.swf",
			flashvars,
			params,
			attributes);
	}
	if ($('#focus_on_belgium').length > 0) {
		var flashvars = {gateway:"/?eID=noorderslag", countryUid: 20};
		var params = {wmode: "transparent"};
		var attributes = {};
		swfobject.embedSWF(
			"/fileadmin/templates/2009/flash/focuscoverflow.swf?r=$Rev: 58168 $", 
			"focus_on_belgium", 
			"100%", 
			"100%", 
			"9.0.0.0",
			"/fileadmin/templates/2009/flash/expressInstall.swf",
			flashvars,
			params,
			attributes);
	}
	if ($('#mobile_widget').length > 0) {
		var flashvars = {};
		var params = {wmode: "transparent"};
		var attributes = {};
		swfobject.embedSWF(
			"/fileadmin/templates/2009/flash/mobilewidget.swf",
			"mobile_widget",
			"100%",
			"100%",
			"9.0.0.0",
			"/fileadmin/templates/2009/flash/expressInstall.swf",
			flashvars,
			params,
			attributes);
	}
	$('#shortcut_nav').accordion({
		active: '.active',
		header: '.header',
		alwaysOpen: true,
		navigation: false,
		event: 'mouseover',
		fillSpace: false,
		autoheight: true,
		animated: 'slide'
	}).accordion('activate', 0);
	
	// Check if mid content overflows enclosing div
	if ($('#home_content p.bodytext').height() > ($('#home_content').height() - $('#home_content div.csc-header').height())) {
		$('#home_content p.bodytext').wrap('<div class="content-wrapper"></div>');
		$('#home_content .content-wrapper').prepend('<a title="Scroll up" href="#" class="double-arrow-down">Omlaag</a>');
		$('#home_content .content-wrapper').prepend('<a title="Scroll down" href="#" class="double-arrow-up">Omhoog</a>');
		
		$('#home_content a.double-arrow-up').hide();
		$('#home_content a.double-arrow-down').bind('click', function(evt) {
			evt.preventDefault();
			var new_top = $('#home_content .content-wrapper').height() - $('#home_content p.bodytext').height();
			$('#home_content p.bodytext').animate({'top': new_top});
			$(this).hide();
			$('#home_content a.double-arrow-up').show();
		});
		$('#home_content a.double-arrow-up').bind('click', function(evt) {
			evt.preventDefault();
			$('#home_content p.bodytext').animate({'top': 0});
			$(this).hide();
			$('#home_content a.double-arrow-down').show();
		});
	}
	
	// Home tabs
	if ($('#home_tabs ul').length > 0) {
		$('#home_tabs ul li a').bind('click', function(evt) {
			evt.preventDefault();
			$('#home_tabs ul li').removeClass('active');
			$(this).parent('li:first').addClass('active');
			$('#home_tabs .tabs-content-wrapper>div').addClass('hidden');
			$('#home_tabs ul li').each(function(index, el) {
				if ($(el).hasClass('active')) {
					$('#home_tabs .tabs-content-wrapper>div:eq(' +index+')').removeClass('hidden');
				}
			});
		});
		$('#home_tabs ul li:first a').click();
		
		$('#home_tabs div.tabs-content-wrapper>div').each(function() {
			this.news_count = $('div div.news-latest-item', this).length;
			this.show_items = 3;
			this.current = 0;
			if (this.news_count > 0 && this.news_count > this.show_items) {
				this.update = function() {
					$('div.news-latest-item', this).hide();
					for (var i = this.current; i < (this.current + this.show_items); i++) {
						$('div.news-latest-item:eq(' +i + ')', this).show();
					}
					if (this.current > 0) {
						$('a.news-latest-previous', this).show();
					} else {
						$('a.news-latest-previous', this).hide();
					}
					if (this.current + this.show_items < this.news_count) {
						$('a.news-latest-next', this).show();
					} else {
						$('a.news-latest-next', this).hide();
					}
				}
				this.update();
				$('div.news-latest-item:gt(' + (this.show_items - 1) + ')', this).hide();
				$('a.news-latest-next', this).bind('click', function(evt) {
					var parent = $(this).parent('div.tabs-content-wrapper>div');
					evt.preventDefault();
					if (parent[0].current < (parent[0].news_count - parent[0].show_items)) {
						parent[0].current += parent[0].show_items;
						parent[0].update();
					}
				});
				$('a.news-latest-previous', this).bind('click', function(evt) {
					var parent = $(this).parent('div.tabs-content-wrapper>div');
					evt.preventDefault();
					if (parent[0].current > 0) {
						parent[0].current -= parent[0].show_items;
						parent[0].update();
					}
				});
			} else {
				$('.news-latest-next', this).hide();
				$('.news-latest-previous', this).hide();
			}
		});
	}
});