$(document).ready(function(){
    $(".portprev").hover(
	        function() {
	            $(this).find('.prevtxt').stop(true, true);
	            $(this).find('.prevtxt').slideDown(200);
	        },
	        function() {
	            $(this).find('.prevtxt').slideUp(200);
	        }
    );
    
    $("a[rel=fancybox]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Фото ' + (currentIndex + 1) + ' из ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
	});
    
    if(!$("#orderform .formnote").text()==""){
        alert($("#orderform .formnote").text());
        $("#orderform .formnote").css("padding","18px 0 52px 0")
    }    

    
    $("#orderbutton").fancybox({
		'type'	: 'inline',
        'overlayOpacity':'0',
        'transitionIn':'none',
        'transitionOut':'none',
        'padding':'0'
    });

    $("#orderbutton1").fancybox({
		'type'	: 'inline',
        'overlayOpacity':'0',
        'transitionIn':'none',
        'transitionOut':'none',
        'padding':'0'
    });
    
    $("#orderbutton2").fancybox({
		'type'	: 'inline',
        'overlayOpacity':'0',
        'transitionIn':'none',
        'transitionOut':'none',
        'padding':'0'
    });
    
    $("#orderbutton3").fancybox({
		'type'	: 'inline',
        'overlayOpacity':'0',
        'transitionIn':'none',
        'transitionOut':'none',
        'padding':'0'
    });    

    $("#orderbutton4").fancybox({
		'type'	: 'inline',
        'overlayOpacity':'0',
        'transitionIn':'none',
        'transitionOut':'none',
        'padding':'0'
    });    

     $("#orderbutton0").fancybox({
		'type'	: 'inline',
        'overlayOpacity':'0',
        'transitionIn':'none',
        'transitionOut':'none',
        'padding':'0'
    });     
    
    
    $(".morehover").hover(function(){
        $(this).css("z-index","100");
        $(this).children(".abshow").show();
    },function(){
        $(this).children(".abshow").hide()
        $(this).css("z-index","0");
    });
    
/* ********************************** */
    if(!$("#orderform .inputtext,#orderform1 .inputtext,#orderform2 .inputtext,#orderform3 .inputtext,#orderform4 .inputtext,#orderform0 .inputtext").attr("value")){
        $("#orderform .inputtext,#orderform1 .inputtext,#orderform2 .inputtext,#orderform3 .inputtext,#orderform4 .inputtext,#orderform0 .inputtext").attr("value",function(){
            return $(this).next(".htitle").attr("title")   
        });        
    }

    
    $("#orderform .inputtext,#orderform1 .inputtext,#orderform2 .inputtext,#orderform3 .inputtext,#orderform4 .inputtext,#orderform0 .inputtext").focus( function(){
        if($(this).attr("value")==$(this).next(".htitle").attr("title")){
            $(this).attr("value","");
            $(this).css("color","#000");
        }
    });
    $("#orderform .inputtext,#orderform1 .inputtext,#orderform2 .inputtext,#orderform3 .inputtext,#orderform4 .inputtext,#orderform0 .inputtext").blur( function(){
        if($(this).attr("value")==""){
            $(this).attr("value",function(){
                return $(this).next(".htitle").attr("title") 
            });
            $(this).css("color","#000");
        }
    });
    
    
    var form="#orderform form";
    var form1="#orderform1 form";
    var form2="#orderform2 form";
    var form3="#orderform3 form";
    var form4="#orderform4 form";
    var form0="#orderform0 form";

    
    $(form).submit(function() {
        var errorAmount = 0;
        $("#orderform form .inputtext").each(function() {
            var element = $(this);
            if($(this).val()==$(this).next(".htitle").attr("title")){
                errorAmount++;  
                $(this).css("color","red");
            }else{
            }
        });
        if(errorAmount>0){
            $("#orderform .err").text("Заполните выделенные поля").show;
            $("#orderform .err").css("margin-bottom","12px");
            
            return false;
        }
        errorAmount = 0;
        $.fancybox.showActivity();
    	$.ajax({
    		type		: "POST",
    		cache	: false,
    		url		: "form.php",
    		data		: $(this).serializeArray(),
    		success: function(data) {
    			$.fancybox(data);
    		}
    	});
    	return false;
    });

    $(form1).submit(function() {
        var errorAmount = 0;
        $("#orderform1 form .inputtext").each(function() {
            var element = $(this);
            
            if($(this).val()==$(this).next(".htitle").attr("title")){
                errorAmount++;  
                $(this).css("color","red");
            }else{
                
            }
        });
        if(errorAmount>0){
            $("#orderform1 .err").text("Заполните выделенные поля").show;
            $("#orderform1 .err").css("margin-bottom","12px");
            
            return false;
            
        }
        errorAmount = 0;
        $.fancybox.showActivity();
    
    	$.ajax({
    		type		: "POST",
    		cache	: false,
    		url		: "/special/form1.php",
    		data		: $(this).serializeArray(),
    		success: function(data) {
    			$.fancybox(data);
    		}
    	});
        
    	return false;
        
    });

    $(form2).submit(function() {
        var errorAmount = 0;
        $("#orderform2 form .inputtext").each(function() {
            var element = $(this);
            
            if($(this).val()==$(this).next(".htitle").attr("title")){
                errorAmount++;  
                $(this).css("color","red");
            }else{
                
            }
        });
        if(errorAmount>0){
            $("#orderform2 .err").text("Заполните выделенные поля").show;
            $("#orderform2 .err").css("margin-bottom","12px");
            
            return false;
            
        }
        errorAmount = 0;
        $.fancybox.showActivity();
    
    	$.ajax({
    		type		: "POST",
    		cache	: false,
    		url		: "/special/form2.php",
    		data		: $(this).serializeArray(),
    		success: function(data) {
    			$.fancybox(data);
    		}
    	});
        
    	return false;
        
    });

    $(form3).submit(function() {
        var errorAmount = 0;
        $("#orderform3 form .inputtext").each(function() {
            var element = $(this);
            
            if($(this).val()==$(this).next(".htitle").attr("title")){
                errorAmount++;  
                $(this).css("color","red");
            }else{
                
            }
        });
        if(errorAmount>0){
            $("#orderform3 .err").text("Заполните выделенные поля").show;
            $("#orderform3 .err").css("margin-bottom","12px");
            
            return false;
            
        }
        errorAmount = 0;
        $.fancybox.showActivity();
    
    	$.ajax({
    		type		: "POST",
    		cache	: false,
    		url		: "/special/form3.php",
    		data		: $(this).serializeArray(),
    		success: function(data) {
    			$.fancybox(data);
    		}
    	});
        
    	return false;
        
    });

    $(form4).submit(function() {
        var errorAmount = 0;
        $("#orderform4 form .inputtext").each(function() {
            var element = $(this);
            
            if($(this).val()==$(this).next(".htitle").attr("title")){
                errorAmount++;  
                $(this).css("color","red");
            }else{
                
            }
        });
        if(errorAmount>0){
            $("#orderform4 .err").text("Заполните выделенные поля").show;
            $("#orderform4 .err").css("margin-bottom","12px");
            
            return false;
            
        }
        errorAmount = 0;
        $.fancybox.showActivity();
    
    	$.ajax({
    		type		: "POST",
    		cache	: false,
    		url		: "/special/form4.php",
    		data		: $(this).serializeArray(),
    		success: function(data) {
    			$.fancybox(data);
    		}
    	});
        
    	return false;
        
    });

    $(form0).submit(function() {
        var errorAmount = 0;
        $("#orderform0 form .inputtext").each(function() {
            var element = $(this);
            
            if($(this).val()==$(this).next(".htitle").attr("title")){
                errorAmount++;  
                $(this).css("color","red");
            }else{
                
            }
        });
        if(errorAmount>0){
            $("#orderform0 .err").text("Заполните выделенные поля").show;
            $("#orderform0 .err").css("margin-bottom","12px");
            
            return false;
            
        }
        errorAmount = 0;
        $.fancybox.showActivity();
    
    	$.ajax({
    		type		: "POST",
    		cache	: false,
    		url		: "/special/form0.php",
    		data		: $(this).serializeArray(),
    		success: function(data) {
    			$.fancybox(data);
    		}
    	});
        
    	return false;
        
    });




    
    
});



