// JavaScript Document

$(document).ready(function() {

			function addListItem() {
				//var listItems = $('#mainmenu li').length;
				if ($('#mainmenu li').length < 9)
				{
					$('#mainmenu').append('<li></li>');
					addListItem();
				}
				else {
					return;
				}
			}

	
	if ($('#mainmenu').length > 0) {

		$('#mainmenu li:eq(1)').after('<li class="liVisual"><div id="liVisualDiv"></div></li>');
		$('#mainmenu li:eq(4)').after('<li><a class="opKopLink2" href="http://www.stichtingopkop.nl/" target="_blank"></a></li>');
		$('#liVisualDiv').append($('#topVisual img'));
	
		$('#liVisualDiv').append($('#topVisual img'));	
		
		if ($('#mainmenu li').length < 9 ){
			addListItem();
		}
		else if($('#mainmenu li').length > 9 ) {
			$('#mainmenu li:gt(9)').css("clear","both");
		}

		$('#mainmenu li:last-child').css("clear", "both");
		$('#mainmenu li').each(function(index) {
			$(this).attr("id", "mm"+(index+1));
		});

	}

	function setHeights(){
		var obj1 = $("#tekst");
		var obj2 = $("#menu");
		var screenh = $(window).height(); // schermhoogte
		var bottomDiv = 30;
		var yTop = $(obj1).offset().top;
		var containerHeight1 = (screenh - bottomDiv - yTop - 40);
		var containerHeight2 = (screenh - bottomDiv - yTop);
		$(obj1).css({height: containerHeight1});
		$(obj2).css({height: containerHeight2});
	}

	$(window).resize(function() {
	setHeights();
	});

	setHeights();
	
		$(function()
		{
			$('#tekst').each(
				function()
				{
					$(this).jScrollPane(
						{
							showArrows: $(this).is('.arrow'),
							verticalDragMinHeight: 10,
							verticalDragMaxHeight: 10
						}
					);
					var api = $(this).data('jsp');
					var throttleTimeout;
					$(window).bind(
						'resize',
						function()
						{
							if ($.browser.msie) {
								// IE fires multiple resize events while you are dragging the browser window which
								// causes it to crash if you try to update the scrollpane on every one. So we need
								// to throttle it to fire a maximum of once every 50 milliseconds...
								if (!throttleTimeout) {
									throttleTimeout = setTimeout(
										function()
										{
											api.reinitialise();
											throttleTimeout = null;
										},
										50
									);
								}
							} else {
								api.reinitialise();
							}
						}
					);
				}
			)
		
		});
	
	
	
});
