jQuery.extend( jQuery.easing,
{
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOut: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	}
});

/* functie om hele blokken klikbaar te maken, en hover toevoegen */
$.fn.hoverClick = function()
{
	this.each(function()
	{
		if($("a:first", this).length)
		{
			$(this).hover(
				function() { $(this).addClass("hover").css("cursor", "pointer"); },
				function() { $(this).removeClass("hover").css("cursor", "pointer"); }
			);
			
			$(this).attr("title", $("a:first", this).attr("title"));
			
			$(this).click(function(){
				window.location = $("a:first", this).attr("href");
			});
		}
	});
	
	return this;
};

$.fn.listJumpbox = function()	
{									
	this.each(function()	
	{ 
		var c = this;
		
		$(c).css("position", "relative");
		
		$("ul", c).css({
			position	: 'absolute',
			left		: '-1px',
			top			: $("span").outerHeight()
		}).hide();
		
		// wanneer er geen meer zichtbaar zijn de eerste tonen
		if($("li.actief", c).length)	{
			$("span.selected", c).text($("li.actief", c).text());
		}
		
		// jumpbox is dicht
		$(c).addClass("jumpbox-dicht");
		var dicht = true;
		
		// de eerste klikbaar maken om de lijst uit te klappen
		$("span.selected", c).click(function()
		{
			if(dicht)
			{
				$(c).removeClass("jumpbox-dicht").addClass("jumpbox-open").css("z-index", 1337);
				dicht = false;

				$("ul", c).css("opacity", 0).animate({ height: 'show', opacity: 1 }, 500);
			}
			else
			{
				$(c).removeClass("jumpbox-open").addClass("jumpbox-dicht");
				dicht = true;
																
				$("ul", c).animate({ height: 'hide', opacity: 0 }, 500, function() {
					$(c).css("z-index", 0)
				});
			}
		});
		
		// de eerste klikbaar maken om de lijst uit te klappen
		$("li:visible", c).click(function()
		{
			$("li", c).removeClass("actief");
			$(this).addClass("actief");
			
			$(c).removeClass("jumpbox-open").addClass("jumpbox-dicht");
			dicht = true;
															
			$("span.selected", c).text($(this).text());

			// lijstje
			$("ul", c).animate({ height: 'hide', opacity: 0 }, 500);
		});
	
	});

	return this;
};


$(function()
{
	// submenu effect	
	var menu = {};

	menu.laatstGeopend = null;
	menu.timeoutTime = 2000;
	menu.timeout = null;
	
	menu.init = function()
	{
		$("ul#menu > li").hover( 
			function() 
			{ 		
				// als laatstegeopend dezelfde is als de huidige, dan de timeout verwijderen
				if($(this).hasClass("hover"))
				{
					clearTimeout(menu.timeout);
				}
				// nieuwe uitschuiven
				else
				{
					$("ul#menu>li>ul").hide();
					$("ul#menu>li").not(this).removeClass("hover");
					
					$(this).addClass("hover");
					$(">ul", this).hide().slideDown(300);
					
					// selectbox in <ie7 verwijderen
					if($.browser.msie && $.browser.version < 7)	{
						$("select").css({ visibility: 'hidden' });	
					}
				}
			},
			function() 
			{ 
				// timeout zetten om na x aantal sec te sluiten
				menu.laatstGeopend = this;
				menu.timeout = setTimeout(function()
				{
					$(menu.laatstGeopend).removeClass("hover"); 
					
					// selectbox in <ie7 tonen
					if($.browser.msie && $.browser.version < 7)	{
						$("select").css({ visibility: 'visible' });	
					}
				}, menu.timeoutTime);
			}
		);
	};
	
	menu.init();
	
	// referenties
	$("#referenties ul li").hoverClick();
	
	// Formulier focus op velden
	$(":input").not("input[type=button], input[type=submit], input[type=radio], input[type=checkbox]").focus(function() { $(this).addClass("veldfocus"); });
	$(":input").not("input[type=button], input[type=submit], input[type=radio], input[type=checkbox]").blur(function() { $(this).removeClass("veldfocus"); });

	$(".jumpbox").listJumpbox();
	
	// Zoeken
	$("#zoeken input:text[title]").each(function() { 
		$(this).defaultvalue( $(this).attr("title") );
	});

});

/** 
 * jquery.defaultvalue 
 * @param	string	defaultvalue
*/
$.fn.defaultvalue = function( defVal )
{
	return this.each(function()
	{
		var $input = $(this);
		if($input.val() == "" || $input.val() == defVal)
		{
			$input.addClass("defaultvalue").val(defVal);
		}
		
		$input
			.focus(function() {
				if($input.val() == defVal) 
					$input.val("").removeClass("defaultvalue");
			})
			.blur(function(){
				if($input.val() == "") 
					$input.addClass("defaultvalue").val(defVal);
			});
	});
};

function controleerZoeken(formulier)
{
	if(($("#zoeken input[type=text]").val().length < 3 || $("#zoeken input[type=text]").val() == $("#zoeken input[type=text]").attr("title")) )
	{
		$("#zoeken-melding").html("Vul svp een zoekterm in van 3 of meer karakters.");
		$("#zoeken-melding").fadeIn(200);
		
		setTimeout( function()
				{
				$("#zoeken-melding").fadeOut(500);	
				}, 4000);
		
		return false
	}
	else
	{
		$("#zoeken-melding").css({display:'none'});
		return true;	
	}
}
