$(document).ready(function(){

$("a.pp, a.fensterln").prettyPhoto({
        counter_separator_label: ' von ',
        slideshow: 5000,
        theme: 'facebook'
    });
    
    

 

  

    
  

$('#eintraege').append('<p class="imp">Impressum</p>');
var sh = 100 + $('#eintraege').height();
$('section:not("#eintraege")').css({top: sh });





$('#laden').ajaxify({
                        target: '#leinwand',
                        tagToload:'#liste',
                        loading_img: 'http://thorsten-konigorski.de/wp-content/themes/neumigrate/bilder/ajax-loader.gif',
                        onError: function() {
                            $('#lesezeichen p.einzublenden').text('Sorry, ich konnte die aktuelle Liste nicht laden.');
                            $('#AjaxifyLoading').fadeOut('slow');
                        },
                        onComplete: function(){ 
                            $('.spy li h4:contains("youtube"), .spy li h4:contains("vimeo")').find('span:eq(1)').text('Video');
                            $('.spy li h4 a[href$="pdf"]').parent().find('span:eq(1)').text('Pdf-Dokument');
                            $('.spy li h4 a[href$="mp3"]').parent().find('span:eq(1)').text('mp3-Datei');                                           
                            $('#liste').mouseover(function() {
                            $(this).find('li:has(h4:contains("Video")) a.flaeche').prettyPhoto({theme: 'facebook'});
                            $(this).find('li:has(h4:contains("Bild")) a.flaeche').prettyPhoto({theme: 'facebook'});
                            });
                            $('.home header p a:eq(1)').click(function() {
        						$('section:visible').fadeOut('fast', function(){
                    			$(this).css({'top':'3000px'});
                    		})
                    		.find('.einzublenden').hide();
        					$('header').animate({top:'28%',marginLeft: '-470px'}, 1000, function(){
                            	$('#lesezeichen .einzublenden').fadeIn('slow');            															                        $('title').html('Thorsten Konigorski &middot; Lesezeichen');
                    		});
	                   		$('#lesezeichen').show().animate({top:'0px'},1000);
                			$('.startlink').slideDown(1000);
                			$('html,body').animate({"scrollTop":'0'},1000);
                			$('header p').fadeOut('fast');
                			return false;
                			}).one("click", function() { $('ul.spy').simpleSpy();  });
                       }    
                       }).click(); 
        
 $('#photos h2:eq(0)').after('<div id="lograhmen"><a href="/aggregat/thumbs.php"></a></div>');
 						$('#lograhmen a').ajaxify({
                        target: '#lograhmen',
                        loading_img: 'http://thorsten-konigorski.de/wp-content/themes/neumigrate/bilder/ajax-loader.gif',
                        onError: function() {
                            $('header p').text('Sorry, ich konnte die aktuelle Liste nicht laden.');
                            $('#AjaxifyLoading').fadeOut('slow');
                        },
                        onComplete: function(){
                        	$('#photos li').each(function () {
								var inhalt = $(this).html();
								var neu = inhalt.replace(/\<br\/?\>\n?.+/igm,'</a>');
								$(this).html(neu);
							 }); 
							 $('#photos img').fadeTo("fast", 0.7)
								.hover(
								function () {
									$(this).stop().fadeTo('slow', 1);
								},
								function () {
									$(this).stop().fadeTo('slow', 0.7);
								}
							);
                             $('.home header p a:eq(0)').click(function() {
								$('section:visible').fadeOut('fast', function(){
                   			 		$(this).css({top:sh});
                  					}).find('.einzublenden').hide();  
               						$('header').animate({top:'0%',marginLeft: '-150px'}, 1000, function(){
                            			$('#photos .einzublenden').fadeIn('slow');            															                        	$('title').html('Thorsten Konigorski &middot; Photos');
                            			$('body').addClass('fixedshuffle'); 
                            			 $('#te').hide();       
                    				});
        							$('html,body').animate({"scrollTop":'0'},1000);
        							$('header p').fadeOut('fast');
        							$('#photos').show().animate({top:'0px'},1000);
        							$('.startlink').slideDown(1000);
									return false;
									}); 
							$('#photos div:last li a')//.attr('rel','prettyPhoto[Matthaeuspassion]')
							.prettyPhoto({
								counter_separator_label: ' von ',
								theme: 'facebook'
							}); 							
                       }
                    }).click();
 
 
      
        
$('.imp').click(function() {
        $('section:visible').fadeOut('fast', function(){
                    $(this).css({top:sh});
                    }).find('.einzublenden').hide();  
        $('header').animate({top: '0%',marginLeft: '-150px'}, 1000, function(){
                  $('#impressum .einzublenden').fadeIn('slow');  
                  $('title').html('Thorsten Konigorski &middot; Impressum'); 
                  $('body').addClass('fixedshuffle');
                  $('#te').hide();        
        });
        $('#impressum').show().animate({top:'0px'},1000);
        $('.startlink').slideDown(1000);
        $('header p').fadeOut('fast');
        $('html,body').animate({"scrollTop":'0'},1000);
        });
        
        
$('.home .startlink').click(function(){
        $('#te').show();
		$('body').removeClass('fixedshuffle');
        $('section:visible').fadeOut('fast', function() {
            $('header').animate({top: '28%',marginLeft:'-390px'}, 1000, function(){
                $('header p').fadeIn('slow');
                $('title').html('Thorsten Konigorski');
                });
            $('.einzublenden').hide();
            $('#eintraege').show().animate({top:'0px'},1000);
            $(this).css({top:sh});
            $('.startlink').slideUp('slow');
      });
    }); 
    
    
$('.single .startlink').click(function(){
	$(this).slideUp('slow',function(){
		location.href='http://thorsten-konigorski.de';
	});
});
     
            
}); //document - ready

$(window).load(function () {
  $('.single .startlink').slideDown('slow');  
  });

/* #############

var nh =  $('#eintraege').height();

jQuery(window).scroll(function () {

                if (jQuery(this).scrollTop() > (nh - 500)) {
                        jQuery('nav span').animate({
                               
                                opacity: 'show'
                        },500);         
                        
                } else {                
                        jQuery('nav span').animate({
                              
                                opacity: 'hide'
                        },1000);        
                }         });



################*/

(function ($) {      //spy

$.fn.simpleSpy = function (limit, interval) {
    limit = limit || 10;
    interval = interval || 6500;

    return this.each(function () {
        var $list = $(this),
            items = [], // uninitialised
            currentItem = limit,
            total = 0, // initialise later on
            height = $list.find('> li:first').height();

        $list.find('> li').each(function () {
            items.push('<li>' + $(this).html() + '</li>');
        });

        total = items.length;

        $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit});

        $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();

       function spy() {
            var $insert = $(items[currentItem]).css({
                height : 0,
                opacity : 0,
                display : 'none'
            }).prependTo($list);

            $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
                 $insert.css({display : 'block'}).animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
                 $(this).remove();
            });

            currentItem++;
            if (currentItem >= total) {
                currentItem = 0;
            }

            setTimeout(spy, interval)
        }

        spy();

    });
};

})(jQuery);
