$(function(){
var reg_email =/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/
var reg_tel =/^(\+79|89)(\d{9})$/
	$('input[name="REGISTER[PASSWORD]"]').bind("keyup", function () {
		if ($('input[name="REGISTER[PASSWORD]"]').val() == "" || $('input[name="REGISTER[PASSWORD]"]').val().length <6 || $('input[name="REGISTER[PASSWORD]"]').val().length >50) {
				$(".err_PASSWORD").addClass("marker_fields");
				$(".regok_PASSWORD").removeClass("marker_fields");
			} else {
				$(".regok_PASSWORD").addClass("marker_fields");
				$(".err_PASSWORD").removeClass("marker_fields");
			}
		if ($('input[name="REGISTER[PASSWORD]"]').val() != $('input[name="REGISTER[CONFIRM_PASSWORD]"]').val() )
				{	$(".err_CONFIRM_PASSWORD").addClass("marker_fields");
					$(".regok_CONFIRM_PASSWORD").removeClass("marker_fields");
				}
	
	});
	
	$('input[name="REGISTER[CONFIRM_PASSWORD]"]').bind("keyup", function () {
		if  ($('input[name="REGISTER[CONFIRM_PASSWORD]"]').val() == "") {
				$(".err_CONFIRM_PASSWORD").removeClass("marker_fields");
				$(".regok_CONFIRM_PASSWORD").removeClass("marker_fields");
				$(".regerr_CONFIRM_PASSWORD").addClass("marker_fields");
			}
			else {
				$(".regerr_CONFIRM_PASSWORD").removeClass("marker_fields");
				if ($('input[name="REGISTER[PASSWORD]"]').val() != $('input[name="REGISTER[CONFIRM_PASSWORD]"]').val() )
				{	$(".err_CONFIRM_PASSWORD").addClass("marker_fields");
					$(".regok_CONFIRM_PASSWORD").removeClass("marker_fields");
				} else {
					$(".regok_CONFIRM_PASSWORD").addClass("marker_fields");
					$(".err_CONFIRM_PASSWORD").removeClass("marker_fields");
				}
			}
	
	});
	$('input[name="REGISTER[EMAIL]"]').bind("keyup", function () {
		if (reg_email.exec($('input[name="REGISTER[EMAIL]"]').val()) == null || $('input[name="REGISTER[EMAIL]"]').val() =="") {
				$(".err_EMAIL").addClass("marker_fields");
				$(".regok_EMAIL").removeClass("marker_fields");
			} else {
				$(".regok_EMAIL").addClass("marker_fields");
				$(".err_EMAIL").removeClass("marker_fields");
			}
	
	});
	
		$('input[name="REGISTER[LOGIN]"]').bind("keyup", function () {
		
		var login_err;
		var request_timeout;
		clearTimeout(request_timeout);
		   request_timeout = setTimeout(function(){
			 $.getJSON(
			'/ajax_reg.php',
			{
				action: 'register_form_login',
				login: $('input[name="REGISTER[LOGIN]"]').val(),
			},
			function(data){
				switch(data.status){
					case 'ok':	
						login_err = 1;
						break;
					case 'wrong_login':
						login_err = 0;
						break;
				}
				if($('input[name="REGISTER[LOGIN]"]').val() == "" || $('input[name="REGISTER[LOGIN]"]').val().length <3 || $('input[name="REGISTER[LOGIN]"]').val().length >50) {
					$(".err_LOGIN").removeClass("marker_fields");
					$(".regok_LOGIN").removeClass("marker_fields");
					$(".regerr_LOGIN").addClass("marker_fields");
				}
				else {
				$(".regerr_LOGIN").removeClass("marker_fields");
					if (login_err == 0) {
						$(".err_LOGIN").addClass("marker_fields");
						$(".regok_LOGIN").removeClass("marker_fields");
					} else {
						$(".regok_LOGIN").addClass("marker_fields");
						$(".err_LOGIN").removeClass("marker_fields");
					}
				}
			}
		);
	  }, 200);
    });

	
		
	$('input[name="REGISTER[PERSONAL_MOBILE]"]').bind("keyup", function () {
		if ($('input[name="REGISTER[PERSONAL_MOBILE]"]').val() == "") {
				$(".err_PERSONAL_MOBILE").removeClass("marker_fields");
				$(".regok_PERSONAL_MOBILE").removeClass("marker_fields");
				$(".regerr_PERSONAL_MOBILE").addClass("marker_fields");			} 
		else {
			$(".regerr_PERSONAL_MOBILE").removeClass("marker_fields");
				if (reg_tel.exec($('input[name="REGISTER[PERSONAL_MOBILE]"]').val()) == null ) {
				$(".regok_PERSONAL_MOBILE").removeClass("marker_fields");
				$(".err_PERSONAL_MOBILE").addClass("marker_fields");
				}
				else {
				$(".regok_PERSONAL_MOBILE").addClass("marker_fields");
				$(".err_PERSONAL_MOBILE").removeClass("marker_fields");
				
				}
		}
	
	});
		
	
	
	
	 $('#reloadcaptcha').click(function(){
         $('#whiteBlock').show();
         $.getJSON('/pers/register/reload_captcha.php', function(data) {
            $('#captchaImg').attr('src','/bitrix/tools/captcha.php?captcha_sid='+data);
            $('#captchaSid').val(data);
            $('#whiteBlock').hide();
         });
         return false;
      });

	$("#register_but").live("click", function () {
	var capcha_err;    
    $.getJSON(
        '/ajax_reg.php',
        {
            action: 'register_form_capcha',
            captcha_code: $('#code_captcha').val(),
            captcha_sid: $('#captchaSid').val(),
        },
        function(data){
            switch(data.status){
                case 'ok':
					$(".err_CAPCHA").removeClass("marker_fields");
					$(".regok_CAPCHA").addClass("marker_fields");
					capcha_err = 1;				
                    break;
                case 'wrong_code':
                    $(".err_CAPCHA").addClass("marker_fields");
					$(".regok_CAPCHA").removeClass("marker_fields");
					capcha_err = 0;	
                    break;
            }
			if ((capcha_err == 1	) && (reg_tel.exec($('input[name="REGISTER[PERSONAL_MOBILE]"]').val()) != null && $('input[name="REGISTER[PERSONAL_MOBILE]"]').val() !="") && $('input[name="REGISTER[NAME]"]').val() != "" && $('input[name="REGISTER[SECOND_NAME]"]').val() != ""  && $('input[name="REGISTER[LAST_NAME]"]').val() != ""  && $('input[name="REGISTER[WORK_COMPANY]"]').val() != "" && $('input[name="REGISTER[WORK_STREET]"]').val() != "" && $('input[name="REGISTER[WORK_STATE]"]').val() != "")
			{
				$('#regform_req').submit();
			}
			else {
				if ($('input[name="REGISTER[NAME]"]').val() == "") {
					$(".err_NAME").addClass("marker_fields");
					$(".regok_NAME").removeClass("marker_fields");
				} else {
					$(".regok_NAME").addClass("marker_fields");
					$(".err_NAME").removeClass("marker_fields");
				}
				if ($('input[name="REGISTER[SECOND_NAME]"]').val() == "") {
					$(".err_SECOND_NAME").addClass("marker_fields");
					$(".regok_SECOND_NAME").removeClass("marker_fields");
				} else {
					$(".regok_SECOND_NAME").addClass("marker_fields");
					$(".err_SECOND_NAME").removeClass("marker_fields");
				}
				if ($('input[name="REGISTER[LAST_NAME]"]').val() == "") {
					$(".err_LAST_NAME").addClass("marker_fields");
					$(".regok_LAST_NAME").removeClass("marker_fields");
				} else {
					$(".regok_LAST_NAME").addClass("marker_fields");
					$(".err_LAST_NAME").removeClass("marker_fields");
				}
				if ($('input[name="REGISTER[PERSONAL_MOBILE]"]').val() == "") {
				$(".err_PERSONAL_MOBILE").removeClass("marker_fields");
				$(".regok_PERSONAL_MOBILE").removeClass("marker_fields");
				$(".regerr_PERSONAL_MOBILE").addClass("marker_fields");			} 
				else {
					$(".regerr_PERSONAL_MOBILE").removeClass("marker_fields");
						if (reg_tel.exec($('input[name="REGISTER[PERSONAL_MOBILE]"]').val()) == null ) {
						$(".regok_PERSONAL_MOBILE").removeClass("marker_fields");
						$(".err_PERSONAL_MOBILE").addClass("marker_fields");
						}
						else {
						$(".regok_PERSONAL_MOBILE").addClass("marker_fields");
						$(".err_PERSONAL_MOBILE").removeClass("marker_fields");
						
						}
				}
				if ($('input[name="REGISTER[WORK_COMPANY]"]').val() == "") {
					$(".err_WORK_COMPANY").addClass("marker_fields");
					$(".regok_WORK_COMPANY").removeClass("marker_fields");
				} else {
					$(".regok_WORK_COMPANY").addClass("marker_fields");
					$(".err_WORK_COMPANY").removeClass("marker_fields");
				}
				if ($('input[name="REGISTER[WORK_STREET]"]').val() == "") {
					$(".err_WORK_STREET").addClass("marker_fields");
					$(".regok_WORK_STREET").removeClass("marker_fields");
				} else {
					$(".regok_WORK_STREET").addClass("marker_fields");
					$(".err_WORK_STREET").removeClass("marker_fields");
				}
				if ($('input[name="REGISTER[WORK_STATE]"]').val() == "") {
					$(".err_WORK_STATE").addClass("marker_fields");
					$(".regok_WORK_STATE").removeClass("marker_fields");
				} else {
					$(".regok_WORK_STATE").addClass("marker_fields");
					$(".err_WORK_STATE").removeClass("marker_fields");
				}
			}
		}
    );
});  
	  
	  
	$("#next_reg").live("click", function () {	
		var login_err;
		 $.getJSON(
        '/ajax_reg.php',
        {
            action: 'register_form_login',
            login: $('input[name="REGISTER[LOGIN]"]').val(),
        },
        function(data){
            switch(data.status){
                case 'ok':	
					login_err = 1;
                    break;
                case 'wrong_login':
					login_err = 0;
                    break;
            }
			if($('input[name="REGISTER[LOGIN]"]').val() == "") {
				$(".err_LOGIN").removeClass("marker_fields");
				$(".regok_LOGIN").removeClass("marker_fields");
				$(".regerr_LOGIN").addClass("marker_fields");
			}
			else {
			$(".regerr_LOGIN").removeClass("marker_fields");
				if (login_err == 0) {
					$(".err_LOGIN").addClass("marker_fields");
					$(".regok_LOGIN").removeClass("marker_fields");
				} else {
					$(".regok_LOGIN").addClass("marker_fields");
					$(".err_LOGIN").removeClass("marker_fields");
				}
			}
			
			var reg_usr_name = /[a-z]+/i;
		

		if ((login_err == 1)&& (reg_email.exec($('input[name="REGISTER[EMAIL]"]').val()) != null && $('input[name="REGISTER[EMAIL]"]').val() !="") && $('input[name="REGISTER[PASSWORD]"]').val() != "" && $('input[name="REGISTER[CONFIRM_PASSWORD]"]').val() != "" && ($('input[name="REGISTER[PASSWORD]"]').val() == $('input[name="REGISTER[CONFIRM_PASSWORD]"]').val())) {
			$(".active_field").addClass("noactive_newfield");
			$(".noactive_newfield").removeClass("active_field");
			$(".noactive_field").addClass("active_newfield");
			$(".active_newfield").removeClass("noactive_field");
			$(".regok_LOGIN").addClass("marker_fields");
			$(".regok_PASSWORD").addClass("marker_fields");
			$(".regok_CONFIRM_PASSWORD").addClass("marker_fields");
			$(".regerr_CONFIRM_PASSWORD").removeClass("marker_fields");
			$(".regok_EMAIL").addClass("marker_fields");
			$(".err_LOGIN").removeClass("marker_fields");
			$(".err_PASSWORD").removeClass("marker_fields");
			$(".err_CONFIRM_PASSWORD").removeClass("marker_fields");
			$(".err_EMAIL").removeClass("marker_fields");
		}
		else 
		{
			if ($('input[name="REGISTER[PASSWORD]"]').val() == "" || $('input[name="REGISTER[PASSWORD]"]').val().length <6 || $('input[name="REGISTER[PASSWORD]"]').val().length >50) {
				$(".err_PASSWORD").addClass("marker_fields");
				$(".regok_PASSWORD").removeClass("marker_fields");
			} else {
				$(".regok_PASSWORD").addClass("marker_fields");
				$(".err_PASSWORD").removeClass("marker_fields");
			}
			if  ($('input[name="REGISTER[CONFIRM_PASSWORD]"]').val() == "") {
				$(".err_CONFIRM_PASSWORD").removeClass("marker_fields");
				$(".regok_CONFIRM_PASSWORD").removeClass("marker_fields");
				$(".regerr_CONFIRM_PASSWORD").addClass("marker_fields");
			}
			else {
				$(".regerr_CONFIRM_PASSWORD").removeClass("marker_fields");
				if ($('input[name="REGISTER[PASSWORD]"]').val() != $('input[name="REGISTER[CONFIRM_PASSWORD]"]').val() )
				{	$(".err_CONFIRM_PASSWORD").addClass("marker_fields");
					$(".regok_CONFIRM_PASSWORD").removeClass("marker_fields");
				} else {
					$(".regok_CONFIRM_PASSWORD").addClass("marker_fields");
					$(".err_CONFIRM_PASSWORD").removeClass("marker_fields");
				}
			}
			if (reg_email.exec($('input[name="REGISTER[EMAIL]"]').val()) == null || $('input[name="REGISTER[EMAIL]"]').val() =="") {
				$(".err_EMAIL").addClass("marker_fields");
				$(".regok_EMAIL").removeClass("marker_fields");
			} else {
				$(".regok_EMAIL").addClass("marker_fields");
				$(".err_EMAIL").removeClass("marker_fields");
			}
			
		}
			
        }
    );
		
	});

	  
	
	
	
	$("#prev_reg").live("click", function () {		
		$(".active_newfield").addClass("noactive_field");
		$(".noactive_field").removeClass("active_newfield");
		$(".noactive_newfield").addClass("active_field");
		$(".active_field").removeClass("noactive_newfield");
	});
	
	
    if ($(".fright .consult_order_cont").length) {
        $(".consult_order_cont form").attr("action", "/consult-order/")
    }
    if ($(".compare_table").length) {
        initScrollbars()
    }
    if ($(".print").length) {
        $(".print").prev().css("width", "70%")
    }
    if ($(".cities").length) {
        $(".cities ul a").live("click", function () {
            if (!$(this).parent().hasClass("active")) {
                var a = $(this).parent().attr("id").replace("city-menu-", "");
                var b = $(this);
                $(this).parent().parent().find(".active").removeClass("active");
                $(this).parent().addClass("active");
                $(this).parent().parent().next().find(".active").fadeOut(300, function () {
                    $(this).removeClass("active");
                    $(b).parent().parent().next().find(".cities_contact:nth-child(" + a + ")").fadeIn(300, function () {
                        $(this).addClass("active")
                    })
                })
            }
            $(this).blur();
            return false
        })
    }
    if ($(".city_contact_selector").length) {
        $(".current_city a").live("click", function () {
            $(".contacts_city_list").fadeIn(300);
            $(this).blur();
            return false
        });
        $(".contacts_city_list ul a").live("click", function () {
            var a = $(this);
            $(this).parent().parent().find(".active").removeClass("active");
            $(this).parent().addClass("active");
            $(".current_city a").text($(this).text());
            $(".contact_cities > .active").fadeOut(300, function () {
                $(".contact_cities .contact_cities_item:nth-child(" + $(a).parent().attr("id").replace("city-menu-contact-", "") + ")").fadeIn(300, function () {
                    $(".contact_cities > .active").removeClass("active");
                    $(this).addClass("active")
                })
            });
            $(".contacts_city_list").fadeOut(300);
            $(this).blur();
            return false
        });
        $(".close_contacts_city_list").live("click", function () {
            $(".contacts_city_list").fadeOut(200);
            $(this).blur();
            return false
        })
    }
    if ($(".consult_order").length) {
        $(".consult_order_bottom a").live("mousedown", function () {
            if (!$(".consult_order_form").hasClass("opened")) {
                $(".consult_order_bottom").css("background-position", "0 -149px")
            } else {
                $(".consult_order_bottom").css("background-position", "0 -169px")
            }
            $(this).blur()
        });
        $(".consult_order_bottom a").live("mouseup", function () {
            if (!$(".consult_order_form").hasClass("opened")) {
                $(".consult_order_bottom").css("background-position", "0 -149px")
            } else {
                $(".consult_order_bottom").css("background-position", "0 -129px")
            }
            $(this).blur()
        });
        $(".consult_order_bottom a").live("click", function () {
            if (!$(".consult_order_form").hasClass("opened")) {
                $(".consult_order_bottom").css("background-position", "0 -129px");
                $(".consult_order_form").slideDown(300).addClass("opened")
            } else {
                $(".consult_order_bottom").css("background-position", "0 -109px");
                $(".consult_order_form").slideUp(300).removeClass("opened")
            }
            $(this).blur();
            return false
        })
    }
    if ($(".tabs").length) {
        $(".tab_menu a").live("click", function () {
            if (!$(this).hasClass("active")) {
                $(".tab_menu a.active").removeClass("active");
                $(this).addClass("active");
                $(".tabs .tab:visible").fadeOut(300, function () {
                    $($(".tab_menu a.active").attr("href")).fadeIn(300);
                    if ($(".tabs_contact").length && !$(".tab_menu a.active .mousetrap").length) {
                        $(".cloud-zoom, .cloud-zoom-gallery").CloudZoom()
                    }
                })
            }
            $(this).blur();
            return false
        })
    }
    if ($(".big_button").length) {
        $(".big_button a").live("mouseover", function () {
            $(".big_img img:visible").removeClass("active").hide();
            $(".big_button .active").removeClass("active");
            $(this).addClass("active");
            $(".big_img img:nth-child(" + $(this).parent().attr("id").replace("big-button-", "") + ")").show()
			$("#all_show").hide();
        })
        
        $(".big_button a").live("mouseout", function () {
            $(".big_img img:visible").removeClass("active").hide();
            $(".big_button .active").removeClass("active");
            $("#all_show").show();
        })
    }
    if ($("#machine_name_hidden").length) {
        $("#machine_name input").val($("#machine_name_hidden").val())
    }
    if ($("ol").length) {
        $("ol").each(function (b) {
            var a = '<table class="ol">';
            $(this).find("li").each(function (c) {
                a += '<tr><td class="num"><span>' + parseInt(c + 1) + "</span></td><td>" + $(this).text() + "</td></tr>"
            });
            a += "</table>";
            $(this).replaceWith(a)
        })
    }
    if ($(".weekly_mailing").length) {
        $(".weekly_mailing a").live("click", function () {
            $(".weekly_mailing .field").slideToggle(300);
            $(this).blur();
            return false
        })
    }
    if ($(".features_menu").length) {
        $(".features_menu a").live("click", function () {
            if (!$(this).parent().hasClass("active")) {
                $(this).parent().parent().find(".active").removeClass("active");
                $(this).parent().addClass("active");
                if($('.tab').length){
                    if ($(this).parent().attr("id") == "features-menu-2") {
                        $(".tab:visible table .nodiff").fadeOut(300);
                        $(".tab:visible table .nodiff").next().fadeOut(300)
                    } else {
                        $(".tab:visible table .nodiff").fadeIn(300);
                        $(".tab:visible table .nodiff").next().fadeIn(300)
                    }
                }else{
                    if ($(this).parent().attr("id") == "features-menu-2") {
                        $(".nodiff").fadeOut(300);
                        $(".nodiff").next().fadeOut(300)
                    } else {
                        $(".nodiff").fadeIn(300);
                        $(".nodiff").next().fadeIn(300)
                    }
                }
            }
            $(this).blur();
            return false
        })
    }
    if ($("#cons-city-sel").length) {
        $(".cons_city_list ul a").live("click", function () {
            var a = $(this).attr("id").replace("cons-city-", "");
            $("#cons-city-sel").text($(this).text());
            $(".cons_city_list").fadeOut(200);
            $(".phone_list li:visible").fadeOut(100, function () {
                $(".phone_list li:nth-child(" + a + ")").fadeIn(200)
            });
            $(this).blur();
            return false
        });
        $("#cons-city-sel").live("click", function () {
            $(".cons_city_list").fadeIn(200);
            $(this).blur();
            return false
        });
        $(".close_city_list").live("click", function () {
            $(".cons_city_list").fadeOut(200);
            $(this).blur();
            return false
        })
    }
    if ($(".search").length) {
        $(".search .submit input").live("mouseover", function () {
            $(this).css("color", "#4a78be");
            $(this).blur();
            return false
        });
        $(".search .submit input").live("mouseout", function () {
            $(this).css("color", "#999");
            $(this).blur();
            return false
        });
        $(".search .submit input").live("mousedown", function () {
            $(this).css("color", "#fff");
            $(this).blur();
            return false
        })
    }
    if ($('a[rel="fancybox"]').length) {
        $('a[rel="fancybox"]').fancybox({
            titleShow: false,
            transitionIn: "elastic",
            transitionOut: "elastic"
        })
    }
    if ($(".tabs_contact .tab_cont").length) {
        $(".tabs_contact .tab_cont a").fancybox({
            titleShow: false,
            transitionIn: "elastic",
            transitionOut: "elastic"
        })
    }
    if ($(".cur_rate").length) {
        $(".calc_data input").live("change", reCalculatePrices);
        $(".calc_data input").live("click", function () {
            if ($(this).val() == 0) {
                $(this).val("")
            }
        });
        $(".calc_data input").live("blur", function () {
            if ($(this).val() == "") {
                $(this).val("0")
            }
        })
    }
    if ($(".quantity_inc").length) {
        $(".quantity_dec").live("click", function () {
            var a = $(this).next().val();
            if (a > 1) {
                $(this).next().val(--a)
            }
            $(this).blur();
            return false
        });
        $(".quantity_inc").live("click", function () {
            var a = $(this).prev().val();
            $(this).prev().val(++a);
            $(this).blur();
            return false
        });
        $(".submit input").live("mouseover", function () {
            $(this).addClass("jshover")
        });
        $(".submit input").live("mouseout", function () {
            $(this).removeClass("jshover")
        })
    }
    if ($(".certificates a").length) {
        $(".certificates a").fancybox({
            titleShow: false,
            transitionIn: "elastic",
            transitionOut: "elastic"
        })
    }
	
    if ($(".reportlink").length) {
        $(".reportlink").fancybox({
            titleShow: false,
            transitionIn: "elastic",
            transitionOut: "elastic"
        })
    }
	
    if ($(".order_history").length) {
        $(".order_history .level-1>a").live("click", function () {
            if ($(this).parent().hasClass("active")) {
                $(this).parent().removeClass("active")
            } else {
                $(this).parent().addClass("active")
            }
            $(this).blur();
            return false
        })
    }
    if ($(".personal_right").length) {
        $(".personal_right .editable").live("click", function () {
            var c = $(this).attr("id");
            var b = $(this).text().replace(/^\s*/, "").replace(/\s*$/, "").replace("&nbsp;", "");
            var a = $(this);
            $(a).hide().after('<input class="editable_field" type="text" name="' + c + '" value="' + b + '" /><input class="editable_button" type="button" name="editable_button" value="" />').next().focus().next().live("click", function () {
                $.get("/ajax.php", {
                    name: c,
                    value: $(this).prev().val()
                }, function (d) {
                    $(a).html(d).fadeIn(300);
                    $(a).next().remove();
                    $(a).next().remove()
                })
            });
            $(a).next().keydown(function (d) {
                if (d.keyCode == "13") {
                    $.get("/ajax.php", {
                        name: c,
                        value: $(this).val()
                    }, function (e) {
                        $(a).html(e).fadeIn(300);
                        $(a).next().remove();
                        $(a).next().remove()
                    })
                }
            });
            $(this).blur();
            return false
        })
    }
    
    $('.add_to_compare a').live('click', function(){
        if(!$(this).hasClass('active')){
            $(this).addClass('active');
        }else{
            $(this).removeClass('active');
        }
        if($(this).parentsUntil('.machines_list_cont').parent().find('.add_to_compare a.active').length == 1){
            $(this).parentsUntil('.machines_list_cont').parent().find('.add_to_compare a').not('.active').each(function(){
                $(this).find('span').css('opacity', 0).show().stop().animate({
                    opacity: 1,
                    top: '-29'
                }, 300);
            });
        }else{
            $(this).parentsUntil('.machines_list_cont').parent().find('.add_to_compare a').each(function(){
                $(this).find('span').stop().animate({
                    opacity: 0,
                    top: '-49'
                }, 300);
            });
            $(this).parentsUntil('.machines_list_cont').parent().find('.tooltip_more_0').stop().animate({
                opacity: 0,
                top: '32'
            }, 300);
            $(this).parentsUntil('.machines_list_cont').parent().find('.tooltip_more_1').stop().animate({
                opacity: 0,
                top: '32'
            }, 300);
            $(this).parentsUntil('.machines_list_cont').parent().find('.tooltip_more_2').stop().animate({
                opacity: 0,
                top: '32'
            }, 300);
        }
        var link = $(this).parentsUntil('.machines_list_cont').parent().find('.compare a');
        $(link).attr('href', '/production/compare/compare-machines.php?type=' + $(link).attr('id').replace('type_', ''));
        $(this).parentsUntil('.machines_list_cont').parent().find('.add_to_compare a.active').each(function(){
            $(link).attr('href', $(link).attr('href') + $(this).attr('href').replace('#compare_', '&id[]='));
        });
        return false;
    });
    
    $('.compare a').live('click', function(){
        if($(this).parent().parent().find('.add_to_compare a.active').length == 1){
            $(this).parent().find('.tooltip_more_1').css('opacity', 0).show().stop().animate({
                opacity: 1,
                top: '32'
            }, 300);
            $(this).parent().find('.tooltip_more_0').stop().animate({
                opacity: 0,
                top: '32'
            }, 300);
            $(this).parent().find('.tooltip_more_2').stop().animate({
                opacity: 0,
                top: '32'
            }, 300);
            return false;
        }else if($(this).parent().parent().find('.add_to_compare a.active').length == 0){
            $(this).parent().find('.tooltip_more_0').css('opacity', 0).show().stop().animate({
                opacity: 1,
                top: '32'
            }, 300);
            $(this).parent().find('.tooltip_more_1').stop().animate({
                opacity: 0,
                top: '32'
            }, 300);
            $(this).parent().find('.tooltip_more_2').stop().animate({
                opacity: 0,
                top: '32'
            }, 300);
            return false;
        }else{
        }
    });
	
	if($('.dipl').length)
	{
	 $('#close_dipl').click(function(){
			jQuery.get("/bage.php",{'mode':'close'},function(result){
			 $('#d_container').hide(); 
			});
		});
	}
	
	if($('#lenta').length)
	{
	 initCarousel();
	 $('.minilavazza a').click(function(){
			var j = $(this).attr('jcarouselindex');
			carouselScrollTo(j);
		});
	}
	
	if($('.t').length)
	{
	 $('.t').hover(
	 
			function(){
						if(!$(this).hasClass("z"))
						{
						 $(this).addClass("z");
						}
					  },

			function(){
						 $(this).removeClass("z");
					  }
					  
		);
	}
	
    
    $('.delorder').live('click', function(){
        if(confirm('Заказ будет отменен. Продолжить?')){
            return true;
        }else{
            return false;
        }
    });
	
	
});

