jQuery.preloadImages = function()
{
 for(var i = 0; i<arguments.length; i++)
 {
  jQuery("<img>").attr("src", arguments[i]);
 }
};

$.preloadImages("images/back.png", "images/back_over.png", "images/back_2.png", "images/next.png", "images/next_b.png", "images/next_2.png","images/norm.png","images/press.png","images/over.png");




 $(document).ready(function(){
    $("#order-button").click(function() {
		$("#form_view").stop(true,true)
                          .animate({opacity: "show", top: "0"}, "fast");
	}, function() {
		$("#form_view").stop(true,true)
                          .animate({opacity: "hide", top: "0"}, "fast");
	});


   
   
    $(".vopros-teaser").click(function () {
        var status=$(this).attr('class');
            if(status=="vopros-teaser active") {
               $(".vopros-teaser").removeClass("active"); 
            }
            else {
                $(".vopros-teaser").removeClass("active");
                $(this).addClass("active"); 
            }
                
    });
    
    
$(".close_form").click(function (){ 
    $("#form_view").stop(true,true)
                          .animate({opacity: "hide", top: "0"}, "fast");
});

$("#order-button").mousedown(function(){
    $(this).removeClass("norm"); 
    $(this).removeClass("over"); 
  $(this).addClass("press");  
});
$("#order-button").mouseup(function(){
    $(this).removeClass("press"); 
    $(this).removeClass("over"); 
  $(this).addClass("norm");  
});

$("#order-button").hover(function(){
  $(this).removeClass("norm");
  $(this).removeClass("press");   
  $(this).addClass("over");   
},
    function(){
        $(this).removeClass("over");
        $(this).removeClass("press");
        $(this).addClass("norm");   
    }
);


$(".catGallery").hover(function(){
    $(this).addClass("active");   
},
    function(){
    $(this).removeClass("active");   
    }
);


//--------------------------------------------
$(".order-by").mousedown(function(){
    $(this).removeClass("norm"); 
    $(this).removeClass("over"); 
  $(this).addClass("press");  
});
$(".order-by").mouseup(function(){
    $(this).removeClass("press"); 
    $(this).removeClass("over"); 
  $(this).addClass("norm");  
});

$(".order-by").hover(function(){
  $(this).removeClass("norm");
  $(this).removeClass("press");   
  $(this).addClass("over");   
},
    function(){
        $(this).removeClass("over");
        $(this).removeClass("press");
        $(this).addClass("norm");   
    }
);
//--------------------------------------------
  });
  
function MyEr() {
		$(".namer").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
	}
    
function MyErUp() {
		$(".namer").stop(true,true).animate({opacity: "hide", right: "0"}, "fast");
	} 

function MyErMail() {
		$(".mailr").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
	}

function MyErMailUp() {
		$(".mailr").stop(true,true).animate({opacity: "hide", right: "0"}, "fast");
	}

function MyErCapcha() {
		$(".capcha").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
	}

function MyErCapchaUp() {
		$(".capcha").stop(true,true).animate({opacity: "hide", right: "0"}, "fast");
	}  

function MyErPhoneUp() {
		$(".phoneError").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
	} 
function MyErPhone() {
		$(".phoneError").stop(true,true).animate({opacity: "hide", right: "0"}, "fast");
	} 
    
    
    
function MyErMessUp() {
		$(".messError").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
	}  
    
function MyErMess() {
		$(".messError").stop(true,true).animate({opacity: "hide", right: "0"}, "fast");
	}     
function organUp() {
		$(".organization").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
	}  
    
function organ() {
		$(".organization").stop(true,true).animate({opacity: "hide", right: "0"}, "fast");
	}     




$(document).ready(function(){
    $(".namer").stop(true,true).animate({opacity: "show", right: "0"}, "fast");	
    $(".messError").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
    $(".phoneError").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
    $(".mailr").stop(true,true).animate({opacity: "show", right: "0"}, "fast");    
    $(".messr").stop(true,true).show(); 
    $(".capcha").stop(true,true).animate({opacity: "show", right: "0"}, "fast");   
    $(".organization").stop(true,true).animate({opacity: "show", right: "0"}, "fast");
 }); 




