$(document).ready(function() {		
	slideShow(4000);
	tooltip();
	initToggle();
	$('a[class~="neu"]').attr({target: "_blank"});

});


function slideShow(speed) {
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
	$('ul.slideshow li').css({opacity: 0.0});
	$('ul.slideshow li:first').css({opacity: 1.0});
	$('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
	$('#slideshow-caption p').html($('ul.slideshow a:first').find('img').attr('alt'));
	$('#slideshow-caption').css({opacity: 0.7, bottom:0});
	var timer = setInterval('gallery()',speed);
	$('ul.slideshow').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 2500);
	$('#slideshow-caption').animate({bottom:-70}, 900, function () {
			$('#slideshow-caption h3').html(title);
			$('#slideshow-caption p').html(desc);				
			$('#slideshow-caption').animate({bottom:0}, 1100);	
	});		
	current.animate({opacity: 0.0}, 1000).removeClass('show');
}


function tooltip()
{
  $("img.tooltip").mouseover(    
    function (event) 
    { 
      var text = this.alt;
      x = event.pageX+3;
      y = event.pageY+3;
      $("body").append("<div id='tooltip'>"+text+"</div>");
      $("#tooltip").css("left", x).css("top", y);
    }
  );

  $("img.tooltip").mouseout(
    function (event)
    {
      $("#tooltip").remove();
    }
  );
}


function initToggle() {
  $('.tt-detaildaten ul').hide();
  $('.tt-detaildaten .show').click(
    function() {
        $(this).next().slideToggle('slow');	
      }
    );
  }
