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;
	}
});

/* 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;
};


function logoSlide()
{
	$("#header .logo").animate( { top:'0' }, 2000, 'easeOut');
}

/* 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;
};

/******************/
/* Menu functions */
/******************/
window.Menu = {
	delay		: 1200,
	timer		: null,
	menuitem	: null,
	
	/**
	 * apply
	 * @param	string	selector
	 */
	apply: function( selector ) {
		$(selector).hover(Menu.open, Menu.setTimer);
		$(document).click(Menu.close);
	},
	
	/** 
	 * cancelTimer
	 */
	cancelTimer: function() {
		if(Menu.timer)	{
			clearTimeout(Menu.timer);
     		Menu.timer = null;
		}
	},
	
	/**
	 * setTimer
	 */
	setTimer: function() {
		Menu.timer = window.setTimeout(Menu.close, Menu.delay);
	},
		
	/** 
	 * close
	 * @param	string	current_menu_id
	 */
	close: function( current_menu_id ) {
		if(Menu.menuitem)	{
			if(Menu.menuitem.data("menuID") != current_menu_id)	
			{
				$("ul", Menu.menuitem).css({ height: 'auto', zIndex: "" }).stop().slideUp();
				$(Menu.menuitem).removeClass("hover");
			}
		}
	},
			
	/** 
	 * open
	 */
	open: function() {
		current_menu = $(this);
		
		current_menu.addClass("hover");
		
		// uniek menu id per submenu, dit om bij het sluiten te checken of niet de actieve wordt gesloten
		if(!current_menu.data("menuID"))	{
			current_menu.data("menuID", (Math.random() +''+ Math.random()).replace(/\./g,""))
		}
		
		Menu.cancelTimer();
		Menu.close( current_menu.data("menuID") );
		Menu.menuitem = current_menu;
		
		$("ul", Menu.menuitem).css({ height: 'auto', zIndex: 100 }).stop().slideDown();	
	}

};

$(function()
{
	
	$("#referentieoverzicht li").hoverClick();
	
	$('#header-fotos').cycle({ 
		fx		: 'fade',
		easing	: 'easeInQuad',  
		speed	: 3000,
		timeout	: 6000 
	 });
	
	/* Submenu */
	/*$('#menu>li').hover( 	
	function() 
	{ 
		$(this).addClass('hover'); 
		$("ul", this).slideDown(300);
	},
	function() 
	{
		$('#menu li ul').hide();
		$(this).removeClass('hover');
		//$("ul", this).hide();
	});*/
	Menu.apply("#menu > li");
	
	// Formulier focus op velden
	$("#content input, #content textarea").focus(function() { $(this).addClass("veldfocus"); });
	$("#content input, #content textarea").blur(function() { $(this).removeClass("veldfocus"); });

});

sIFR.replaceElement(named({ sSelector:"#content h1", sFlashSrc: submap + "/fla/metaplus.swf", sColor:"#FFFFFF", sBgColor:"#9492B5", sWmode:"transparent" }));
sIFR.replaceElement(named({ sSelector:"#content h2", sFlashSrc: submap + "/fla/metaplusnormal.swf", sColor:"#605d91", sBgColor:"#FFFFFF", sWmode:"transparent" }));

