$(document).ready(function() {

	$('#menu img').mouseover( function() {
		$(this).attr('src', 'static/img/knop_' + $(this).attr('id') + '_active.gif' );
	}).mouseout( function() {
		var strHref = window.location.href;
		if( strHref.indexOf( $(this).attr('id') ) == -1 )
			$(this).attr('src', 'static/img/knop_' + $(this).attr('id') + '.gif' );
	}).css('cursor','pointer').
	click( function() {		
		var linkTag = $(this).attr('id');			
		if( linkTag != 'producten' && linkTag != 'behandelingen' && linkTag != 'informatie' )
			window.location = '/' + linkTag;	
	}).each( function() {
		var strHref = window.location.href;
		if( strHref.indexOf( $(this).attr('id') ) > -1 )
			$('#' + $(this).attr('id') ).attr('src', 'static/img/knop_' + $(this).attr('id') + '_active.gif' );
	});
	
	function fadeOutRest()
	{
		$('.behandelingen').fadeOut();	
		$('.producten').fadeOut();	
		$('.informatie').fadeOut();
		fadeOutSubRest();	
	}
	
	function fadeOutSubRest()
	{
		var strHref = window.location.href;
		if( $('.behandelingen').css('display') == 'block' )	
		{
			$('.behandelingen').children('div').unbind().fadeOut();			
			$('.behandelingen').children('div').children('div').fadeOut();
		}
		if( $('.producten').css('display') == 'block' )	
		{
			$('.producten').children('div').unbind().fadeOut();
			$('.producten').children('div').children('div').fadeOut();
		}
		if( $('.informatie').css('display') == 'block' )	
		{
			$('.informatie').children('div').unbind().fadeOut();
			$('.informatie').children('div').children('div').fadeOut();
		}
	}
	
	$('#informatie').unbind().mouseover( function() {
		fadeOutRest();
		if( $('.informatie').css('display') == 'none' )
			$('.informatie').show();	
		
		$('.informatie').children('a').mouseover( function() {
			fadeOut( 'informatie', $(this).attr('id') );			
		});	
	});
	
	$('#behandelingen').unbind().mouseover( function() {
		fadeOutRest();
		if( $('.behandelingen').css('display') == 'none' )
			$('.behandelingen').show();	
		
		$('.behandelingen').children('a').mouseover( function() {
			fadeOut( 'behandelingen', $(this).attr('id') );			
		});	
	});
	
	$('#content, #headerflash').mouseover( function() { fadeOutRest(); fadeOutSubRest(); });
	
	$('#producten').unbind().mouseover( function() {
		fadeOutRest();
		if( $('.producten').css('display') == 'none' )
			$('.producten').show();	
		
		$('.producten').children('a').mouseover( function() {
			fadeOut( 'producten', $(this).attr('id') );		
			
			var overDiv = $(this).attr('id');
			$('.' + $(this).attr('id') ).children('a').mouseover( function() {
				fadeOut( overDiv, $(this).attr('id') );											  
			});
		});	
	});	
	
	function fadeOut( submenu, div )
	{
		$('.' + submenu ).children('div').each( function() {
			$('.' + div ).show();											
			if( $(this).attr('class') != div )
				$(this).hide();	
		});	
	}
	
	$('#send #submit').click( function() {
		$('#loader').html( '<font color="#F69510">De emails worden verzonden, &eacute;&eacute;n moment geduld aub.</font>');		
	});
	
	//forms
	$('#contact #submit').click( function() {
		$('#loader').html( '<img src="http://www.lindaenco.nl/static/img/ajax-loader.gif" alt="loader" /> <font color="#F69510">word verzonden, &eacute;&eacute;n moment geduld aub.</font>');								  
		$.post('contact', { naam : $('#naam').val(), email : $('#email').val(), telefoonnummer : $('#telefoonnummer').val(), opmerkingen : $('#opmerkingen').val() },
		function( data ) {
			$('#loader').html( data );
		});
	});
	
	$('#reactie #submit').click( function() {
		$('#loader').html( '<img src="http://www.lindaenco.nl/static/img/ajax-loader.gif" alt="loader" /> <font color="#F69510">word verzonden, &eacute;&eacute;n moment geduld aub.</font>');								  
		$.post('informatie/Uw reactie', { naam : $('#naam').val(),  email : $('#email').val(), bericht : $('#bericht').val() },
		function( data ) {
				if( data == 'succes<br />' )
				window.location = 'informatie/uw%20reactie/bedankt';
			else
				$('#loader').html( data );
		});
	});
	
	$('#afspraak #submit').click( function() {		   
		$('#loader').html( '<img src="http://www.lindaenco.nl/static/img/ajax-loader.gif" alt="loader" /> <font color="#F69510">word verzonden, &eacute;&eacute;n moment geduld aub.</font>');								  
		$.post('afspraak_maken', { naam : $('#naam').val(),  adres : $('#adres').val(),  datum : $('#datum').val(),  tijd : $('#tijd').val(),  soort : $('#soort option:selected').val(),  postcode : $('#postcode').val(),  woonplaats : $('#woonplaats').val(),  mobielnummer : $('#mobielnummer').val(), email : $('#email').val(), telefoonnummer : $('#telefoonnummer').val(), bericht : $('#bericht').val() },
		function( data ) {
			if( data == 'succes<br />' )
				window.location = 'afspraak_maken/bedankt';
			else
				$('#loader').html( data );
		});
	});
	

});

