$(document).ready(function(){

	$(".blog .delicious").hide();
	$(".blog .delicious").before('<p class="toggledeliciouswrapper"><span class="toggledelicious">&darr; Linksammlung anzeigen/ausblenden</span></p>');
	$(".toggledelicious").click(function() {
	  	$(this).parent().next(".delicious").slideToggle('slow', function() {
		    // Animation complete.
		  });
	});

    // Image-descrition when hovering an image
	$(".size-full").hover(function(){
			var title = $(this).attr("title");
			if (title != "") {
				$(this).removeAttr("title");					
				$(this).after('<div class=\"imagetitle\">' + title + '</div>');
			}
			$(this).next(".imagetitle").stop(true, true).fadeIn();
		},
		function(){
			$(this).next(".imagetitle").stop(true, true).fadeOut();
	});
    
	// Script for opening the area with meta-information of a post
	$(".metaopener span").click(function () {
      $(".metadata").slideToggle("slow");
    });
    

	//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 p label').each(function(){
        var restingPosition = '25px';

        // 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    

    
});
