/**
 * Различные обслуживающие скрипты для сайта
 */
$(document).ready( function() {
	/**
	 * Выпадающее меню
	 */
	$('.top_menu ul li').hover( function() {
		$(this).addClass("active");// изменяем фон выбранного элемента путем
									// добавления класса active
			$(this).find('ul').stop(true, true); // останавливаем всю текущую
													// анимацию
			$(this).find('ul').slideDown();// находим элемент ul и вызываем
											// анимацию slideDown
		}, function() {
			$(this).removeClass("active");
			$(this).find('ul').slideUp('fast');
		});

	/**
	 * Обработка изменения прозрачности превьюшки при наведении курсора мыши
	 */
	$("div.pages img").css("opacity", "0.4").filter(".active").css("opacity", "1");

	$("div.pages img").mouseover( function() {
		$(this).animate( {
			opacity : "1"
		}, "fast");
	})

	$("div.pages img").mouseout( function() {
		if (!($(this).is('.active'))) {//если это не активная (выбранная) превьюшка
			$(this).animate( {
				opacity : "0.4"
			}, "fast");
		}
	})

	/**
	 * Call slideshow function
	 */
	$( function() {
		setInterval("slideSwitch()", 2000);
	});

	/**
	 * for Pretty Photo prettyPhoto 3.0: Beta
	 * http://www.no-margin-for-errors.com
	 */
	// $("a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook',
	// animationSpeed:'slow'});
	});

/**
 * slideshow on main page
 * 
 * @return
 */
function slideSwitch() {
	var $active = $('#slideshow IMG.active');

	if ($active.length == 0)
		$active = $('#slideshow IMG:last');

	// use this to pull the images in the order they appear in the markup
	var $next = $active.next().length ? $active.next()
			: $('#slideshow IMG:first');

	// uncomment the 3 lines below to pull the images in random order

	// var $sibs = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next = $( $sibs[ rndNum ] );

	$active.addClass('last-active');

	$next.css( {
		opacity : 0.0
	}).addClass('active').animate( {
		opacity : 1.0
	}, 1000, function() {
		$active.removeClass('active last-active');
	});
}

