$(document).ready(function() {
	var opened = new Array();
	var closeTO = null;
	$('.uitklap').click(function() {

		closeOpen();
		if ($(this).next().hasClass('home')) {
			if ($(this).next().css('display') == 'none') {
				if ($(this).next().attr('rel') == undefined) {
					var sWidth = $(this).next().width();
					$(this).next().attr('rel', sWidth);
				} else {
					var sWidth = $(this).next().attr('rel');
				}
				$(this).next().css({
					width : 0,
					display : 'block'
				}).animate({
					width : sWidth
				});

				opened.push($(this).next());
				$($(this).next()).mouseenter(function() {
					clearTimeout(closeTO);
				}).mouseleave(function() {
					closeTO = setTimeout(function() {
						closeOpen();
					}, 200);
				});
			}
		} else {
			if ($(this).next().css('display') == 'none') {
				$(this).next().slideDown();
			} else {
				$(this).next().slideUp();
			}
		}
	}).mouseleave(function() {
		closeTO = setTimeout(function() {
			closeOpen();
		}, 200);
	}).mouseenter(function() {
		if ($(this).next() == $(opened[0])) {
			clearTimeout(closeTO);
		}
	});

	function closeOpen() {
		for (x in opened) {
			$(opened[x]).animate({
				width : 0
			}, function() {
				$(this).css('display', 'none');
			})
		}
		opened = new Array();
	}

	$('a._blank').each(function() {
		$(this).attr('target', '_blank');
	});
});

/* slider */

$(document).ready(function() {
	var current;
	var nInterval = null;

	$('.quote > .prev').click(function() {
		nextQuote(true);
	});

	$('.quote > .next').click(function() {
		nextQuote();
	});

	$('.quote > .item').mouseover(function() {
		cancelLoop();
	}).mouseout(function() {
		cancelLoop();
		startLoop();
	});

	function startLoop() {
		if ($('.quote > .item').length > 1) {
			nInterval = setInterval(function() {
				nextQuote();
			}, 6000);
		}
	}
	startLoop();

	function cancelLoop() {
		clearInterval(nInterval);
	}

	function nextQuote(p_sPrev) {
		var prev = p_sPrev || false;
		$('.quote > .item.active, .quote > .item.first').each(function() {
			$(this).slideUp().removeClass('active').removeClass('first');
			if (prev == false) {
				if ($(this).next('.item').length != 0) {
					$(this).next('.item').slideDown().addClass('active');
				} else {
					$('.quote > .item:first').slideDown().addClass('active')
				}
			} else {
				if ($(this).prev('.item').length != 0) {
					$(this).prev('.item').slideDown().addClass('active');
				} else {
					$('.quote > .item:first').slideDown().addClass('active')
				}
			}
		});
	}
});
var objNewsScoller = null;
$(document).ready(function() {
	function newsScroll() {
		var owner = this;
		this.target = '#nieuws .scroll'; 
		this.parentheight = $('#nieuws').height();  
		this.height = $(this.target).height();

		this.count = $(this.target + ' li').length 
		this.timerdelay = 1000;
		
		this.timeDown = this.count * 1.5 * 1000;
		this.running = false;
		this.timeUp = 1000;
		this.scrollDown = function(){
			owner.running = true;
			$(this.target).animate({
				top : '-' + (this.height-this.parentheight+20) + 'px'
			}, this.timeDown, 'linear', function(){
				owner.running = false;
				setTimeout(function(){owner.scrollUp();}, owner.timerdelay);
			});
		};
		
		this.scrollUp = function(){
			owner.running = true;
			$(this.target).animate({
				top : 0
			}, this.timeUp, 'linear', function(){
				owner.running = false;
				setTimeout(function(){owner.scrollDown();}, owner.timerdelay);
			});
		};
		
		this.pause = function(){
			$(this.target).stop(true, false);
			owner.running = false;
		};
		
		this.start = function(){
			if(owner.running == false){
				setTimeout(function(){owner.scrollDown();}, owner.timerdelay);
			}
		}; 
		this.start();
	};
	
	objNewsScoller = new newsScroll();
	
});
