// JavaScript Effects

	
	function hideExMenu() {
		$("#expressmenu ul").stop();
		$("#expressmenu ul").slideUp("normal");

	}
	
	function showExMenu() {
		$("#expressmenu ul").stop();
		$("#expressmenu ul").slideDown("normal");
	}
	
	disableScrollButtons = false;
	
	function scrollNextPage() {
		if (disableScrollButtons) return;
		thisscroll = parseInt($("#scrolled").css("margin-top"));
		tabheight = parseInt($("#mangle").height());
		contentheight = parseInt($("#scrolled").height());
		
		
		if (contentheight>(Math.abs(thisscroll)+tabheight)) {
			disableScrollButtons = true;
			$("#scrolled").animate({
			marginTop: thisscroll-tabheight,
			}, 1000, function() {testContentScroll(); disableScrollButtons = false; } );
	  	}
	}
	
	function scrollBackPage() {
		if (disableScrollButtons) return;
		thisscroll = parseInt($("#scrolled").css("margin-top"));
		tabheight = parseInt($("#mangle").height());
		contentheight = parseInt($("#scrolled").height());
		
		if (thisscroll<0) {
			disableScrollButtons = true;
			$("#scrolled").animate({
			marginTop: thisscroll+tabheight,
			}, 1000, function() { testContentScroll(); disableScrollButtons = false;  }  );
	  	}
	}
	
	function testContentScroll() {
		backbutton = false;
		forthbutton = false;
		
		thisscroll = parseInt($("#scrolled").css("margin-top"));
		
		tabheight = parseInt($("#mangle").height());
		contentheight = parseInt($("#scrolled").height())-6;
		
		if (contentheight>(Math.abs(thisscroll)+tabheight)) {
			forthbutton = true;
		}
		
		if (thisscroll<0) {
			backbutton = true;
		}
		
		if (backbutton) EnableScrollButtonBack(); else DisableScrollButtonBack();
		if (forthbutton) EnableScrollButtonForth(); else DisableScrollButtonForth();
	}
	
	function EnableScrollButtonBack() { $("#naviback").show(); }
	function EnableScrollButtonForth() { $("#naviforth").show(); }
	function DisableScrollButtonBack() { $("#naviback").hide(); }
	function DisableScrollButtonForth() { $("#naviforth").hide(); }
	
	function ContentHide() {
		$("#scrolled").animate({
        opacity: 0
      }, 500 );
	}
	
	function ContentShow() {
		disableScrollButtons = true;
		$("#scrolled").css("margin-top", "0px");
		$("#scrolled").animate({
        opacity: 1
      }, 500, function() { testContentScroll(); disableScrollButtons = false;  } );
	}
	
	slidescrollDesable = false;
	
	function SlideScrollLeft() {
		if (slidescrollDesable) return;
		slideledt = parseInt($(".slidescrolled").css("margin-top"));
		swidth = parseInt($(".slidesself").height());
		if ((slideledt+swidth)>0) { return; }
		slidescrollDesable = true;
		if (IEtest) { // IE fix
			$(".slidescrolled").css("margin-top", ((slideledt + swidth)==0) ? "0px" : (slideledt + swidth));
			slidescrollDesable = false;
		} else {
		$(".slidescrolled").animate({
							 opacity: 0		
									}, 400, function() {
										$(".slidescrolled").css("margin-top", slideledt + swidth);
											$(this).animate({
														opacity: 1 
														 }, 400, function() { slidescrollDesable = false; });
									});
		}
	}
	
	function SlideScrollRight() {
		if (slidescrollDesable) return;
		slideledt = parseInt($(".slidescrolled").css("margin-top"));
		
		swidth = parseInt($(".slidesself").height());
		
		if (Math.abs(slideledt-swidth)>=$(".slidescrolled").height()) return;
		if (IEtest) { // IE fix
		$(".slidescrolled").css("margin-top", slideledt - swidth);
		slidescrollDesable = false;
		} else {
		$(".slidescrolled").animate({
							 opacity: 0		
									}, 400, function() {
										$(".slidescrolled").css("margin-top", slideledt - swidth);
											$(this).animate({
														opacity: 1 
														 }, 400, function() { slidescrollDesable = false; });
									});
		}
	}
	
	function HideIntro() {
		$("#intromovie").hide();
		$("#intro").animate({
        opacity: 0
      }, 2000, function() { $("#intro").css('display', 'none'); } );
	}
	
	function HideAllContent() {
	
	  $("#pagehead").animate({
        opacity: 0
      }, 0);
	  $("#footer").animate({
        opacity: 0
      }, 0 );
	  hideExMenu();
	 $("#bgonimage").animate({
        opacity: 0
      }, 0, function() { $("#bgonimage").css("visibility", "hidden"); } );
	 $("#contentwrapper").animate({
        opacity: 0
      }, 0 );
	 $("#contentnavi").animate({
        opacity: 0
      }, 0 );
	  
	}
	
	function ShowAllContent() {
	  $("#pagehead").animate({
        opacity: 1
      }, 1500, function() {
		  $("#bgonimage").css("visibility", "visible");
		  $("#bgonimage").animate({
        opacity: 0.75,
      }, 2000, function() {
				showExMenu();
			  $("#contentwrapper").animate({
				opacity: 1
			  }, 0 );
			  $("#contentnavi").animate({
				opacity: 1
			  }, 0, function() {
				  $("#footer").animate({
					opacity: 1
				  }, 0 ); 
			  });
		  
	  		});
		  
	  } );
	}
	
	function releaseSite() {
		HideAllContent();
		setTimeout(function() { rs_step1(); }, 500);	
	}
	
	function rs_step1() {
		$("#zanaves").animate({
        opacity: 0
      }, 1000, function() {
		 $("#zanaves").hide();
		 setTimeout(function() { rs_step2(); }, 3200);
	  });
		
	}
	
	function rs_step2() {
		$("#intro").css("background-color", "white");
		HideIntro();	
		setTimeout(function() { 
							$("#bgzanaves").animate({
										opacity: 0
													}, 2000, function() { $("#bgzanaves").hide(); } );
							ShowAllContent(); }, 2000);
	}
	
	  DisableExpressMoveSens = false; 	
	  ExBreak = false;
	  Direction = 0;
	  
	  function E_MoveUp() {
		  	  if (ExBreak==true) { ExBreak=false; return false;  }
		  	  if (DisableExpressMoveSens==true) return false;
			  slider = $("#expressslider");
			  slidemargin = parseInt(slider.css('margin-top'));
			  exslid = $("#expressmenu");
			  movezonetop = exslid.height()/8;
			  movezonebottom = (exslid.height()/8)*7;
			  mposition = globale.pageY-(exslid.position().top);//+$("#wrapper").position().top+16+$("#infobox").height()
			 
			 
			  // Определяем направление
			  if (mposition<movezonetop) Direction=2;
			  if (mposition>movezonebottom) Direction=1;
			  if (mposition<=movezonebottom && mposition>=movezonetop) Direction=0;
			 
			  switch (Direction) {
				case 1:// двигаемся вниз
				  if (Math.abs(parseInt(slider.css('margin-top')))>slider.height()-exslid.height()-32) return false;
				 	DisableExpressMoveSens = true;
				  slider.animate({'marginTop':slidemargin-32}, 200, function() { DisableExpressMoveSens=false; E_MoveUp(); });
				break;
				case 2:// двигаемся вверх
				  if (slidemargin>=0) return false;
				 
					 DisableExpressMoveSens = true;
				  slider.animate({'marginTop':slidemargin+32}, 200, function() { DisableExpressMoveSens=false; E_MoveUp(); });
				break;
				case 0:
					return false;
				break;
			  }
	  }
	  
	  globale = false;
	  
	 $(document).ready(function(){
								
								$("#expressmenu").mouseover(function(e) {
									ExBreak=false;
									globale = e;
									E_MoveUp();
								});
								$("#expressmenu").mousemove(function(e) {
									ExBreak=false;
									globale = e;
									E_MoveUp();
								});
								
								$("#expressmenu").mouseout(function(e) {
									Direction=0;
									ExBreak=true;
								});
			});
								
								
