//$('.popup').click(function(){$('#modal-window').modal();return false;});//
//Галлерея на стартовой странице
function indexPageGallery(){
	var current = ($('#iCollage img.show')?$('#iCollage img.show'):$('#iCollage img:first'));
	//Берем следующую картинку
	var next = ((current.next().length)?((current.next().hasClass('caption'))?$('#iCollage img:first'):current.next()):$('#iCollage img:first'));	
	//Фейд эффект
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	//Скрываем текущее изображение
	current.animate({opacity: 0.0}, 1500).removeClass('show');
}
//Функционал стартовой страницы
function gallery(){
	if($("#iCollage img").length>0){
		//всем картинкам нулевую прозрачность
		$('#iCollage img').css({opacity: 0.0});
		//Первая картинка видна и имеет класс - отображается
		$('#iCollage img:first').css({opacity: 1.0}).addClass('show');
		//Запускаем по таймеру функцию
		$('#iCollage img:last').load(function () {
			setInterval('indexPageGallery()',7000);
		});
	}
	return false;
}
//----------------------------------------------
$(function(){

	if($("#iCollage img").length>1){gallery();}else{$('#iCollage img:first').css({opacity: 1.0}).addClass('show');}
	/*Обработчики*/
	$('a.scrollerButton')
		.click(function(e){e.stopPropagation();var position = $('a[name="' + $(this).attr('href').replace('#', '')+ '"]').position();$('html,body').animate({ scrollTop: position.top }, { duration: 1700, easing: 'easeInOutQuint'});return false;});	
	$(".iMenu a img:not(.act), #smallFooterLogo, #big-logo a img")
		.mouseover(function() { var src = $(this).attr("src").match(/[^\.]+/) + "_.gif";$(this).attr("src",  "." + src);})
		.mouseout(function() {var src = $(this).attr("src").replace("_.gif", ".gif");$(this).attr("src", src);});
	$("div.infoPanel, .footerText").mouseover(function(){$(this).children("div.infoDescription").fadeTo(0, 1);}).mouseout(function(){$(this).children("div.infoDescription").fadeTo(0, 0.6);});
	$('a.map').click(function(){
		$.modal("<img src=\"" + $(this).attr("href") + "\" />", {
			opacity: 80,
			autoResize:true, 
			autoPosition: true, 
			minWidth: 680,			
			maxWidth: 680,
			minHeight: 680,			
			maxHeight: 680,
			appendTo: 'a.map', 			
			closeClass: 'simplemodal-overlay', 
			modal : true
		});
		return false;
	});	
});
