$(document).ready(function() {
  
  //init fancybox
  
  $('.referenzen a').fancybox();
  
  //slideshow on frontpage
  
  $('#slideshow a').load('/die_lente_wp/referenzen/ .thumb', function() {
    
    $('#slideshow .thumb').wrap('<li />').parent().wrapAll('<ul />').hide().fadeIn('fast');
    var wrappedImg = $(this).find('img');
    var countImg = wrappedImg.length;
    var wrappedImgDimension = wrappedImg.outerWidth(true);
    var containerDimension = countImg * wrappedImgDimension;
    $('#slideshow ul').css('width', containerDimension);
  });

  var first = 0;
	var last = 0;
	var speed = 1000; //set the speed of the animation in miliseconds
	var pause = 4000; //set pause in miliseconds
	
		function removeLast(){
			last = $('div#slideshow ul li:last').html();
			$('div#slideshow ul li:last')
			.hide(function() {$(this).next().remove().end().remove();})
			addFirst(last);			
		}
		
		function addFirst(last, height){
			first = '<li style="display: block; width: 0px;">'+last+'</li>';
			$('div#slideshow ul').prepend(first);
			$('div#slideshow ul li:first')
			.animate({width : 145}, speed );
      // .fadeIn(speed);
      // .slideDown(speed, 'swing', function() {$(this).find('div.item').unwrap();});
		}
	
	interval = setInterval(removeLast, pause);
  
});

