/**
 *	Copyright:
 * 	Florian Brinker 2011
 *	
 */
 
jQuery(function() {

	var menu 		= $('.pageMenu');
	var articles 	= $('.article');
		
	// menu above the articles
		articles.mouseenter(function() {
			// clone menu if neccessary
			if($(this).find('.pageMenu').length == 0)
				$(this).prepend(menu.clone());
			// display menu
			articles.find('.pageMenu').hide();
			$(this).find('.pageMenu').fadeIn();
		}).mouseleave(function() {
			// hide menu
			$(this).find('.pageMenu').fadeOut();
		});
		
	// autofocus / IE focus fix
		$('.autofocus').focus();
		
		$('input').focus(function() {
			$(this).addClass('formFocus');
		}).blur(function() {
			$(this).removeClass('formFocus');
		});
		$('textarea').focus(function() {
			$(this).addClass('formFocus');
		}).blur(function() {
			$(this).removeClass('formFocus');
		});
		$('button').focus(function() {
			$(this).addClass('formFocus');
		}).blur(function() {
			$(this).removeClass('formFocus');
		});
		
	// contactForm
		$('#contactForm').submit(function(evt) {		
			evt.preventDefault();
			$('#contactForm').slideUp();
			$('#inputError').fadeOut(50);
			$('#inputRoger').fadeOut(50);
			
			var name 	= $('#contactFormName').val();
			var mail 	= $('#contactFormEmail').val();
			var msg		= $('#contactFormMsg').val();
			
			if(0 < name.length && 0 < mail.length && 0 < msg.length) {
				$.ajax({
					url 	: 'contact.php?form=send&ajax=yes',
					type	: 'POST',
					data	: {
						'name'	: name,
						'mail'	: mail,
						'msg'	: msg
					},
					success	: function() {
						$('#inputRoger').fadeIn();
						$('#contactFormName').val('');
						$('#contactFormEmail').val('');
						$('#contactFormMsg').val('');
					},
					error	: function() {
						$('#inputMailingError').fadeIn();
						$('#contactForm').slideDown();
					}
				});
			}
			else {
				$('#inputError').fadeIn();
				$('#contactForm').slideDown();
			}
		});
		
	// piwikOptOut
		setTimeout(function() {
			$('#piwikOptOut').contents().html();
		}, 1000);

});