var marginArray = new Array(381,-53,-475);
var current_device = 2, prev_device = 2;

function scrollPrev()
{
prev_device = current_device;
var delta = 1;
 if(current_device==1) current_device=4;
      /*return false;*/
  
  if(scrollPrev.arguments.length==1)
	delta = scrollPrev.arguments[0];

 current_device-=delta;  
 $('#lenta').animate({marginLeft:marginArray[current_device-1] + "px"});
  /*if(current_device==1) 
      $('#arrow_prev').fadeOut(100);*/
  if(current_device>=1) 
    $('#arrow_prev').fadeIn(100);
      if(current_device<=3) 
    $('#arrow_next').fadeIn(100);
	
  loadDeviceContent('prev');
 
}

function scrollNext()
{
prev_device = current_device;
var delta = 1;

 if(current_device==3) current_device=0;
    /*return false;*/

    if(scrollNext.arguments.length==1)
	delta = scrollNext.arguments[0];

current_device+=delta;
 $('#lenta').animate({marginLeft:marginArray[current_device-1] + "px"});
  /*if(current_device==3) 
    $('#arrow_next').fadeOut(100);*/
    if(current_device<=3) 
    $('#arrow_next').fadeIn(100);
      if(current_device>=1) 
    $('#arrow_prev').fadeIn(100);
	
	
 loadDeviceContent('next');
}

