	var last="";  
	var lastMode=0;
	var mode=0;  
	var preloader='<p align="left"><img src="/img/ajax-loader.gif" border="0"></p>';                                 
	function goUp() {
		last="-=250%";
		lastMode=1;
		mode=2;
		$('#about_ajax').html(preloader);
$('#about_ajax').load('/index.php?get_element=yes&element_type=page&id_page=about');
		document.title='about';		
	    $("div.block").animate({top: "+=250%"}, 1200);
        return false;
	}
	function goDown() {
		last="+=400%";
		lastMode=2;
		mode=2;
		$('#clients_ajax').html(preloader);
$('#clients_ajax').load('/index.php?get_element=yes&element_type=clients&id_page=clients');			
	    $("div.block").animate({top: "-=400%"}, 1200);
		document.title='clients';
        return false;
	}	
	function goLeft() {
		last="-=300%";
		lastMode=3;
		mode=1;
	$('#photos').load('/index.php?get_element=yes&element_type=portfolio&id_category=6');		
	    $("div.block").animate({left: "+=300%"}, 1200);
		document.title='portfolio';
		//goPort();
        return false;
	}
	function goRight() {
		last="+=300%";
		mode=1;
		lastMode=4;
		$('#contacts_ajax').html(preloader);
$('#contacts_ajax').load('/index.php?get_element=yes&element_type=page&id_page=contacts');		
		document.title='contacts';
	    $("div.block").animate({left: "-=300%"}, 1200);
        return false;
	}	
	function goBack() {
	 if (lastMode>0) {
	 	//alert(last);
		switch (lastMode) {
			case 1:
			$("div.block").animate({top: "-=250%"}, 1200);
			break;
			case 2:
			$("div.block").animate({top: "+=400%"}, 1200);
			break;
			case 3:
			$("div.block").animate({left: "-=300%"}, 1200);
			break;
			case 4:
			$("div.block").animate({left: "+=300%"}, 1200);
			break;
		}
			lastMode=0;
	 }
	}
	
