$(document).ready(function(){
	
	$i	=	1;		
	$t	=	5000;	//Timeout - Wartezeit
	$a	=	750;	//Animationsdauer
	//$w 	=	654;	//breite eines list-item
	$w	=	((5)*($('.rotator-item').outerWidth(true)));	//breite list-item
	$s	=	5;		//Anzahl "slides"
		
	$('.rotator-wrap').hover(function(){
		clearInterval(interval);
	}, function(){
		slider();
		$('.tooltip').remove();
	});	

	$('.indicator:first-child').addClass('active-slider');
	
	$('.indicator').click(function(){
		$('.indicator').removeClass('active-slider');
		$(this).addClass('active-slider');
		$className = $(this).attr('class');
		$number	=	$className.substr(13, 1);
		$i	=	$number - 1;
		$('.rotator-list').stop(true, false).animate({'marginLeft' :  -$w * $i + 'px'}, $a);
	});
	
	slider	=	function(){
		$t	=	5000;
		interval = setInterval(function(){
			if($i<$s){
				$('.rotator-list').animate({'marginLeft' :  -$w * $i + 'px'}, $a);
				$i++;
			} else {
				$i	=	1;
				$('.rotator-list').animate({'marginLeft' :  '0px'}, $a);
			};
			setTimeout(function(){
				$('.indicator').removeClass('active-slider');
				$('.gt-'+$i).addClass('active-slider');
			}, $a/2);
			$('.tooltip').remove();
		}, $t);
	};
	
	$('.rotator-item').hover(function(){
		$id		=	$(this).attr('vehicleid');
		$lang	=	$(this).attr('lang');
		$(this).addClass('loading');
		$.post("extensions/extension_tooltip.php", {id: $id, lang: $lang}, function(data) {
			if($('.rotator-item:hover').hasClass('loading')){
				$('#wrapper').append('<div class="tooltip">' + data + '</div>');	
			}
		});		
	},function(){
		$('.tooltip').remove();
		$(this).removeClass('loading');
	});
	
	$(document).mousemove(function(e){
    	$('.tooltip').css({
    	   left:  e.pageX + 10 + "px",
    	   top:   e.pageY + 10 + "px"
    	});
	});
	
	slider();

});
