$(function()
{
	jQuery.extend( jQuery.easing, {
		easeOutQuad: function (x, t, b, c, d) {
			return -c *(t/=d)*(t-2) + b;
		}
	});
	
	/********************/
	/* Werkwijze pagina */
	/********************/
	// Standaard hoogte bepalen van content voor werkwijze pagina
	// Hoogte van tekstblok bepalen
	var hoogte = 0;
	$("#werkwijze li div")
	.each(function()	{
		if($(this).height() > hoogte)	{
			hoogte = $(this).height();
		}
	})
	.each(function()	{
		$(this).height(hoogte)
	});

	var contenthoogte = 200 + hoogte;
	$("#werkwijze").css("height", contenthoogte+"px");
	
	// Selecteer class welke als eerst voorkomt
	function getFirstClass(e)	{
		if(e.className) return e.className.split(" ")[0];
		else			return false;
	}

	// Werkwijze standaard eerste keus aan
	$("#werkwijze li.stap1").addClass("stap1_hover");
	
	// Werkwijze hover
	$("#werkwijze li").hover(function()
	{
		// Loop over elke li en verwijder de class
		$("#werkwijze li").each(function()
		{
			$(this).removeClass(getFirstClass(this) + "_hover");					
		});
		
		// Zet class op deze li
		$(this).addClass(getFirstClass(this) + "_hover");
	},
	function()
	{
		// Niks
	});
	
	// Lightbox fotoboek
	$("a[rel^='prettyPhoto'], #fotoboek-links .fotogroot a, #fotoboek-links .fotos a").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.75, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: false, /* true/false */
		counter_separator_label: ' / ' /* The separator for the gallery counter 1 "of" 2 */
	});
});

// Fotoboekje link
var huidige = '';
function fotoBoekje()
{
	// Bij klik op foto deze foto in vergroting zetten
	var imgLoader = null;
			
	$("#fotoboek-links li a").hover(function()
	{
		var tlink = this;
		huidige = submap + $(this).attr("rel").split(" ")[0];
		
		if($("#fotoboek-links .fotogroot p img").attr("src") != huidige)
		{
			//alert($("#fotoboek-links .fotogroot p img").attr("src"));
			$('#fotoboek-links .fotogroot p').fadeOut(200, function()
			{
				imgLoader = new Image();  
				imgLoader.onload = function()	
				{
					$('#fotoboek-links .fotogroot p a').attr({ href: $(tlink).attr("href"), title: $(tlink).attr("title") });
					$('#fotoboek-links .fotogroot p img').attr({ src: imgLoader.src, alt: $(tlink).attr("title") });
					$('#fotoboek-links .fotogroot p').fadeIn(200);
				}
				imgLoader.src = $(tlink).attr("rel").split(" ")[0];	
			});
		}
	},
	function()
	{
		// niks
	});
	
	// Navigatie
	// 3 foto's per keer
	var aantal_fotos = $('#fotoboek-links ul.fotos').children().size();
	var breedte_ul = aantal_fotos*66;
	
	$("#fotoboek-links ul.fotos").css("width", breedte_ul);
	
	// Navigatie bouwen
	var aantal_navigatie = Math.ceil(aantal_fotos/3);
	$(".fotosnav").append("<ul><\/ul>");
	
	var i = 1;
	for(i=1; i<=aantal_navigatie; i++)
	{
		if(i==1)
		{
			$(".fotosnav ul").append("<li><a class='actief' href='' title='"+i+"'>"+i+"<\/a><\/li>");
		}
		else
		{
			$(".fotosnav ul").append("<li><a href='' title='"+i+"'>"+i+"<\/a><\/li>");	
		}
	}
	
	// Navigatie bij klik naar andere foto's
	$(".fotosnav ul li a").click(function() { return false; });
	$(".fotosnav ul li a").click(function()
	{
		$(".fotosnav ul li a").removeClass("actief");
		$(this).addClass("actief");
		
		var margin_lijst = $(this).attr("title");
		var aantal_pixels = (margin_lijst*198)-198;
		//$("#fotoboek ul.fotos").css("margin-left", "-"+aantal_pixels+"px");
		$("#fotoboek-links ul.fotos").animate({ 
				marginLeft: "-"+aantal_pixels+"px"
			  }, 500, 'easeOutQuad');

	});

}

/******************/
/* Menu functions */
/******************/
window.Menu = {
	delay		: 600,
	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)	
			{
				$(".submenu", Menu.menuitem).css({ height: 'auto', zIndex: "" }).stop().hide();
				$(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;
		
		$(".submenu", Menu.menuitem).css({ height: 'auto', zIndex: 100 }).stop().show();	
	}

};

$(function()
{
	/* submenu effectje en timeout */
	Menu.apply("#menu > li");
	
});	
