jQuery.noConflict();
jQuery(document).ready(function($){

// Target Blank
$('.newwindow').each(function(){
	$(this).attr('onClick','window.open(this.href); return false;');
});

// Portfolio
$("#box-slider-1").easySlider({	'continuous':true,'nextId':"nextproject",'prevId':"lastproject",'controlsShow':false,'auto':true,'pause':15000,'speed':500 });
$("#box-slider-2").easySlider({	'continuous':true,'nextId':"nextproject",'prevId':"lastproject",'controlsShow':false,'auto':true,'pause':15000,'speed':500,'vertical':true });
$("#nextproject a,#lastproject a").click(function(){ return false; });

// Contactform
$("#contactform").attr('action','contact.php');
$("#contactform").validate({
	errorPlacement: function(error,element){},
	'submitHandler': function(form){
		$(form).ajaxStart(function(){
			$('#result').html('<div class="loader">Nachricht senden</div>');
		}).ajaxError(function(){
			$('#result').html('<div class="failure">Fehlgeschlagen</div>');
			alert('Das senden der Nachricht ist Fehlgeschlagen. Bitte versuchen Sie es erneut oder benutzen Sie die links stehende Email-Adresse.');
		}).ajaxSubmit({
			'target': "#result",
			'success':function(){
				$(form).find('input,textarea').attr({'readonly':'readonly'}).addClass('readonly');
				$(form).find('input.submit').attr({'disabled':'disabled'}).addClass('readonly');
			}
		});
	}
});

// Email
$(".email").html('<a href="mailto:inbox@elpato.info" title="Email schreiben">inbox@elpato.info</a>');

// SmoothScroll
$('a[href*=#]').click(function() {

   // duration in ms
   var duration=1000;

   // easing values: swing | linear
   var easing='swing';

   // 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 }, duration, easing, function() {

         // add new hash to the browser location
         window.location.href=newLocation;
      });

      // cancel default click action
      return false;
   }

});

});