$(function(){
	
	// slide-down images
	$('#body_home #work li').hover(function(){
		$(this).find('img').animate({top:'80px'},{queue:false,duration:500});
	}, function(){
		$(this).find('img').animate({top:'0px'},{queue:false,duration:500});
	});
});

$(document).ready(function() {
  function filterPath(string) {
    return string
      .replace(/^\//,'') 
      .replace(/(index|default).[a-zA-Z]{3,4}$/,'') 
      .replace(/\/$/,'');
  }
  $('a[href*=#]').each(function() {
    if ( filterPath(location.pathname) == filterPath(this.pathname)
    && location.hostname == this.hostname
    && this.hash.replace(/#/,'') ) {
      var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
      var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
       if ($target) {
         var targetOffset = $target.offset().top;
         $(this).click(function() {
           $('html, body').animate({scrollTop: targetOffset}, 400);
           return false;
         });
      }
    }
  });
});

function checkform(of)
		{
			var reqfields,em,i,f,ty;
			/* Changes from form example */
			// reading all the labels and placing them in an associative 
			// array
			var labels,fieldnames;
			fieldnames=new Array();
			if(document.getElementsByTagName('label').length>0)
			{
				labels=document.getElementsByTagName('label');
				for(i=0;i<labels.length;i++)
				{
					fieldnames[labels[i].htmlFor]=labels[i].firstChild.nodeValue;
				}
			}
			/* end Changes from form example */
			if(document.getElementById('required'))
			{
				reqfields=document.getElementById('required').value.split(',');
				if(document.getElementById('errormsg')){
					em=document.getElementById('errormsg');
					em.parentNode.removeChild(em);
				}
				for(i=0;i<reqfields.length;i++)
				{
					f=document.getElementById(reqfields[i]);
					if(f.previousSibling && /img/i.test(f.previousSibling.nodeName)){
						f.parentNode.removeChild(f.previousSibling);
					}
					f.style.background='#fff';
					if(f){
						ty=f.type.toLowerCase();
						switch(ty)
						{
							case 'text':
								if(f.value==''){adderr(f.id,fieldnames[f.id],of)}							
								if(f.id=='email' && !isEmailAddr(f.value)){adderr(f.id,fieldnames[f.id],of)}							
							break;
							case 'textarea':
								if(f.value==''){adderr(f.id,fieldnames[f.id],of)}							
							break;
							case 'checkbox':
								if(!f.checked){adderr(f.id,fieldnames[f.id],of)}							
							break;
							/* extend as needed */
						}
					}
					
				}
				
			}
			if(document.getElementById('errormsg'))
			{
				return false;
			}
		}
		function adderr(id,name,of)
		{
		 	var se,i,nli,na,newli;
			i=document.createElement('span');
			se=document.getElementById(id);
			se.parentNode.insertBefore(i,se)
			se.style.background='#FBE94E';
			if(!document.getElementById('errormsg'))
			{
				var em=document.createElement('span');
				em.id='errormsg';
				/*em.appendChild(document.createTextNode('Fuellen Sie bitte folgende Felder aus:'))*/
			/* Changes from form example */
				ul=document.createElement('span');
				ul.id='errorlist';
				em.appendChild(ul);
			/* end Changes from form example */
				for(var i=0;i<of.getElementsByTagName('input').length;i++)
				{
					if(/submit/i.test(of.getElementsByTagName('input')[i].getAttribute('type')))
					{
						var sb=of.getElementsByTagName('input')[i];
						break;
					}
				}
				sb.parentNode.insertBefore(em,sb);
			}
			if(id=='email' && !isEmailAddr(document.getElementById(id).value))
			{
				pn=document.createElement('span');
				/*pn.appendChild(document.createTextNode("Geben Sie nur Buchstaben, Ziffern und \"@-.\"-Zeichen in das Feld \"E-mail\" ein."))	*/
				document.getElementById('errormsg').appendChild(pn);
			}
			/* Changes from form example */
			newli=document.createElement('span');
			/*newli.appendChild(document.createTextNode(name))*/
			document.getElementById('errorlist').appendChild(newli);
			/* end Changes from form example */
		}

		function isEmailAddr(str) 
		{
		    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
		}



function testform(theForm)
{ 
if (theForm.name.value == "")
 {
 alert("Geben Sie einen Wert in das Feld \"Name\" ein.");
 theForm.name.focus();
 return (false);
 }

 if (theForm.name.value.length < 2)
 {
 alert("Geben Sie mindestens 2 Zeichen in das Feld \"Name\" ein.");
 theForm.name.focus();
 return (false);
 }
 
if ((theForm.email.value == "")||(theForm.email.value.indexOf('@') == -1))
 {
 alert("Geben Sie eine gueltige E-Mail-Adresse in das Feld \"E-Mail\" ein.");
 theForm.email.focus();
 return (false);
 }
 var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@-.";
 var checkStr = theForm.Mailadresse.value;
 var allValid = true;
 for (i = 0; i < checkStr.length; i++)
 {
 ch = checkStr.charAt(i);
 for (j = 0; j < checkOK.length; j++)
 if (ch == checkOK.charAt(j))
 break;
 if (j == checkOK.length)
 {
 allValid = false;
 break;
}
}
 if (!allValid)
{
 alert("Geben Sie nur Buchstaben, Ziffern und \"@-.\"-Zeichen in das Feld \"E-mail\" ein.");
 theForm.email.focus();
 return (false);
}
if (theForm.msg.value == "")
 {
 alert("Geben Sie einen Wert in das Feld \"Nachricht\" ein.");
 theForm.msg.focus();
 return (false);
 }

 return (true);
}