function carouselScrollTo(pos)
{
 if(pos > current_device)
	scrollNext(pos - current_device);

  if(pos < current_device)
		scrollPrev(current_device - pos);
}


function loadDeviceContent(state)
{
 $('#white_content').hide();
  $('#lavazzabody').show();

	  
	 if(state!='show')
	 {
	  var o = $('#lenta div[jcarouselindex="' + current_device + '"]'),
	  o2 = $('#lenta div[jcarouselindex="' + prev_device + '"]'),

	  p = $('.minilavazza a[jcarouselindex="' + current_device + '"]'),
	  p2 = $('.minilavazza a[jcarouselindex="' + prev_device + '"]');
	
	  var device_id = $(o).attr('did');
	
		  $(o).find('img.iniimg').hide();
		  $(o).find('div.hiddendevice').show();
		  $(o).find('div.devicetitle').css('visibility','visible');
	
		  $(o2).find('img.iniimg').show();
		  $(o2).find('div.hiddendevice').hide();	 
		  $(o2).find('div.devicetitle').css('visibility','hidden');

	
		  $(p).attr("class","vis_link");
	
		  $(p2).attr("class","hid_link");

		  
		  $('#machine_name').find('input').val($(o).find('div.devicetitle').text());
		  
	  $.get("/device.php",{'device_id':device_id},function(result){
	      $('.lavazzamenu a').attr("class","lmlink");
		$('#lavazzabody').html(result);
	  });
	}  
}

