$(function() {
	
	// Hide sub navigation
	hideSubNavigation();
	
	// Show active sub navigation
	$('#nav ul.first_level_ul li.active').children().show();
	
	// First level navigation 
	$('#nav ul.first_level_ul').children('li').hover(			
		function() {
			hideSubNavigation();
			$(this).children('ul.second_level_ul').show();
		},		
		function() {
			// Do nothing
		}
	);
	
	// Hide sub navigation when leaving the navigation area and display the active sub navigation items
	$('#nav').hover(			
		function() {
			// Do nothing
		},
		function() {			
			hideSubNavigation();
			$('#nav ul.first_level_ul li.active').children().show();
		}
	);
	
	// Newsletter
	$('#newsletter_name')
		.val('NAME')
		.focus( function() {
			$(this).val('');
			$(this).css('color', '#000');
		});
	
	$('#newsletter_email')
		.val('E-MAIL')
		.focus( function() {
			$(this).val('');
			$(this).css('color', '#000');
		});
	
	
	$('#newsletter_submit').click(function(){
		$(this).attr('disabled', 'true');
		var name = $('#newsletter_name').val();
		var email = $('#newsletter_email').val();
		
		$.ajax({
			url: 'newsletter.php',
			type: 'POST',
			data: { 'name': name, 'email': email },
			dataType: 'json',
			success: function(data){
									
				if (data.result == 'SUCCESS')
				{
					$('#newsletter_name').val('');
					$('#newsletter_email').val('');
					alert('Vielen Dank für Ihre Anmeldung!');						
				}
				else
				{
					if (data.errorName != '')
					{
						$('#newsletter_name').css('color', '#ff0000').val(data.errorName);
					}
					if (data.errorEmail != '')
					{
						$('#newsletter_email').css('color', '#ff0000').val(data.errorEmail);
					}
				}
				
				// Enable newsletter submit button again
				$('#newsletter_submit').removeAttr('disabled');
				
			}	
		});
		
		return false;
	});
		
	
	// Cycle
	$('#cycle') 
     	.cycle({ 
        	fx:      'fade', 
            speed:   300, 
            timeout: 5000, 
            next:   '#cycle_next', 
    		prev:   '#cycle_prev',
            pause:   1
       });

	
});


function hideSubNavigation() {
	$('#nav ul.second_level_ul').hide();
}


