$(document).ready(function()
{
	var time_animation = 200;
	var time_opacity = 200;
	var to;
	function przesun()
	{
		$("#first .desc").css("width", "250px");
		$(".moved").animate({left:"+=500px"}, time_animation);
		$(".moved").addClass("move").removeClass("moved");
		$("#first .desc").animate({left: "0px"}, time_animation);
		$(".desc").not("#first .desc").animate({left:"-290px", width: "300px"}, time_animation);
	}
	$(".move").mouseenter(function()
	{
		$(".desc").animate({left:"-290px", width: "290px"}, time_animation);
		$(this).prevAll(".move:not(.moved)").andSelf().not(".moved").animate({left:"-=500px"}, {duration:"slow", easing: 'easeOutQuart' });		
		$(this).prevAll(".move:not(.moved)").andSelf().not(".moved").addClass("moved");
		$(this).nextAll(".moved").animate({left:"+=500px"},{duration: time_animation, easing: 'easeInCubic' });
		$(this).nextAll(".moved").removeClass("moved");
		$("#first .desc").children("span").animate({opacity:0}, 100);
	});
	
	$(".move, #first").hover(function(){
		to = $(this);
		$(this).data('timeout', setTimeout(function(){
			to.not("#first").children(".desc").animate({left:"0", width: to.children(".desc").children("span").children("img").width()}, {duration: time_animation, easing: 'easeOutCubic' });		
			to.children(".desc").children("span").delay(100).animate({opacity:1}, 500);
		}, 200));
	}, function(){
		$("*").stop(false,true);
		to = $(this);
		to.children(".desc").not("#first .desc").children("span").animate({opacity:0}, 100);
		clearTimeout($(this).data('timeout'));
	});
	
	$("#container").mouseleave(function()
	{
		$(".desc").stop(true,true);
		$(".desc").not("#first .desc").children("span").animate({opacity:0}, 100);
		$("#first .desc").children("span").delay(100).animate({opacity:1}, 500);
		przesun();
	});
	$("#first").mouseenter(function()
	{
		przesun();
	});
});