function initCarousel()
{
	$('#lenta div[jcarouselindex="2"]').find('img.iniimg').hide();
	$('#lenta div[jcarouselindex="2"]').find('div.hiddendevice').show();
	$('#lenta div[jcarouselindex="2"]').find('div.devicetitle').css('visibility','visible');

	$('#machine_name').find('input').val($('#lenta div[jcarouselindex="2"]').find('div.devicetitle').text());
		  
		  $.get("/device.php",{'device_id':97},function(result){
				$('#lavazzabody').html(result);
			  });	
}


function showLavazzaInfo(n,obj)
{
  $('#lavazzabody').hide();
  $('.lavazzamenu a').attr("class","lmlink");
  $(obj).attr("class","lmlink_s");
  
 if($('#white_content').is(":hidden"))
   $('#white_content').show();

	$(".innerwhite").hide();
	$("#white" + n + "_content").show();  
}

function showServiceInfo(n)
{
var ot = Math.abs(n-3);
 if($("#folder" + n + "_content").is(":hidden"))
 {
   $(".folder" + n).removeClass("t").addClass("b");   
   $(".folder" + ot).css({zIndex:"-1"}); 
   $("#folder" + n + "_content").slideDown('slow',function(){
		$(".folder" + n).toggleClass("z");
		
   });


 }
 else {
		
		$("#folder" + n + "_content").slideUp('slow',function(){
				$(".folder" + n).toggleClass("z");
				$(".folder" + n).removeClass("b").addClass("t");     
				$(".folder" + ot).css({zIndex:""}); 				
			});
	  }  

}

