/* ------------------------------------------------- */
/* JQuery functions
/* ------------------------------------------------- */

/* ------------------------------------------------- */
/* On document ready
/* ------------------------------------------------- */
jQuery(document).ready(function($) {
	
	/* ------------------------------------------------- */
	/* Scrollable inits
	/* ------------------------------------------------- */
	if($('#home-scrollable').length) $('#home-scrollable').scrollable({mousewheel:true});
	if($('#news-scrollable').length) $('#news-scrollable').scrollable({mousewheel:true});
	$('.slideshow').cycle({fx:'scrollLeft',pause:true,sync:true,timeout:6000});
	$('.slideshow-fade').cycle({timeout:6000});
	
	/* ------------------------------------------------- */
	/* Make full blocks clickable
	/* ------------------------------------------------- */
	$('div.voet-blok:not(".talen")').each(function() {
		if($('a', $(this)).length) {
			$(this).css({'cursor':'pointer'});
			$(this).click(function() {
				window.location = $('a', $(this)).attr('href');
			});
		}
		$(this).hover(function() {
			$(this).stop().animate({top:-205}, 200, function() {});
		},
		function () {
			$(this).stop().animate({top:0}, 200, function() {});
		});
	})
	
	/* ------------------------------------------------- */
	/* Menu Suckerfish
	/* ------------------------------------------------- */
	if($('#menu').length) {
		$('ul', $('#menu')).each(function() {
			$(this).css({'left':$('#menu').width() + 5})
		});
	}
	
	var timeout	   = 500;
	var timeout2	= 500;
	var closetimer;
	var closetimer2;
	
	var ddmenuitem;

	function menu_open() {
		menu_canceltimer();
		menu_close();
		ddmenuitem = $(this).find('ul').css('display', 'block');
	}

	function menu_close() {
		if(ddmenuitem) ddmenuitem.css('display', 'none');
	}

	function menu_timer() {
		closetimer = window.setTimeout(menu_close, timeout);
	}

	function menu_canceltimer() {
		if(closetimer)
		{
			window.clearTimeout(closetimer);
			closetimer = null;
		}
	}

	function close_timer(){
		if(closetimer2)
		{
			window.clearTimeout(closetimer2);
			closetimer2 = null;
		}
	}

	function set_timer()
	{
		closetimer2 = window.setTimeout(set_fadeout, timeout2);
	}

	function set_fadeout(){
		$('#menu').fadeOut('fast', function () {
			$('#menu-btn').stop().fadeIn('fast');
		});
	}

	$('#menu > li').bind('mouseover', menu_open)
	$('#menu > li').bind('mouseout',  menu_timer)
	$("#menu").mouseover(function(){ close_timer(); })
	$("#menu").mouseout(function(){ set_timer(); })
	
	$('#menu-btn').mouseover(function() {
		$('#menu-btn').stop().fadeOut('fast', function () {
			$('#menu').stop().fadeIn('fast');
		});
	});
	
	$('#menu-btn').click(function(e) { e.preventDefault(); })
	
	if($('#contact-form').size() > 0) {
		$("#contact-form").validate();
	}
	
	$('a.colorbox').colorbox();
	
});
