$(function(){
	$('.box604').hover(function(){
		a = $(this);
		class_ = a.attr('rel');
		class_ = 'box604 '+class_+' box604Hovered '+class_+'Hovered'; // генерим названия классов (ие же не понимает конструкции .class1.class2)
		a.attr('class',class_);
		a.find('.cw').stop().animate({ // увеличиваем высоту блока до 69
			height:89
		},300);
		a.find('.hint').css({ // сбрасываем параметры подсказки на дефолтные
			opacity:0,
			display:'block'
		}).stop().animate({ // показываем подсказку
			opacity:1
		},200);
	},function(){
		a = $(this);
		class_ = a.attr('rel');
		class_ = 'box604 '+class_;
		a.attr('class',class_);
		a.find('.hint').stop().animate({ // прячем подсказку
			opacity:0
		},300,function(){
			$(this).hide(); // прячем до конца
		});

		a.find('.cw').stop().animate({ // вертаем высоту блока обратно
			height:44
		},300);
	});

	lastSupply.ready();
});

lastSupply = function(){
	var count,bprev,bnext,wrapper,inner,offset,scroller,direction;
	function ready(){
		offset = 0;
		items = $('.ls-item');
		count = items.length;
		bprev = $('.ls-scroll-prev');
		bnext = $('.ls-scroll-next');
		wrapper = $('.ls-scroller-wrapper');
		inner = $('.ls-scroller-inner');
		direction = -1;

		if (count<=1) {
			bprev.hide();
			bnext.hide();
		} else {
			bprev.click(function(){
				window.clearInterval(scroller);
				if (!inner.is(':animated')) {
					scroll(1);
				};
			});
			bnext.click(function(){
				window.clearInterval(scroller);
				if (!inner.is(':animated')) {
					scroll(-1);
				};
			});
			bprev.hide();
			height = items.eq(0).height();
			wrapper.height(height);
			bnext.css({
				top:height+50
			}).show();
		};

		scroller = window.setInterval(function(){
				if (!inner.is(':animated')) {
					scroll(direction);
				};}, 5000);
                $(".ls-item").hover(function(){
                                window.clearInterval(scroller);
                                });

	};
	function scroll(dir) {
		nextOffset = offset+dir;
		if (dir<0) {
			height = items.eq(Math.abs(offset)).height();
			inner.animate({
				marginTop:'-='+height+'px'
			},300);
			wrapperHeight = items.eq(Math.abs(offset)+1).height()
		} else {
			height = items.eq(Math.abs(offset)-1).height();
			inner.animate({
				marginTop:'+='+height+'px'
			},300);
			wrapperHeight = items.eq(Math.abs(offset)-1).height()
		};
		wrapper.animate({
			height:wrapperHeight
		},300);
		bnext.animate({
			top:wrapperHeight+50
		},300);
		offset = nextOffset;
		check();
	};
	function check(){
		if (offset == 0) {
			bprev.hide();
			bnext.hide().show();
			direction = -1;
		} else if (Math.abs(offset) >= (count-2)) {
			bprev.show();
			bnext.hide();
			direction = 1;
		} else {
			bprev.show();
			bnext.hide().show();
		}
	};

	return {
		ready:ready
	};
}();


