/*
 * Alles pas laden als het document gereed is
 */
$(document).ready( function()
{
	
	/**
	 * Acties voor de google field
	 * 
	 * Zorgt dat het google logootje verdwijnt als er
	 * getyped wordt.
	 * 
	 * Eerst checken of het veld wel leeg is
	 */
	if ( $('.googlefield').attr('value') ) $('.googlefield').addClass('focus');
	
	$('.googlefield').focus( function()
	{
		$(this).addClass('focus');
	});
	
	$('.googlefield').blur( function()
	{
		// Alleen weer terug gaan als het veld nog leeg is!!
		if ( !$(this).attr('value') ) $(this).removeClass('focus');
	});
	
	
	/**
	 * Submit actie voor Google
	 * 
	 * Zorgt ervoor dat google getoond wordt in de site zelf
	 */
	$('form[name="googlesearch"]').submit( function()
	{
		//Search query
		var query = $('.googlefield').attr('value');
		
		$('#body_secondwrap').animate( {height:"246px"}, 'normal', 'linear', function()
		{	
			// CALLBACK
			$(this).animate( {height:"585px"}, 'normal', 'linear', function()
			{
				// CALLBACK
				$(this).prepend('<iframe src="http://www.google.nl/cse?q=' + query + '&hl=nl&cx=001797921389887845606:lvsohpucj08&cof=FORID:9&ie=UTF-8" width="518" height="565" frameborder="no" style="margin-top: 25px; display: none;" id="googleframe"></iframe>');
				
				// Fade de frame in
				$('#googleframe').fadeIn('normal');
			});
		});
		
		$('#body_secondwrap *').fadeOut('normal');
		
		return false;
	});
	
	
	/**
	 * Acties voor bij de login form
	 * 
	 * Dit stukje zorgt ervoor dat het informatie tekst
	 * tevoorschijn komt en verdwijnt bij de nodige
	 * situaties
	 */
	/*
	 * Username field focus en blur
	 */
	$('input[name="login_username"]').focus( function()
	{
		if ( $(this).attr('value') == 'Gebruikersnaam' ) $(this).attr('value', '');
			
		$(this).css('color', '#555');
	});
	
	$('input[name="login_username"]').blur( function()
	{
		if ( !$(this).attr('value') )
		{
			$(this).css('color', '#999');
			$(this).attr('value', 'Gebruikersnaam');
		}	
	});
	
	/*
	 * password field focus en blur
	 */
	$('input[name="login_password"]').focus( function()
	{
		if ( $(this).attr('value') == 'Wachtwoord' ) $(this).attr('value', '');
			
		$(this).css('color', '#555');
	});
	
	$('input[name="login_password"]').blur( function()
	{
		if ( !$(this).attr('value') )
		{
			$(this).css('color', '#999');
			$(this).attr('value', 'Wachtwoord');
		}	
	});
	
	
	/**
	 * Actie voor de footer
	 * 
	 * Bij mouseover wordt de tekst van de footer
	 * duidelijker om te lezen (donker tekst)
	 */
	$('#footer span').hover(
		function()
		{
			$(this).css('color', '#333');
		},
		function()
		{
			$(this).css('color', '#999');
		}
	);
	
	
	/**
	 * Functie voor de sidebar headers
	 * 
	 * Deze functie zorgt ervoor dat je items in de sidebar
	 * open en dicht kunt klappen
	 */
	$('#sidebar_content div span').click( function()
	{
		// Verkrijg status van de huigige item
		var visible = $(this).parent().find('p').is(':visible');
		
		// Klap alle visible texten dicht
		$('#sidebar_content div p:visible').hide( 'blind' );
		
		// Klap de huidige item open als hij nog niet open was
		if ( visible == false ) $(this).parent().find('p').show( 'blind' );
		
		return false;
	});
	
	
	// Open het eerste sidebar item
	$('#sidebar_content div:first p').show();
	
	
	// Submit on enter - Inlog form
	$('[name="login_username"], [name="login_password"]').keypress( function(e)
	{
		// Set placeholder for the keycode
		var keycode = e.which;
		
		// If the keycode was 13 (enter) submit the form
		if ( keycode == 13 ) document.login_member.submit();
		
		// The tab switch
		else if ( keycode == 0 )
		{
			// Get active field
			var currentField = $(this).attr( 'name' );
			
			// Blur this field
			$(this).blur();
			
			// Focus the password field
			if ( currentField == 'login_username' )$('[name="login_password"]').focus();
			
			// or else the username field
			else $('[name="login_username"]').focus();
			
			// Return false to skip the actuall tab switch
			return false;
		}
		
		return true;
	});

});