$(document).ready(function() {
	
	/*
		Aleksey Skubaev

		askubaev@gmail.com
		icq - 322253350
		Разработка шаблонов для DLE и кроссбраузерная верстка
		------------------
		Необходимые jQuery скрипты.
	
	*/
	
	//  Расставление правых пунктов
	var sliderRightItem = $('.slider-item-small');
	var SlidreRightItemSdvig = 12;
	for (i=0; i<sliderRightItem.length; i++)
		{
			$(sliderRightItem[i]).css({'top' : SlidreRightItemSdvig});
			var SlidreRightItemSdvig = SlidreRightItemSdvig + 74;
		}	
		
	// Задаем первый элемент слайдера
	$('.slider-item:first').addClass('slider-item-active');
	$('.slider-item-big:first').fadeIn();
	var sliderTime = 8000;//скорость слайдера

	// Расчет отступа для ссылки
	var sliderLeftItem = $('.slider-item-big:first');
	var SliderItemTitleHeight = sliderLeftItem.find('h2').height();
	sliderLeftItem.find('.slider-item-big-link').css({'bottom' : SliderItemTitleHeight +35});
		
	
	// Перелистывание слайдера
	function showNext() {
		clearTimeout(timerId);
		var currentBlock = $('.slider-item-active');
		var nextBlock = currentBlock.next('.slider-item').length ? currentBlock.next('.slider-item') : $('.slider-item:first');
		$('.slider-item-big').fadeOut(0);
		$('.slider-item').removeClass('slider-item-active');
		nextBlock.addClass('slider-item-active');
		nextBlock.find('.slider-item-big').fadeIn();
		
		var SliderItemTitleHeight = nextBlock.find('h2').height();
		nextBlock.find('.slider-item-big-link').css({'bottom' : SliderItemTitleHeight +35});
		
		timerId = setTimeout(showNext, sliderTime);
	}
	
	function showHover() {
		clearTimeout(timerId);
		$('.slider-item-big').fadeOut(0);
		$('.slider-item').removeClass('slider-item-active');
		
		var currentBlock = $(this).parent();
		var nextBlock = currentBlock.next('.slider-item').length ? currentBlock.next('.slider-item') : $('.slider-item:first');
		currentBlock.addClass('slider-item-active');
		
		currentBlock.find('.slider-item-big').fadeIn(0);
		
		var SliderItemTitleHeight = currentBlock.find('h2').height();
		currentBlock.find('.slider-item-big-link').css({'bottom' : SliderItemTitleHeight +35});
		
		timerId = setTimeout(showNext, sliderTime);
	}
	
	$('.slider-item-small').hover(showHover);
	
	timerId = setTimeout(showNext, sliderTime);
	
});