$(document).ready(function(){
$("#load").animate({opacity: "hide"}, 1200);
   /*управление на индексе*/
   $("#index2about").click(
   	function () {
		goUp();
	}
   );
   $("#index2about").hover(function() {
     $(this).attr({ src: 'img/index/about1.png'});
   },function(){
     $(this).attr({ src: 'img/index/about2.png'});
   });
   
   $("#index2clients").click(
   	function () {
		goDown();
	}
   );
   $("#index2clients").hover(function() {
     $(this).attr({ src: 'img/index/clients1.png'});
   },function(){
     $(this).attr({ src: 'img/index/clients2.png'});
   });   

   $("#index2portfolio").click(
   	function () {
		goLeft();
	}
   );
   $("#index2portfolio").hover(function() {
     $(this).attr({ src: 'img/index/portfolio1.png'});
   },function(){
     $(this).attr({ src: 'img/index/portfolio2.png'});
   });   

   $("#index2contacts").click(
   	function () {
		goRight();
	}
   );
   $("#index2contacts").hover(function() {
     $(this).attr({ src: 'img/index/contacts1.png'});
   },function(){
     $(this).attr({ src: 'img/index/contacts2.png'});
   }); 
   
   /*управление на about*/ 
   $("#about2portfolio").click(
   	function () {
		goBack();
		goLeft();
	}
   );
   
   $("#about2portfolio").hover(function() {
     $(this).attr({ src: 'img/about/portfolio2.png'});
   },function(){
     $(this).attr({ src: 'img/about/portfolio1.png'});
   });    
   
   $("#about2clients").click(
   	function () {
		goBack();
		goDown();
	}
   );
   
   $("#about2clients").hover(function() {
     $(this).attr({ src: 'img/about/clients2.png'});
   },function(){
     $(this).attr({ src: 'img/about/clients1.png'});
   });       
   
   $("#about2contacts").click(
   	function () {
		goBack();
		goRight();
	}
   );
   
   $("#about2contacts").hover(function() {
     $(this).attr({ src: 'img/about/contacts2.png'});
   },function(){
     $(this).attr({ src: 'img/about/contacts1.png'});
   });     
   /*конец управления на about*/

   /*управление на contacts*/
   $("#contacts2portfolio").click(
   	function () {
		goBack();
		goLeft();
	}
   );
   
   $("#contacts2portfolio").hover(function() {
     $(this).attr({ src: 'img/contacts/portfolio2.png'});
   },function(){
     $(this).attr({ src: 'img/contacts/portfolio1.png'});
   });    
   
   $("#contacts2clients").click(
   	function () {
		goBack();
		goDown();
	}
   );
   
   $("#contacts2clients").hover(function() {
     $(this).attr({ src: 'img/contacts/clients2.png'});
   },function(){
     $(this).attr({ src: 'img/contacts/clients1.png'});
   });       
   
   $("#contacts2about").click(
   	function () {
		goBack();
		goUp();
	}
   );
   
   $("#contacts2about").hover(function() {
     $(this).attr({ src: 'img/contacts/about2.png'});
   },function(){
     $(this).attr({ src: 'img/contacts/about1.png'});
   });     
   
   /*конец управления на contacts*/
   
   /*управление на clients*/
   $("#clients2portfolio").click(
   	function () {
		goBack();
		goLeft();
	}
   );
   
   $("#clients2portfolio").hover(function() {
     $(this).attr({ src: 'img/clients/portfolio2.png'});
   },function(){
     $(this).attr({ src: 'img/clients/portfolio1.png'});
   });    
   
   $("#clients2contacts").click(
   	function () {
		goBack();
		goRight();
	}
   );
   
   $("#clients2contacts").hover(function() {
     $(this).attr({ src: 'img/clients/contacts2.png'});
   },function(){
     $(this).attr({ src: 'img/clients/contacts1.png'});
   });       
   
   $("#clients2about").click(
   	function () {
		goBack();
		goUp();
	}
   );
   
   $("#clients2about").hover(function() {
     $(this).attr({ src: 'img/clients/about2.png'});
   },function(){
     $(this).attr({ src: 'img/clients/about1.png'});
   });     
   
   /*конец управления на clients*/  
   
   /*управление на portfolio*/  
   var moveInt;
   var leftHide=1;
   var rightHide=0;
   var upMode=1;
   
   $("#CtrlUp").click(
   	function () {
	/*
		if (upMode==1) {
			$(this).attr({ src: 'img/arrow_down.jpg'});
			$("#portfolio_content").animate({top: "-=200px",height: "200%"}, 1200);
			upMode=0;
		} else {
			$(this).attr({ src: 'img/arrow_up.jpg'});
			$("#portfolio_content").animate({top: "+=200px", height: "100%"}, 1200);		
			upMode=1;
		}
	*/
	goPort();
	}
   );   
   
   function goPort() {
		if (upMode==1) {
			$("#CtrlUp").attr({ src: 'img/arrow_down.jpg'});
			$("#portfolio_content").animate({top: "-=200px",height: "200%"}, 1200);
			upMode=0;
		} else {
			$("#CtrlUp").attr({ src: 'img/arrow_up.jpg'});
			$("#portfolio_content").animate({top: "+=200px", height: "100%"}, 1200);		
			upMode=1;
		}   
   }
   
   check();

 $("#photos").ajaxStart(function(){
	$(this).html(preloader);   
 });

   
 $("#photos").ajaxComplete(function(event,request, settings){
   check();
 });
   
   
   function check() {
   	if ($("#photo_move").innerWidth()<$("body").innerWidth()) {
		leftHide=1;
		rightHide=1;
		$("#CtrlRight").hide();
		$("#CtrlLeft").hide();
	} else {
		leftHide=1;
		rightHide=0;
		$("#CtrlRight").show();
		$("#CtrlLeft").hide();	
	}
   }
   
   function moveRight() {
		var offset = $("#photo_move").offset();
		if ((offset.left-10)<30) {
			$("#CtrlLeft").show();
		}
		var pos=$("#photo_move").innerWidth()+offset.left-10;
		if (pos<=$("body").innerWidth()) {
			$("#CtrlRight").hide();
			rightHide=1;
			$("#CtrlRight").attr({ src: '/img/arrow_right.jpg'});
			clearInterval(moveInt);
		} else {
			$("#photo_move").css('left',(offset.left-10)+'px');
		}
		if (leftHide==1) {
			$("#CtrlLeft").show();
		}		
   }

   function moveLeft() {
		var offset = $("#photo_move").offset();
		if ((offset.left+10)>30) {
			$("#CtrlLeft").hide();
			leftHide=1;
			$("#photo_move").css('left','30px');
			$("#CtrlLeft").attr({ src: '/img/arrow_left.jpg'});
			clearInterval(moveInt);
		} else {
			$("#photo_move").css('left',(offset.left+10)+'px');
		}
		if (rightHide==1) {
			$("#CtrlRight").show();
		}
   }
   
   $("#CtrlRight").mousedown(function() {
     $(this).attr({ src: '/img/arrow_right_down.jpg'});
	 clearInterval(moveInt);
	 moveInt=setInterval(moveRight,7);	 
   });
   $("#CtrlRight").mouseup(function() {
     $(this).attr({ src: '/img/arrow_right.jpg'});
	 clearInterval(moveInt);
   });   
      
   $("#CtrlRight").hover(function() {
	$(this).attr({ src: '/img/arrow_right_down.jpg'});
	 moveInt=setInterval(moveRight,7);
   },function(){
     $(this).attr({ src: '/img/arrow_right.jpg'});
	 clearInterval(moveInt);
   }); 	  
	  
   $("#CtrlLeft").mousedown(function() {
	 clearInterval(moveInt);
     $(this).attr({ src: '/img/arrow_left_down.jpg'});
	 moveInt=setInterval(moveLeft,7);	
   });
   $("#CtrlLeft").mouseup(function() {
     $(this).attr({ src: '/img/arrow_left.jpg'});
	 clearInterval(moveInt);
   });   	  
	  
   $("#CtrlLeft").hover(function() {
     $(this).attr({ src: '/img/arrow_left_down.jpg'});
	 moveInt=setInterval(moveLeft,7);	
   },function(){
     $(this).attr({ src: '/img/arrow_left.jpg'});
	 clearInterval(moveInt);
   }); 	  
	  
   $("#portfolio2about").click(
   	function () {
		goBack();
		goUp();
	}
   );
   
   $("ul.control li").hover(function() {
   	//    $(this).toggleClass("selected");
	//    $(this).css({color: '#FFFFFF','text-decoration':'none'});
   },function(){
   	//	$("ul.control li").removeClass("selected");  
	//	$(this).css({color: '#B2B2B2','text-decoration':'underline'});
   });   
   
   $("ul.control li").click(
   function() {
	   $("ul.control li").removeClass("selected");  
	   $("ul.control li").css({color: '#B2B2B2','text-decoration':'underline'}); 
   	   $(this).toggleClass("selected");
	   $(this).css({color: '#FFFFFF','text-decoration':'none'});
   }
   );	   
   
   $("#portfolio2about").hover(function() {
     $(this).attr({ src: 'img/portfolio/about2.png'});
   },function(){
     $(this).attr({ src: 'img/portfolio/about1.png'});
   });    
   
   $("#portfolio2contacts").click(
   	function () {
		goBack();
		goRight();
	}
   );
   
   $("#portfolio2contacts").hover(function() {
     $(this).attr({ src: 'img/portfolio/contacts2.png'});
   },function(){
     $(this).attr({ src: 'img/portfolio/contacts1.png'});
   });       
   
   $("#portfolio2clients").click(
   	function () {
		goBack();
		goDown();
	}
   );
   
   $("#portfolio2clients").hover(function() {
     $(this).attr({ src: 'img/portfolio/clients2.png'});
   },function(){
     $(this).attr({ src: 'img/portfolio/clients1.png'});
   });     
   
   /*конец управления на portfolio*/       
   
   /*конец управления на индексе*/
   $(".goback").click(function() {
   		goBack();
   });    
});