$(document).ready(function(){

	$('footer .subnav').remove();

	if ($('nav:eq(0) li:eq(0)').hasClass('active')) {
		$('.subnav').css('left', $('nav:eq(0) li:eq(0) a').position().left);
	} else {
		$('.subnav').css('left', $('nav:eq(0) li:eq(0) a').position().left-5);
	}

	$('.subnav:eq('+($('.subnav').size()-2)+')').css('margin-left', '98px');
	$('.subnav:last').hide();
	$('.subnav a.activeS').css('font-size', '18px');
	$('.subnav:visible:last a.activeS').css('font-size', '24px');


	$('html').css('background-image','url('+$('body').attr('data-bg')+')');

	$('body').css('height',$(window).height()-11);

	$(window).bind("resize", function(){
		$('body').css('height',$(window).height()-11);
		if ($('nav:eq(0) li:eq(0)').hasClass('active')) {
			$('.subnav').css('left', $('nav:eq(0) li:eq(0) a').position().left);
		} else {
			$('.subnav').css('left', $('nav:eq(0) li:eq(0) a').position().left-5);
		}		
	});



	$(".photo").lightBox();
	$(".imageLink").lightBox();
	
	var slideDownInterval;
	var slideUpInterval;
	var slideDownInterval2;
	var slideUpInterval2;
	var slidePhotoLeft;
	var slidePhotoRight;

	$('.topScroll, .topScrollFlex').hover(function(){
		slideUpInterval = setInterval(function(){
			$('.text').scrollTop($('.text').scrollTop()-10);
			$('.textBio').scrollTop($('.textBio').scrollTop()-10);
			$('.content').scrollTop($('.content').scrollTop()-10);
			$('.pubContent').scrollTop($('.pubContent').scrollTop()-10);
		},50);
	},function(){
		clearInterval(slideUpInterval);
	});

	$('.bottomScroll, .bottomScrollFlex').hover(function(){
		slideDownInterval = setInterval(function(){
			$('.text').scrollTop($('.text').scrollTop()+10);
			$('.textBio').scrollTop($('.textBio').scrollTop()+10);
			$('.content').scrollTop($('.content').scrollTop()+10);
			$('.pubContent').scrollTop($('.pubContent').scrollTop()+10);
		},50);
	}, function(){
		clearInterval(slideDownInterval);
	});

/*
	$('.topScrollFlex').mousedown(function(){
		slideUpInterval = setInterval(function(){
			if ($('.contentwrapper').position().top<0){
				$('.contentwrapper').css('top',$('.contentwrapper').position().top+10);
			}else{
				$('.contentwrapper').css('top','0px');
			}
		},50);
	}).mouseup(function(){
		clearInterval(slideUpInterval);
	});

	$('.bottomScrollFlex').mousedown(function(){
		slideDownInterval = setInterval(function(){
			min = ($('.contentwrapper').height()-355)*(-1);
			console.log(min);
			if ($('.contentwrapper').position().top>min){
				$('.contentwrapper').css('top',$('.contentwrapper').position().top-10);
			}else{
				$('.contentwrapper').css('top',min);
			}
		},50);
	}).mouseup(function(){
		clearInterval(slideDownInterval);
	});	
*/
	$('.topScrollPub').mousedown(function(){
		slideUpInterval2 = setInterval(function(){
			if (parseInt($('#flexcroll_02_contentwrapper').css('top'))<0){
				$('.contentwrapper').css('top',parseInt($('#flexcroll_02_contentwrapper').css('top'))+10);
			}else{
				$('.contentwrapper').css('top','0px');
			}
		},50);
	}).mouseup(function(){
		clearInterval(slideUpInterval2);
	});

	$('.bottomScrollPub').mousedown(function(){
		slideDownInterval2 = setInterval(function(){
			min = ($('#flexcroll_02_contentwrapper').height()-305)*(-1);
			position = parseInt($('#flexcroll_02_contentwrapper').css('top'));
			next = parseInt($('#flexcroll_02_contentwrapper').css('top'))-10;
			if (parseInt($('#flexcroll_02_contentwrapper').css('top'))>min){
				$('#flexcroll_02_contentwrapper').css('top',next);
			}else{
				$('#flexcroll_02_contentwrapper').css('top',min);
			}
			position = $('#flexcroll_02_contentwrapper').position().top;
		},50);
	}).mouseup(function(){
		clearInterval(slideDownInterval2);
	});	

	var maxPhotoWidth = -793;
	$('.photos img').bind('load', function(){
		maxPhotoWidth += $(this).width()+10;
		console.log(maxPhotoWidth);
	});
	//var maxPhotoWidth = $('.photos img').length*280-793;
	
	// Скрллер фоток по горизонтали
	$('.scrollRight, .next').hover(function(){
		slidePhotoLeft = setInterval(function(){
			if (parseInt($('.photos').css('margin-left'))>(maxPhotoWidth*(-1))){
				$('.photos').css('margin-left',(parseInt($('.photos').css('margin-left'))-10));
			}
		},50);
	},function(){
		clearInterval(slidePhotoLeft);
	});
	$('.scrollLeft, .prev').hover(function(){
		slidePhotoRight = setInterval(function(){
			if (parseInt($('.photos').css('margin-left'))<0){
				$('.photos').css('margin-left',(parseInt($('.photos').css('margin-left'))+10));
			}
		},50);
	},function(){
		clearInterval(slidePhotoRight);
	});
	
});

