//animated background-images in nav...

// functie om te checken voor aanwezigheid actieve submenu
function checkForSub() {
	
	$('ul.nav_sub').each( function() {
		$(this).addClass('hide');
		var $isActive = $(this).prev().hasClass('active');
	//	console.log($isActive);
	//	alert($isActive);
		if ($isActive) { $(this).addClass('show').removeClass('hide'); }
		else { $(this).addClass('hide').removeClass('show') }
	})
	
}

// functie voor tonen en verbergen van witte pagina overlay
function modalOverlay(actie) {
	   var $winheight = $('body').height()+100;
	   var $winwidth = $('body').width()+100;
	
	switch(actie) {
		case "show":
 			$("#wit_overlay").fadeIn(1000).fadeTo('slow', 0.8).css({height:$winheight, width:$winwidth});
			$("html").css("overflow","hidden");		
			break;
		
		case "close":
			$("#wit_overlay").fadeOut(); 
			$("html").css("overflow","scroll");
			break;			 
	}
}
// functie voor het sluiten van modal windows
function closeModal() {
	$(".modal").fadeOut('slow');
	modalOverlay("close");  	
	$("#zoeken_cont").fadeOut("1000");
}

$(function(){
	
	checkForSub();

	$('div#guestbook .items').jScrollPane();
	$('div#foto .items').jScrollPane();
	$('div#video .items').jScrollPane();
	
	
	$('.nav_main a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -39px)"}, {duration:250})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200})
		});
					
	$('.nav_main a.active')
		.css( {backgroundPosition: "0 -78px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -39px)"}, {duration:250})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -78px)"}, {duration:200})
		});
	
	$('.nav_sub a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -38px)"}, {duration:1})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:1})
		});
		
	$('.nav_sub a.active')
		.css( {backgroundPosition: "0 -76px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -38px)"}, {duration:1})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -76px)"}, {duration:1})
		});		
		
	// sluit modal windows
	$("a.sluit").bind("click", function(e) { closeModal() });
	
	// toon zoek baby modal window
	$("#zoekeenbaby").click( function(e) {
		e.preventDefault();
		modalOverlay("show");
		var $top = $(this).offset().top;
		//var $old_left = $(this).offset().left - $(this).width();
		var $left = $('#nav').offset().left + $('#nav').width() - ($('#zoeken_cont').width() + $('#zoeken_cont').offset().left) - 40;
		$("#zoeken_cont").fadeIn("1000").css({top:$top,left:$left});		   
	});
	
	// toon gastenboek modal window
	$("#gastenboek_btn").click( function(e) {
		e.preventDefault();
		modalOverlay("show");
		if(!($.browser.msie && $.browser.version < 7 ))	{
			var $winH = $(window).height()/2 - 200;  
			var $winW = $(window).width()/2 - 200;
			$("#gastenboek_cont").css({top: $winH, left: $winW });	
		}
		
		// Zeker weten dat gastenboek direct aan <body> hangt. Fijn he, IE?
		//$('body').append($("#gastenboek_cont"));
		
		$("#gastenboek_cont").fadeIn();
	});
	
	// toon add babyfoto modal window
	$("#addbabyfoto_btn").click( function(e) {
		e.preventDefault();
		modalOverlay("show");
		if(!($.browser.msie && $.browser.version < 7 ))	{
			var $winH = $(window).height()/2 - 200;  
			var $winW = $(window).width()/2 - 200;
			$("#addbabyfoto_cont").css({top: $winH, left: $winW });	
		}

		// Zeker weten dat addbabyfoto direct aan <body> hangt. Fijn he, IE?
		//$('body').append($("#addbabyfoto_cont"));
		
		$("#addbabyfoto_cont").fadeIn();
	});
  
	// toon add babyvideo modal window
	$("#addbabyvideo_btn").click( function(e) {
		e.preventDefault();
		modalOverlay("show");
		if(!($.browser.msie && $.browser.version < 7 ))	{
			var $winH = $(window).height()/2 - 200;  
			var $winW = $(window).width()/2 - 200;
			$("#addbabyvideo_cont").css({top: $winH, left: $winW });	
		}

		// Zeker weten dat addbabyfoto direct aan <body> hangt. Fijn he, IE?
		//$('body').append($("#addbabyvideo_cont"));

		$('#addbabyvideo_frame').attr('src', $('#addbabyvideo_action').val());
    
		$("#addbabyvideo_cont").fadeIn();
	});

	// toon login modal window	
	$('a.btn_showlogin').click( function() {
		var isLogged = $(this).hasClass('logged');
		var isOpen = $(this).hasClass('open');

		if (isLogged) {
			// do nothing

			return true;
		}
		else {
			if(isOpen) {
				$("#login_content").fadeOut();
				$(this).parent().animate({height:'25px'},500);
				$(this).toggleClass('open');
			} else {
				$(this).toggleClass('open');
				$(this).parent().animate({height:'150px'},500, function(){ $("#login_content").fadeIn(); } );
			}
		}

		return false;
	});	

	// toon namen van babiess
	$("ul.babygallery li a").hover(
		function(){  $(this).children('.name').fadeIn('slow'); },
		function(){  $(this).children('.name').fadeOut('fast'); }
	);

});
