function theRotator() {
	$('div#slide img').css({opacity: 0.0});
 
	// Берем первую картинку и показываем ее (по пути включаем полную видимость)
	$('div#slide img:first').css({opacity: 1.0});
 
	// Вызываем функцию rotate для запуска слайдшоу, 5000 = смена картинок происходит раз в 5 секунд
	setInterval('rotate()', 12000);
}
 
function rotate() {	
	// Берем первую картинку
	var current = ($('div#slide img.show')?  $('div#slide img.show') : $('div#slide img:first'));
 
	// Берем следующую картинку, когда дойдем до последней начинаем с начала
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#slide img:first') :current.next()) : $('div#slide img:first'));	
 
	// Расскомментируйте, чтобы показвать картинки в случайном порядке
	//var sibs = current.siblings();
	//var rndNum = Math.floor(Math.random() * sibs.length );
	//var next = $( sibs[ rndNum ] );
 
	// Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1800);
 
	var nextIndex = curIndex + 1;
	if (nextIndex >= bg_images.length)
			nextIndex = 0;
	document.cookie = 'slides_curr=' + nextIndex + '; path=/';
	
	// Прячем текущую картинку
	current.animate({opacity: 0.0}, 1800, function(){

		$(this).attr('src', bg_images[curIndex]);
		curIndex++;
		if (curIndex >= bg_images.length)
			curIndex = 0;
		
	}).removeClass('show');
};

$(window).scroll(function() {
	var scroll = $(document).scrollTop();
	var offset = $('#cat_tree').offset().top + $('#cat_tree').height();
	
	if (scroll > offset && !$('#to_top').is(':visible'))
	{
		$('#to_top').css('left', $('#main').offset().left + 75);
		$('#to_top').show();
	}
	
	if (scroll <= offset && $('#to_top').is(':visible'))
	{
		$('#to_top').hide();
	}
});

$(window).resize(function(){
	if ($('#to_top').is(':visible'))
		$('#to_top').css('left', $('#main').offset().left + 75);
});

$(document).ready(function() {
	preload(new Array('/des/spoiler_hover.png', '/des/spoiler_arrow_up.png'));
	
	$('.in_content .spoiler .spoiler_head').click(function(){
		$(this).next().slideToggle('normal', function(){
			if($(this).is(':visible'))
				$(this).prev().find('img').attr('src', '/des/spoiler_arrow_up.png');
			else
				$(this).prev().find('img').attr('src', '/des/spoiler_arrow_down.png');
		});
	});
	
	$('.in_content .spoiler .spoiler_head').hover(
		function(){
			$(this).css('background', 'url(/des/spoiler_hover.png)');
		},
		function(){
			$(this).css('background', 'url(/des/spoiler.png)');
		}
	);
});
