var openLightbox = function() {
	document.appendChild('<div id="light" class="lightbox_white_content"></div><div id="fade" class="lightbox_black_overlay"></div>');
	var a = document.getElementByTagName('body');
	a.style.overflow = 'hidden';
}

var selectAll = function (check, form) {
	for (n = 0; n < form.elements.length; n++) {
		if (form.elements[n].type == 'checkbox') {
			form.elements[n].checked = check;
		}
	}
}

$( function() {
	if( $( "#nieuwsTicker .back_button" ).length ) {
		$( "#nieuwsTicker .back_button" ).remove();
	}
} );

function cycleInit() {
	$( "#highlightmenu li" ).hoverIntent( {
		sensitivity: 1,
		interval: 0,
		over: makeTall,
		timeout: 0,
		out: makeShort
	} );

	$( "#highlightmenu li" ).each( function() { $( this ).find( "img:first" ).toggle(); } );
	$( "#highlightmenu li#actief img" ).toggle();
	$( "#highlightimages ul.es" ).toggle();
	$( "#highlighttekst div.es" ).css( "z-index", 2 );
	$( "#highlightkop div.es" ).css( "z-index", 2 );

	function makeTall() { $( this ).animate( { "height" : 45 }, 250 ); if( $( this ).attr( "id" ) != "actief" ){ $( this ).find( "img" ).toggle(); } }
	function makeShort() { var Obj = $( this ); if( Obj.attr( "id" ) != "actief" ){ Obj.animate( { "height" : 35 }, 250, function(){ Obj.find( "img" ).toggle(); } ); } }
}

function homeInit() {
	cycleInit();

	$( "#highlightimages ul.gr, #highlightimages ul.tr, #highlightimages ul.es, #highlightimages ul.ai" ).cycle( { fx: "fade" } ).cycle( "pause" );
	/* DEZE ZIJN ERUIT GEHAALD, MAAR 1 PLAATJE: MOCHTEN ER MEER TOEGEVOEGD WORDEN ZET DEZE ERIN!
		, #highlightimages ul.eg, #highlightimages ul.vw
	*/
	$( "#highlightimages ul.es" ).cycle( "resume" );

	$( "#highlightmenu li" ).click( function() {
		var $diaClass = $( this ).attr( "class" );

		$( "#highlightmenu li#actief" ).animate( { "height" : 35 }, 250, function(){
			$( this ).find( "img" ).toggle();
		} ).removeAttr( "id" );
		$( this ).attr( "id", "actief" ).animate( { "height" : 45 }, 250 );

		$( "#highlightimages ul.gr, #highlightimages ul.tr, #highlightimages ul.es, #highlightimages ul.eg, #highlightimages ul.ai, #highlightimages ul.vw" ).cycle( "pause" ).hide();
		$( "#highlightimages ul." + $diaClass ).cycle( "resume" ).fadeIn();

		$( "#highlighttekst div, #highlightkop div" ).css( "z-index", 1 );
		$( "#highlighttekst div." + $diaClass + ", #highlightkop div." + $diaClass ).css( "z-index", 2 );
	} );
}

function menuInit() {
	if( $( "#subMenuContainer ul.mainMenu" ).length == 1 )
		$( "#subMenuContainer ul.mainMenu" ).addClass( "subNavigatie" ).removeClass( "mainMenu" );

	$( "ul.mainMenu > li:last" ).css( "border-right", "2px solid #e7e5e6" );
	$( "ul.subMenu" ).each( function() {
		$( this ).find( "li:first" ).css( "padding-top", "20px" );
	} );

	$( "ul.mainMenu li, ul.mainMenu li a, ul.mainMenu li h5 a" ).hover( function() {
		if( $( this ).find( ".subMenu" ).length == 1 && $( this ).find( ".subMenu:animated" ).length == 0 ) {
			var nieuweBreedte = $( this ).width() + 38;
			nieuweBreedte = ( nieuweBreedte > 200 ) ? nieuweBreedte : 200;
			$( this ).find( ".subMenu" ).width( nieuweBreedte + "px" );

			var aantalLi = $( this ).find( "li" ).length;
			var nieuweHoogte = ( ( aantalLi * 40 ) - ( ( aantalLi > 4 ? ( ( aantalLi / 4 ) * 10 ) : 0 ) ) ) + "px";
			$( this ).find( ".subMenu" ).css( { height: nieuweHoogte, display: "block", position: "absolute" } );

			if( $( this ).find( ".subMenu:last" ).length == 1 )
				$( ".subMenu:last" ).css( { "margin-left" : "-85px" } );
		}
	}, function() {
		$( this ).find( ".subMenu" ).css( { height: "0px", display: "none" } );
	} );
}