$(document).ready(function(){
    $(".messr").click(function() {
		 $(this).hide();
	});
    
	if ($("#photogalery").size() != 0){
	   
       $('#photogalery .arrow_right').hover (
        
        function(){$(this).addClass("hover_a"); },
        function(){$(this).removeClass("hover_a");}
        
        );
        
         $('#photogalery .arrow_left').hover (
        
        function(){$(this).addClass("hover_b"); },
        function(){$(this).removeClass("hover_b");}
        
        );
    
		var width_img = 115;
		var width_big = 157;
		var width_mar = 4;
		var width_outer = 638;
		var time = 500;
		var vol = $("#photogalery .inner").children().size();
		var width_inner =  vol * (width_img + width_mar) + (width_big - width_img);
		var state = 0;
	
    	var mar = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;
	    var num = -mar/(width_img+width_mar)+2;
	    $('#photogalery a').removeClass('active');
        $('#photogalery a:eq('+num+')').addClass('active');
      	$('#photogalery img:eq(2)').addClass('big');
		var mar_left = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;
        
				if (mar_left == 0){ 
					$('#photogalery .arrow_left').css('background-position','center');
                    
                    
				}else{
					$('#photogalery .arrow_left').css('background-position','right');
	                       			
                    }
                
				if ((width_inner + mar_left) <= width_outer){ 
					$('#photogalery .arrow_right').css('background-position','center)');
				}else{ 
					$('#photogalery .arrow_right').css('background-position','bottom');
				}
                
		$('#photogalery .arrow_right').click(function(){
        
			if (state == 0){
				state = 1;
				var mar_left = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;
				if ($("#photogalery .inner").css('margin-left') == 'auto'){
					var mar_left = 0;
				}
				if ((width_inner + mar_left) > width_outer){
					var new_mar = mar_left - 119 + 'px';
					$("#photogalery .inner").animate({marginLeft: new_mar}, time);
					$('.big').animate({width: width_img, height: '150px', marginTop: '54px'},time);
					$('#photogalery img').removeClass('big');
					var mar = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;
                    
					var num = -mar/(width_img+width_mar) + 3;
                    
					$('#photogalery img:eq('+num+')').animate({width: width_big, height: '226px', marginTop: '14px'},time);
					$('#photogalery img:eq('+num+')').addClass('big');	
                    $('#photogalery a').removeClass('active');
                    $('#photogalery a:eq('+num+')').addClass('active');
                    
				} else {}
				setTimeout(function(){
					state = 0;
					var mar_left = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;
					if (mar_left >= 0){
						$('#photogalery .arrow_left').css('background-position','center center');
					}else{
						$('#photogalery .arrow_left').css('background-position','bottom center');
					}
					if ((width_inner + mar_left) <= width_outer){
						$('#photogalery .arrow_right').css('background-position','center center');
					}else{
						$('#photogalery .arrow_right').css('background-position','bottom center');
					}
				},500);
			}
		})	
		
        $('#photogalery .arrow_left').click(function(){
        
			if (state == 0){
				state = 1;
				var mar_left = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;	
				if (mar_left < 0){
					var new_mar = mar_left + 119 + 'px';
					$("#photogalery .inner").animate({marginLeft: new_mar}, time);

					$('.big').animate({width: width_img, height: '150px', marginTop: '54px'},time);
					$('#photogalery img').removeClass('big');
					var mar = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;
					var num = -mar/(width_img+width_mar) + 1;
					$('#photogalery img:eq('+num+')').animate({width: width_big, height: '226px', marginTop: '14px'},time);
					$('#photogalery img:eq('+num+')').addClass('big');
                    $('#photogalery a').removeClass('active');
                    $('#photogalery a:eq('+num+')').addClass('active');
				} else {}
				setTimeout(function(){
					state = 0;
					var mar_left = $("#photogalery .inner").css('margin-left').slice(0,-2) - 0;
					if (mar_left >= 0){
						$('#photogalery .arrow_left').css('background-position','center center');
					}else{
						$('#photogalery .arrow_left').css('background-position','center bottom');
					}
					if ((width_inner + mar_left) <= width_outer){
						$('#photogalery .arrow_right').css('background-position','center center');
					}else{
						$('#photogalery .arrow_right').css('background-position','center bottom');
					}
				},500);	
			}
		})
	}
});





