$(document).ready(function(){

	//Fauler Bildlader
	if(!navigator.userAgent.toLowerCase().match('ipad')) { $("img").lazyload({effect : "fadeIn"}); };

	//Elastic textarea for comments
	$('#comment').elastic();
	
	// Smooth scrolling
    $('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;
	   }

	});

	// Script for animated labels in comment form
    $('#commentform label').each(function(){
        var restingPosition = '28px';

        // style the label with JS for progressive enhancement
        $(this).css({
                'position' : 'relative',
                'top' : restingPosition,
                'left' : '5px',
                'display' : 'inline',
                'z-index' : '99',
                'color' : '#999'
        });

        var inputval = $(this).next().val();

        // grab the label width, then add 5 pixels to it
        var labelmove = '0';

        // onload, check if a field is filled out, if so, move the label out of the way
        if(inputval !== ''){
            $(this).stop().animate({ 'top':'-'+labelmove }, 1);
        }    	

        // if the input is empty on focus move the label to the left
        // if it's empty on blur, move it back
        $('input, textarea').focus(function(){
            var label = $(this).prev('label');
            var adjust = '0';
            var value = $(this).val();

            if(value == ''){
                label.stop().animate({ 'top':'-'+adjust }, 'fast');
            } else {
                label.css({ 'top':'-'+adjust });
            }
        }).blur(function(){
            var label = $(this).prev('label');
            var value = $(this).val();

            if(value == ''){
                label.stop().animate({ 'top':restingPosition }, 'fast');
            }	

        });
    }) // End "each" statement   
	
});
