 $.fn.exists = function () {
    return $(this).length !== 0;
}

 
 $(document).ready(function(){

		function home_menu() {
		$(".menu_home_pasik").animate({width: "477px", opacity: "0.70"},  3000);
		setTimeout(function(){
			$(".menu_home").animate({opacity: "1"}, 1000);
			},
			3000);
		}
		
		function home_backgrounds() {
		$('.home' + n ).fadeIn(1500);
		$('.home' + n ).fadeOut(2000, home_backgrounds );
		n++;
		if ( n > 4 ) { n=1; }
		} 
		
		
		
		
		function bio_next() {
		if ( e < 7 ) {$(".bio_article").scrollTo($('#bio' + e ), 1000); e++; };
		if ( e == 7 ) {$(".next").fadeOut(500);   } ;
		$(".prev").fadeIn(500);
     	}
		
		function bio_prev() {
		if ( e > 2 ) {e--; $(".bio_article").scrollTo($('#bio' + (e - 1) ), 1000);  };
		if ( e == 2  ) {$(".prev").fadeOut(500);   } ;
		$(".next").fadeIn(500);
     	}
		
		var e=2;
		
		
		var n=1;
		var s=5;

		$(".navigation").localScroll({
		   target:".bio_article"
		});
		$(".navigation .prev").fadeOut(1);
		$(".navigation .prev").click(function() {
				bio_prev();
				$(this).css({'color':'#ffffff'});
				$(".next").css({'color':'#a39d9d'});
		});
		
		$(".navigation .next").click(function() {
				bio_next();
				$(this).css({'color':'#ffffff'});
				$(".prev").css({'color':'#a39d9d'});
		});
		
		
		
		$(".sprava").css("opacity","0")
		$(".sprava p").css("opacity","0")
		
		$(".sprava").hover(function() {
				$(this).stop().animate({opacity: "0.95"}, 200);
				$(".sprava p").stop().animate({opacity: "0.95"}, 200);
		},  
		function() {  
				$(this).stop().animate({opacity: "0.01"}, 1000);
				$(".sprava p").stop().animate({opacity: "0.01"}, 1000);
		});
		
		
		
		
		
		$(".news_navigation").localScroll({
		   target:".news_holder"
		});
		

	
		


		$(".news_navigation .next").fadeOut(1);
		
		$(".news_navigation .prev").click(function() {
				
				$(".next").fadeIn(500);
				
				if ($(".activenews").next("div").exists()) {
					//alert($(".active").next("img").exists());
					$(".news_holder").find("div").scrollTo(($(".activenews").next("div")), 500);
					$(".activenews").next("div").addClass("activenews");
					$(".activenews:first").removeClass("activenews");
				} else {
					$(".prev").fadeOut(500);
				}
				
				$(this).css('color','#ffffff');
				$(".next").css({'color':'#a39d9d'});
		});
		
		$(".news_navigation .next").click(function() {

				$(".prev").fadeIn(500);
				
				if ($(".activenews").prev("div").exists()) {
					//alert($(".active").next("img").exists());
					$(".news_holder").find("div").scrollTo(($(".activenews").prev("div")), 500);
					$(".activenews").prev("div").addClass("activenews");
					$(".activenews:last").removeClass("activenews");
				} else {
					$(".next").fadeOut(500);
				}
				
				$(this).css('color','#ffffff');
				$(".prev").css({'color':'#a39d9d'});
		});
		
		
		
		
		
		$(".menu_home_pasik").css("width","0").css("opacity","0");
		$(".menu_home").css("opacity","0");
	
	
		home_menu();
		home_backgrounds();
		
		$(".activeimg").fadeIn(1500);
		
		$("#gallery_next").click(function() {
			
			$(".activeimg").fadeOut(500);
			
			if ($(".activeimg").next("img").exists()) {
				//alert($(".active").next("img").exists());
				$(".activeimg").next("img").fadeIn(500).addClass("activeimg");
				$(".activeimg:first").removeClass("activeimg");
			} else {
				//alert("no");
				$(".activeimg").removeClass("activeimg");
				$(".gallery_holder img:first").fadeIn(500).addClass("activeimg");
			}
		});
		
		$("#gallery_prev").click(function() {
				
			$(".activeimg").fadeOut(500);	
			if ($(".activeimg").prev("img").exists()) {
				//alert($(".active").next("img").exists());
				$(".activeimg").prev("img").fadeIn(500).addClass("activeimg");
				$(".activeimg:last").removeClass("activeimg");
			} else {
				//alert("no");
				$(".activeimg").removeClass("activeimg");
				$(".gallery_holder img:last").fadeIn(500).addClass("activeimg");
			}
			
		});
		

		
		
		$(".partners a").css("opacity",0.3);
		$(".partners a").hover(function(){
			$(this).animate({opacity: 1},300);
		},function(){
			$(this).animate({opacity: 0.3},100);
		});
	
});