function reCalculatePrices() {
    var b = 30;
    var a = 84;
    if ($(".tab:visible").attr("id") == "tab-1") {
        cur_rate = $("#tab-1 .cur_rate").val();
        auto_price = $("#tab-1 .auto_price").val();
        auto_num = $("#tab-1 .auto_num").val();
        $(".avg_glass_earn").val($(".avg_sell_price").val() - $(".avg_cost").val());
        avg_glass_sell = $("#tab-1 .avg_glass_sell").val();
        avg_glass_earn = $("#tab-1 .avg_glass_earn").val();
        total_price = auto_price * auto_num;
        total_price_rub = total_price * cur_rate;
        $("#tab-1 .total_price").val(number_format(total_price, 2, ".", ""));
        $("#tab-1 .total_price_rub").val(number_format(total_price_rub, 2, ".", ""));
        place_rent = parseInt($("#tab-1 .place_rent").val());
        oil = parseInt($("#tab-1 .oil").val());
        tax = parseInt($("#tab-1 .tax").val());
        payment = parseInt($("#tab-1 .payment").val());
        office_rent = parseInt($("#tab-1 .office_rent").val());
        other = parseInt($("#tab-1 .other").val());
        month_income = b * auto_num * avg_glass_sell * avg_glass_earn;
        month_cost = place_rent + oil + tax + payment + office_rent + other;
        month_income_wo_amort = month_income - month_cost;
        amort = number_format(total_price_rub / a, 2, ".", "");
        total_month_income = month_income_wo_amort - amort;
        total_month_income_euro = number_format(total_month_income / cur_rate, 2, ".", "");
        total_year_income_euro = number_format(total_month_income / cur_rate * 12, 2, ".", "");
        payback_time = Math.ceil(auto_price / total_month_income_euro);
        $("#tab-1 .month_income").val(month_income);
        $("#tab-1 .month_cost").val(month_cost);
        $("#tab-1 .month_income_wo_amort").val(month_income_wo_amort);
        $("#tab-1 .amort").val(amort);
        $("#tab-1 .total_month_income").val(total_month_income);
        $("#tab-1 .total_month_income_euro").val(total_month_income_euro);
        $("#tab-1 .total_year_income_euro").val(total_year_income_euro);
        $("#tab-1 .payback_time").val(payback_time)
    } else {
        cur_rate = $("#tab-2 .cur_rate").val();
        auto_price = $("#tab-2 .auto_price").val();
        auto_num = $("#tab-2 .auto_num").val();
        sell_volume = $("#tab-2 .sell_volume").val();
        addit_price = $("#tab-2 .addit_price").val();
        total_price = auto_price * auto_num;
        total_price_rub = total_price * cur_rate;
        $("#tab-2 .total_price").val(number_format(total_price, 2, ".", ""));
        $("#tab-2 .total_price_rub").val(number_format(total_price_rub, 2, ".", ""));
        place_rent = parseInt($("#tab-2 .place_rent").val());
        oil = parseInt($("#tab-2 .oil").val());
        tax = parseInt($("#tab-2 .tax").val());
        payment = parseInt($("#tab-2 .payment").val());
        office_rent = parseInt($("#tab-2 .office_rent").val());
        other = parseInt($("#tab-2 .other").val());
        month_income = number_format((sell_volume * b * auto_num) - sell_volume / (1 + addit_price / 100) * b * auto_num, 2, ".", "");
        month_cost = place_rent + oil + tax + payment + office_rent + other;
        month_income_wo_amort = month_income - month_cost;
        amort = number_format(total_price_rub / a, 2, ".", "");
        total_month_income = month_income_wo_amort - amort;
        total_month_income_euro = number_format(total_month_income / cur_rate, 2, ".", "");
        total_year_income_euro = number_format(total_month_income / cur_rate * 12, 2, ".", "");
        payback_time = Math.ceil(auto_price / total_month_income_euro);
        $("#tab-2 .month_income").val(month_income);
        $("#tab-2 .month_cost").val(month_cost);
        $("#tab-2 .month_income_wo_amort").val(month_income_wo_amort);
        $("#tab-2 .amort").val(amort);
        $("#tab-2 .total_month_income").val(total_month_income);
        $("#tab-2 .total_month_income_euro").val(total_month_income_euro);
        $("#tab-2 .total_year_income_euro").val(total_year_income_euro);
        $("#tab-2 .payback_time").val(payback_time)
    }
    return false
}
function initScrollbars() {
    return false
}
function SelectSection(b, a) {
    if (!a || a == "" || a == 0) {
        a = 1
    }
    if (b == 0) {
        if (a == 1) {
            $("#slave_section").fadeOut()
        }
        $("#slave_items").fadeOut(100);
        return false
    } else {
        if (a == 1) {
            $("#slave_section").fadeOut()
        }
        $("#slave_items").fadeOut(100)
    }
    if (a == 1) {
        $("#slave_section").html('<img src="/i/loading.gif" width="16" height="16" alt="" />');
        $("#slave_section").fadeIn(100)
    } else {
        if (a == 2) {
            $("#slave_items").html('<img src="/i/loading.gif" width="16" height="16" alt="" />');
            $("#slave_items").fadeIn(100)
        }
    }
    $.get("/addons/ajax.php", {
        mode: "section",
        id: b,
        dataType: "json"
    }, function (c) {
        if (a == 1) {
            $("#slave_section").html(c);
            $("#slave_section").fadeIn(100)
        }
        if (a == 2) {
            $("#slave_items").html(c);
            $("#slave_items").fadeIn(100)
        }
        return false
    })
}
function openOrderSpare(c, b, a) {
    $("#num" + a).blur().addClass("loading");
    $.get("/personal/spare/spare.php", {
        id: c,
        product_id: b
    }, function (d) {
        $("#num" + a).removeClass("loading").parent().append(d);
        $("#spare_order_form").fadeIn(200);
        return false
    });
    return false
}
function closeOrderSpare() {
    $("#spare_order_form").fadeOut(50, function () {
        $(this).remove()
    })
}
function number_format(f, c, h, e) {
    f = (f + "").replace(",", "").replace(" ", "");
    var b = !isFinite(+f) ? 0 : +f,
        a = !isFinite(+c) ? 0 : Math.abs(c),
        j = (typeof e === "undefined") ? "," : e,
        d = (typeof h === "undefined") ? "." : h,
        i = "",
        g = function (o, m) {
            var l = Math.pow(10, m);
            return "" + Math.round(o * l) / l
        };
    i = (a ? g(b, a) : "" + Math.round(b)).split(".");
    if (i[0].length > 3) {
        i[0] = i[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, j)
    }
    if ((i[1] || "").length < a) {
        i[1] = i[1] || "";
        i[1] += new Array(a - i[1].length + 1).join("0")
    }
    return i.join(d)
}
function changeInputType(a, c) {
    var b = document.createElement("input");
    b.type = c;
    if (a.size) {
        b.size = a.size
    }
    if (a.value) {
        b.value = a.value
    }
    if (a.name) {
        b.name = a.name
    }
    a.parentNode.replaceChild(b, a);
    b.focus()
};



    $('#master_video').change(function() {
    var a = $(this);
      $.get("/personal/video/ajax.php", {
            value: $(a).val()
        }, function (d) {
            $('#video').html(d);
        })
    });
    
/*$(document).ready(function(){    
    $(".capsule_block_element").mouseover(function (){
       $(this).find('.capsule_fon').show();
    });
    $(".capsule_block_element").mouseout(function (){
        $(this).parent().find('.capsule_fon').hide();
    });
    $(".dostavka_new").mouseover(function (){
       $(this).find('.dostavka_fon').show();
    });
    $(".dostavka_new").mouseout(function (){
        $(this).find('.dostavka_fon').hide();
    });
});*/

          
