$(document).ready(function(){ 	
	/**************************************************************************************************************************************************
	Move Conatiner
	***************************************************************************************************************************************************/
	// Referenzen/Kunden 
	$("#kundenliste .setposition, #referenzenalle .alignbtm, #referenzen a").hover(
		function () {
			$(this).find(".overlaybox").stop().animate({top:'0px'}, 250);
		}, 
		function () {
			var height = $(this).height();
			$(this).find(".overlaybox").stop().animate({top:'100%'}, 250);
		}
	);
	
	// Social Icons
	$("#icons_social div").hover(
		function () {
			$(this).animate({bottom:'10px'}, 150);
		}, 
		function () {
			$(this).animate({bottom:'0px'},150);
		}
	);
	
	/**************************************************************************************************************************************************
	Swap Images
	***************************************************************************************************************************************************/
	// Image swap on hover
	$("#showcase li img").hover(function(){
			$('#main-img').attr('src',$(this).attr('src').replace('thumb/', ''));
	});
	// Image preload
	var imgSwap = [];
	 $("#showcase li img").each(function(){
			imgUrl = this.src.replace('thumb/', '');
			imgSwap.push(imgUrl);
	});
	$(imgSwap).preload();	
	/**************************************************************************************************************************************************
	Clear Form Inputs
	***************************************************************************************************************************************************/
	var clearMePrevious = '';
	
	// clear input on focus
	$('input.clearme').focus(function()
	{
		if($(this).val()==$(this).attr('value'))
		{
			clearMePrevious = $(this).val();
			$(this).val('');
		}
	});
	// if field is empty afterward, add text again
	$('input').blur(function()
	{
		if($(this).val()=='')
		{
			$(this).val(clearMePrevious);
		}
	});
	/**************************************************************************************************************************************************
	Navigation
	***************************************************************************************************************************************************/
	$("ul.sf-menu").superfish({ // "ul.sf-menu" ist die ID vom Navigations Container
		delay:      1000, // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
		speed:      250, // speed of the animation in ms
		pathClass:  'current' // "current" ist der Name der class, die den aktiven link kennzeichnet
	}); 
	/**************************************************************************************************************************************************
	Collapse
	***************************************************************************************************************************************************/
	// Merke: Container für den Inhalt ist ein div, ul oder p DIREKT nach dem h3 Tag
	$("body").collapse({show: function(){
			this.animate({
				opacity: 'toggle', 
				height: 'toggle'
			}, 300);
		},
		hide : function() {
			this.animate({
				opacity: 'toggle', 
				height: 'toggle'
			}, 300);
		}
  });
	
});

/**************************************************************************************************************************************************
	Image Preload
***************************************************************************************************************************************************/
$.fn.preload = function() {
	this.each(function(){
			$('<img/>')[0].src = this;
	});
}

/**************************************************************************************************************************************************
	Check Forms
***************************************************************************************************************************************************/
function checkEingaben() {
	var Vorname = document.mail.Vorname.value;
	var Nachname = document.mail.Nachname.value;
	var Mail = document.mail.Mail.value;
	var Nachricht = document.mail.elements["Nachricht"].value;

	if (Vorname=='') {
		window.alert('Geben Sie bitte Ihren Vornamen ein.');
		document.mail.Vorname.style.border="1px solid #FF6400";
		document.mail.Vorname.focus();
		return false;
	}
	
	if (Nachname=='') {
		window.alert('Geben Sie bitte Ihren Nachnamen ein.');
		document.mail.Nachname.style.border="1px solid #FF6400";
		document.mail.Nachname.focus();
		return false;
	}
		
	if (Mail=='') {
		window.alert('Geben Sie bitte Ihre E-Mail Adresse ein.');
		document.mail.Mail.style.border="1px solid #FF6400";
		document.mail.Mail.focus();
		return false;
	}
	var str=document.mail.Mail.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		// testresults=true;
	} else {
		window.alert("Geben Sie bitte eine gültige E-Mail Adresse ein!");
		document.mail.Mail.style.border="1px solid #FF6400";
		document.mail.Mail.focus();
		return false;
	}
	
	if (Nachricht=='') {
		window.alert('Geben Sie bitte Ihre Nachricht ein.');
		document.mail.Nachricht.style.border="1px solid #FF6400";
		document.mail.Nachricht.focus();
		return false;
	}
}
