$(document).ready(function() {

	var active = null;
	if ($("#projects").length > 0) {
		if (active == null) {
			active = $("#projects ul li.active");
			$(active).find('div').css('display','block');
		}
		$("#projects ul li").click(function() {
			if (active !== this) {
				$(active).removeClass('active');
				$(active).find('div').slideUp();
				active = this;
				$(active).addClass('active');
				$(active).find('div').slideDown();
			}
		});
	}

	var menu = null;
	if ($("#submenu ul li").length > 0) {
		if ($("#submenu ul li.active").length > 0) {
			menu = $("#submenu ul li.active")[0];
		}
		$("#submenu ul li.main").click(function() {
			if (menu !== this) {
				if (menu) {
					$(menu).find('ul').slideUp();
					$(menu).removeClass('active');
				}
				menu = this;
				$(menu).find('ul').slideDown();
				$(menu).addClass('active');
			}
		});
	}

	$("#language").mouseover(function() {
		$("#select").css('display', 'block');
	});

	$("#language").mouseout(function() {
		$("#select").css('display', 'none');
	});

	$(".block").mouseover(function() {
		$(this).addClass('hover');
	});

	$(".block").mouseout(function() {
		$(this).removeClass('hover');
	});

	if ($("#form-projects").length > 0) {
		$("#form-projects select").change(function() {

			var url = $("#url").attr("value") + '/' + $("#select-gebied").attr("value");

			var year = $("#select-jaar").attr("value");
			if (year)
				url = url + '/year/' + year;

			var month = $("#select-maand").attr("value");
			if (month)
				url = url + '/month/' + month;

			location.href 	= url;
		});
	}

	if ($("#header img").length > 1) {
		setInterval("slideShow()", 5000);
    }

    $('a.group').fancybox({
		frameWidth: 520,
		frameHeight: 540,
		overlayColor: '#000',
		overlayOpacity: 0.66,
		padding: 0,
		hideOnContentClick: false
	});

    $('a.group2').fancybox({
		frameWidth: 520,
		frameHeight: 448,
		overlayColor: '#000',
		overlayOpacity: 0.66,
		padding: 0,
		hideOnContentClick: false
	});

});

function slideShow() {

    var $active = $('#header IMG.active');

    if ($active.length == 0)
    	$active = $('#header IMG:last');

    var $next =  $active.next().length ? $active.next() : $('#header IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}