/* functie om hele blokken klikbaar te maken, en hover toevoegen */
$.fn.hoverClick = function()
{
	this.each(function()
	{
		$(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;
};


function filter_op_categorie(formulier)
{
	if(formulier.value != '')
		$("#categorieform").submit();
}

$(function()
{
	
	// Formulier focus op velden
	$("#content input, #content textarea").focus(function() { $(this).addClass("veldfocus"); });
	$("#content input, #content textarea").blur(function() { $(this).removeClass("veldfocus"); });


	
	/* Subsubmenu */
	var menu = {};

	menu.laatstGeopend = null;
	menu.timeoutTime = 2000;
	menu.timeout = null;
	
	menu.init = function()
	{		
		/* hover op li */
		$("#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
				{
					$("#menu>li>ul").hide();
					$("#menu>li").not(this).removeClass("hover");
					
					$(this).addClass("hover");
					$(">ul", this).slideDown(400);									
				}
			},
			function() 
			{ 
				// timeout zetten om na x aantal sec te sluiten
				menu.laatstGeopend = this;
				menu.timeout = setTimeout(function()
				{
					$(menu.laatstGeopend).removeClass("hover"); 
					
				}, menu.timeoutTime);
			}
		);
	}

	menu.init();




});


/* jumpbox */
$.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;
};
