$(document).ready(function() {
	
	$('section.job a.button').attr('href', 'mailto:welcome@visor3000.com');
	

	
	
	/* $.get("slides.html", function(data) { */
	$("#portfolio-slider")
		// .append(data)
		.wrapInner('<div class="slidewrap"><div id="welcome-slides" class="slider"></div></div>')
		.find(".slidewrap")
			.carousel({
				slide: '.slide',
				addPagination: true,
				addNav : false 
			});
			
		$("#studio")
		// .append(data)
		.wrapInner('<div class="studiowrap"><div id="studio-slides" class="slider"></div></div>')
		.find(".studiowrap")
			.carousel({
				slide: '.agency',
				addPagination: false,
				addNav : true 
			});
}); 
				

// jQuery SmoothScroll | Version 10-04-30

$('a[href*=#]').not('ul.slidecontrols a').not('ol.carousel-tabs a').click(function() {
	 // get / set parameters
	 var newHash=this.hash;
	 var target=$(this.hash).offset().top;
	 var oldLocation=window.location.href.replace(window.location.hash, '');
	 var newLocation=this;
	 // make sure it's the same location      
	 if(oldLocation+newHash==newLocation)
	 {
			// animate to target and set the hash to the window.location after the animation
			$('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, 800, function() {
				// add new hash to the browser location
				 window.location.href=newLocation;
			});
		// cancel default click action
			return false;
	 }
});		
			
$('#contactform').bind('submit', function(e){
	e.preventDefault();
	var data = 'xhr=1&name='+$('#fname').val()+'&email='+$('#femail').val()+'&msg='+$('#fmsg').val();
	console.log(data);
	$.ajax({
	  url: "contact.php",
	  type: 'POST',
	  data: data,
	  dataType: 'json',
	  success: function(data){
		// unset errors
		$('#contactform input').removeClass('error');
		$('#contactform textarea').removeClass('error');
		$('#contactform span.error').text(' ');
		if(data.code != 1){
			console.log('error accoured');
			if(data.errors.name && data.errors.name.length > 0){
				$('#err-name').text(data.errors.name);
				$('#fname').addClass('error');
			}
			if(data.errors.email && data.errors.email.length > 0){
				$('#err-email').text(data.errors.email);
				$('#femail').addClass('error');
			}
			if(data.errors.msg && data.errors.msg.length > 0){
				$('#err-msg').text(data.errors.msg);
				$('#fmsg').addClass('error');
			}
		} else {
			$('#formResponse').html('<h3>Vielen Dank für Deine Nachricht!</h3>');
			$('#contactform').remove();
		}
	  },
	  error: function(){
		console.log('request error');
	  }
	});
});























