$(function(){

	var $slideshow = $('.slideshow');
	
	if($slideshow.length){
	
		$slideshow.each(function(){
	
			var $this = $(this),
				$lenta = $this.find('.lenta ul'),
				$blocks = $lenta.find('li'),
				$prev = $this.find('.prev'),
				$next = $this.find('.next'),
				$img = $this.find('.window img'),
				pos = 0,
				w = -100,
				lim = $blocks.length - 3;
			
			$prev.hide();
			if($blocks.length <= 3) $next.hide();
			
			$prev.click(function(){
				if(pos > 0){
					pos--;
					$lenta.stop().animate({ left:pos*w }, 100);
					if (pos <= 0) {
						$prev.hide();
					}
					$next.show();
				}
			});
			
			$next.click(function(){
				if(pos < lim){
					pos++;
					$lenta.stop().animate({ left:pos*w }, 100);
					if (pos >= lim) {
						$next.hide();
					}
					$prev.show();
				}
			});
			
			$blocks.click(function(){
				var $li = $(this),
					addr = $li.find('a').attr('href');
				
				$blocks.removeClass();
				$img.attr('src', addr);
				$li.addClass('act');
				return false;
			})
			
		});
	
	}

})
