
// Google Analytics

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26598519-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();



(function ($, window, document, undefined) {
	var validator = {};
	
	validator.phone = function (input) {
		return (/^\+?[\d+\(\)\/]{3,}$/).test(input.replace(/\s+/, ''));
	};

	validator.mail = function (input) {
		return (/^\w[\w\d\.-]*@\w[\w\d\.-]*$/i).test(input.replace(/\s+/, ''));
	};

	validator.name = function (input) {
		return (/[a-z]/i).test(input);
	};
	
	validator.message = 'Es wurde ein Pflichtfeld nicht bzw. ungültig ausgefüllt!';
	
	validator.presence = function (input) {
		return input.replace(/\s+/,'') !== '';
	};
	
	
	$(function () {
		var legend = $('#comments legend.errors');
		
		$('header').cover({
			src: [
				'images/slides/visual1.2.jpg',
				'images/slides/visual2.2.jpg',
				'images/slides/visual3.2.jpg'
			],
			duration: 2000,
			timeout: 9000,
			loader: 'images/loader.gif',
			position: 'left 40%',
			play: true
		});
		

		if (!$.browser.msie) {
			$('#navigation > ul > li > a').each(function () {
				var link = $(this), over = link.clone();

				link.after(over.addClass('hover').css({
					position: 'absolute', left: 0, top: 0, opacity: 0 }));

				over.hover(
					function () {
						over.stop().animate({ opacity: 1 }, 300);
						link.stop().animate({ opacity: 0 }, 300);
					},
					function () {
						over.stop().animate({ opacity: 0 }, 600);
						link.stop().animate({ opacity: 1 }, 600);					
				});
			});
		}				

		
		$('#comments input, #comments textarea').each(function () {
			var input = $(this), label = input.data('label'),
				validate = (input.data('validate') || '').split(/\s/);
			
			if ($.inArray('presence', validate) >= 0) {
				label += '*';
			}
			
			if (label) {
				
				if (!input.val()) {
					input.val(label);
				}
				
				input.focusin(function () {
					input.removeClass('invalid');

					if (input.val() === label) {
						input.attr('value', '');
					}
				});
				
				input.focusout(function () {
					var errors = false;
					
					if (!input.val()) {
						input.val(label);
					}
					else {
						$.each(validate, function () {
							if (validator[this] && !validator[this](input.val() || '')) {
								errors = true;
							}
						});
					}

					input[errors ? 'addClass' : 'removeClass']('invalid');
					legend.html(input.parent().find('.invalid').length ? validator.message : '');
					
				});
			}
			
		});
		
		
		$('form#comments').submit(function () {
			$(this).find('input, textarea').each(function () {
				var input = $(this), label = input.data('label');
				if (input.val().replace(/\*$/, '') === label) {
					input.val('');
				}
				
			});
		});
		
	});
	
})(jQuery, this, this.document);

