$(document).ready(function(){

    var opt = {success:    function(responseText, statusText, xhr, form) {
            try {
                eval('var data = ' + responseText);

                $('#FeedbackForm .errors').html('');
                try {
                for(var i = 0; i < data.errors.length; i++) {
                    $('#FeedbackForm .errors').append('<div>'+data.errors[i]+'</div>');
                }
                } catch(ee){}

                if(data.state == true) {
                    var href = location.href;
                    href = href.split('/');
                    if(href[3] == 'en'){
                        $('#FeedbackForm .errors').html('Thank you for your address! Our manger will answer you in 48 hours.');
                    }else{
                        $('#FeedbackForm .errors').html('Спасибо за Ваше обращение! Наш менеджер ответит Вам в течении 48 часов.');
                    }
                    
                    //setTimeout(location.reload(),3000);
                }
                $('#FeedbackForm .errors').removeClass('hide');
            } catch(E){}
        }
    };

    $('#FeedbackForm').ajaxForm(opt);

	//------------

    var maxHeight = 0;
    $('.goods section').each(function() {
        if($(this).height() > maxHeight)
            maxHeight = parseInt($(this).height());
    });

    $('.goods section').css('height', maxHeight + 'px')

    if(parseInt(screen.width) >= 1600) {
        $('.container').css('overflow', 'visible');
    }

    $('.content .solutions-block ul.solul a').click(function() {
        var prn = $(this).parent().parent();
        
        var index = $(this).parent().index();

        $(prn).find('li').removeClass('active');
        $(prn).find('li:eq('+index+')').addClass('active');
        $(prn.parent()).find('.sol-des-content').css('display', 'none');
        $(prn.parent()).find('.sol-des-content:eq('+index+')').css('display', 'block');


        $(prn.parent()).find('.bottom-text').css('display', 'none');
        $(prn.parent()).find('.bottom-text:eq('+index+')').css('display', 'block');

        return false;
    });

    /*var opt = {success:    function(responseText, statusText, xhr, form) {
            try {
                eval('var data = ' + responseText);

                $('#FeedbackForm .errors').html('');
                try {
                for(var i = 0; i < data.errors.length; i++) {
                    $('#FeedbackForm .errors').append('<div>'+data.errors[i]+'</div>');
                }
                } catch(ee){}

                if(data.state == true) {
                    $('#FeedbackForm .errors').html('Ваше сообщение отправлено');
                    
                }

                $('#FeedbackForm .errors').removeClass('hide');
            } catch(E){}
        }
    };

    $('.ask-question, .feedback, .question').click( function(){
        $('.fb').css('display', 'block');
        $('.fb').css("position","fixed");
        $('.fb').css({top:'50%',left:'50%',margin:'-'+($('.fb').height() / 2)+'px 0 0 -'+($('.fb').width() / 2)+'px'});
        return false;
    });

    $('#FeedbackForm').ajaxForm(opt);*/

    /*$('.fb .close').click(function() {
        $('.fb').css('display', 'none');
       return false;
    });*/

	Cufon.replace(".pdf-buy a,a.GoOrderForm, .communication .phone span, header.basic .menu li, .main h2, .read, .question, .-contacts ul li h4, .-contacts ul li h4.active, .feedback, .catalog li h2, .back, .resume, .solutions-block h2, .ask-question, .about-menu ul li a, #mainslider ul.slides li.history p, .go-catalog, .menu li a, nav ul li a, .aside h2, .about-menu ul li a, .history span", {hover: true});
	
    
	$('header.basic .menu li a').hover( 
	function() {
		$(this).parent('li').addClass('hover');
	},
	function() {
		$(this).parent('li').removeClass('hover');
	}); 
	
	
	$('.goods section ul').hover( 
	function() {
		$(this).parent('section').find('header').addClass('active');
	},
	function() {
		$(this).parent('section').find('header').removeClass('active');
	}); 
	
	
	$('.news section .img a img').hover( 
	function() {
		$(this).parent('a').parent('.img').addClass('hover');
		$(this).parent('a').parent('.img').addClass('hover');
	},
	function() {
		$(this).parent('a').parent('.img').removeClass('hover');
	}); 
	
	
	$('.cycle').cycle({
		fx:      'scrollHorz',
		speed:  1000,
		timeout: 3000,
		next: '.next',
		prev: '.prev'
	});
	
	$(".pause").toggle(
		function(){ 
			$('.cycle').cycle('pause');
			$(this).addClass('play');
		},
		function(){ 
			$('.cycle').cycle('resume');
			$(this).removeClass('play');	
		}
	);

	
	$(".contacts ul li:first h4").addClass("active");
	$(".contacts ul li:first div").show();
	$(".contacts ul li").click(function() {
		$(".city a.active").removeClass('active'); 
		if ($(this).find('h4').hasClass('active') == false) {
			$(".contacts ul li div").slideUp("slow");
			$('.contacts ul li').find("h4").removeClass("active");
			$('.contacts ul li').removeClass("active");
			$(this).find("div").slideDown("slow");
			$(this).children("h4").addClass("active");
			
			
			var atrli = $(this).attr('name');
			$('.city a').each(function(){
			var atra = $(this).attr('rel');
			if ( atra == atrli ) {
				$(this).addClass('active');
				/* $(".contacts ul li div").slideUp("slow");
				$('.contacts ul li').find("h4").removeClass("active");
				$('.contacts ul li').removeClass("active");
				$(this).find("div").slideDown("slow");
				$(this).children("h4").addClass("active"); */
			}
		});	
			
		}
		
	});
	
	
	
	$(".city a").click(function() {
		if ( $(this).hasClass('active') == false ) {
		var atr = 0;
		var atrl = 0;
		atr = $(this).attr('rel');
		$(".city a.active").removeClass('active'); 
		$(this).addClass('active');
		$('.contacts li').each(function(){
			atrl = $(this).attr('name');
			if ( atr == atrl ) {
				$(".contacts ul li div").slideUp("slow");
				$('.contacts ul li').find("h4").removeClass("active");
				$('.contacts ul li').removeClass("active");
				$(this).find("div").slideDown("slow");
				$(this).children("h4").addClass("active");
			}
		});
		
}});

	
	
var slHeight = 0;
	$('.slt section .sl div ul li').each(function(){
	var lih = $(this).innerHeight();
	if (lih > slHeight) {
		slHeight = lih;
	}
		$('.slt section .sl div').css('height', (slHeight < 94 ? 94 : slHeight) + 'px');
	});
	
	
mf = 0;
	mf = $('.slt section ul');
	if (mf.length > 0) {
		var mdiff = 0;
		var mnum = 2;
		var mclick = true;
		var mli = $('li:first', mf);
		mdiff = 290;
		mfwidth = mf.children().length * mdiff;
		mf.width(mfwidth);
		$('.slt .prev').click(function() {
			var ml = parseInt(mf.css('margin-left')) + mdiff;
			if (mclick && ml <= 0) {
				mclick = false;
				mf.animate({'margin-left': ml + 'px'}, 360, function(){mclick = true;});
				if (ml+mdiff > 0) {
					$(this).addClass('disabledl');
				}
				if ($('.slt .next').hasClass('disabledr')) {
					$('.slt .next').removeClass('disabledr');
				}
			}
		});
		$('.slt .next').click(function() {
			var ml = parseInt(mf.css('margin-left')) - mdiff;
			if (mclick && ml - mdiff * (mnum-1) > -mfwidth) {
				mclick = false;
				mf.animate({'margin-left': ml + 'px'}, 360, function(){mclick = true;});
				if (ml - mdiff * mnum <= -mfwidth) {
					$(this).addClass('disabledr');
				}	
				if ($('.slt .prev').hasClass('disabledl')) {
					$('.slt .prev').removeClass('disabledl');
				}
			}
		});	
	}
	if (parseInt(mf.css('margin-left')) == 0) {$('#move-left').addClass('disabledl');}
	if (mf.find('li').length <= 1) {$('#move-right').addClass('disabledr');}
	
	
	$('.catalog li ul li').hover( 
	function() {
		Cufon.replace(".catalog li h2", {hover: true});
	},
	function() {
		Cufon.replace(".catalog li h2", {hover: true});
	}); 

	
	$('.catalog > li').each(function(){
		
		$('li' ,this).each(function(){
			
			if ($('> a', this).next('ul').length > 0){
				$('> a', this).addClass('plus');
				$(this).addClass('plus');
			} else {
				$('> a', this).addClass('marker')
			};
			
		});
		
	});

        $('.catalog li a.plus').click(function() {
            if(!$(this).hasClass('minus')) {
		$(this).next('ul').css('display','block');
		$(this).addClass('minus');
            } else {
		$(this).next('ul').css('display','none');
		$(this).removeClass('minus');
            }

            return false;
        });

	
	
var slHeight = 0;
	$('.slt section .sl div ul li').each(function(){
	var lih = $(this).innerHeight();
	if (lih > slHeight) {
		slHeight = lih;
	}
		$('.slt section .sl div').css('height', slHeight + 'px');
	});
	
	
mf = 0;
	mf = $('.slt section ul');
	if (mf.length > 0) {
		var mdiff = 0;
		var mnum = 2;
		var mclick = true;
		var mli = $('li:first', mf);
		mdiff = 290;
		mfwidth = mf.children().length * mdiff;
		mf.width(mfwidth);
		$('.slt .prev').click(function() {
			var ml = parseInt(mf.css('margin-left')) + mdiff;
			if (mclick && ml <= 0) {
				mclick = false;
				mf.animate({'margin-left': ml + 'px'}, 360, function(){mclick = true;});
				if (ml+mdiff > 0) {
					$(this).addClass('disabledl');
				}
				if ($('.slt .next').hasClass('disabledr')) {
					$('.slt .next').removeClass('disabledr');
				}
			}
		});
		$('.slt .next').click(function() {
			var ml = parseInt(mf.css('margin-left')) - mdiff;
			if (mclick && ml - mdiff * (mnum-1) > -mfwidth) {
				mclick = false;
				mf.animate({'margin-left': ml + 'px'}, 360, function(){mclick = true;});
				if (ml - mdiff * mnum <= -mfwidth) {
					$(this).addClass('disabledr');
				}	
				if ($('.slt .prev').hasClass('disabledl')) {
					$('.slt .prev').removeClass('disabledl');
				}
			}
		});	
	}
	if (parseInt(mf.css('margin-left')) == 0) {$('#move-left').addClass('disabledl');}
	if (mf.find('li').length <= 1) {$('#move-right').addClass('disabledr');}


 
var slHeight = 0;
	$('.sliderpro section .sl div ul li').each(function(){
	var lih = $(this).innerHeight();
	if (lih > slHeight) {
		slHeight = lih;
	}
		$('.sliderpro section .sl div').css('height', slHeight + 'px');
	});	
	

mfr = 0;	
	mfr = $('.sliderpro section ul');
	if (mfr.length > 0) {
		var mdiff = 0;
		var mnum = 6;
		var mclick = true;
		var mli = $('li:first', mfr);
		var mdiff = 143;
		var mfwidth = mfr.children().length * mdiff;
		mfr.width(mfwidth);
		$('.sliderpro .prev').click(function() {
			var ml = parseInt(mfr.css('margin-left')) + mdiff;
			if (mclick && ml <= 0) {
				mclick = false;
				mfr.animate({'margin-left': ml + 'px'}, 360, function(){mclick = true;});
				if (ml+mdiff > 0) {
					$(this).addClass('disabledl');
				}
				if ($('.sliderpro .next').hasClass('disabledr')) {
					$('.sliderpro .next').removeClass('disabledr');
				}
			}
		});
		$('.sliderpro .next').click(function() {
			var ml = parseInt(mfr.css('margin-left')) - mdiff;
			if (mclick && ml - mdiff * (mnum-1) > -mfwidth) {
				mclick = false;
				mfr.animate({'margin-left': ml + 'px'}, 360, function(){mclick = true;});
				if (ml - mdiff * mnum <= -mfwidth) {
					$(this).addClass('disabledr');
				}	
				if ($('.sliderpro .prev').hasClass('disabledl')) {
					$('.sliderpro .prev').removeClass('disabledl');
				}
			}
		});	
	}
	if (parseInt(mfr.css('margin-left')) == 0) {$('#move-left').addClass('disabledl');}
	if (mfr.find('li').length <= 1) {$('#move-right').addClass('disabledr');} 
	

	
	$('.sliderTov img').hover( 
	function() {
		$(this).addClass('hover');
	},
	function() {
		$(this).removeClass('hover');
	}); 
	


	$(".foto a").click(function(){
		$(".foto a img").removeClass('red');	
		$(".big img").hide().attr({"src": $(this).attr("href") + '?a=' + Math.random()});	
		$(this).find('img').addClass('red');
		$(".big>img").load(function(){$(".big>img:hidden").fadeIn("slow")});
		 return false;
	});
	
	
	
	var dsh = 0;
	$('.sol-des .desul').each(function(){
	var desh = $(this).innerHeight();
	if (desh > dsh) {
		dsh = desh;
	}});
	$('.sol-des .desul').css('height', dsh + 'px');
	

	
	Cufon.replace(".about-menu ul li a", {hover: true});


   $('.order-form-link').click(function() {
       //alert($(this).attr('ajax') + " " + $(this).attr('eid'));
       if($('.order-form').size() > 0) {
           $('.order-form').css('display', 'block');
           return;
       }
       
       $.post( $(this).attr('ajax'), {'ELEMENT_ID' : $(this).attr('eid')}, function(data) {
            $("body .container").append(data);
            $('.order-form').css({top:'20%',left:'50%',margin:'-'+($('.fb').height() / 2)+'px 0 0 -'+($('.fb').width() / 2)+'px'});

            initOrderForm();
       } ) ;
       return false;
   });


   $('.ask-question, .feedback, .question').click( function(){
        $('.fb').css('display', 'block');
        $('.fb').css("position","fixed");
        $('.fb').css({top:'50%',left:'50%',margin:'-'+($('.fb').height() / 2)+'px 0 0 -'+($('.fb').width() / 2)+'px'});
        return false;
    });
	$('.solutions-block').each(function(){
		$('.sol-des .sol-des-content').each(function(){
			$('.desul:last', this).css('background','none');
		});
		
	});
	
    $('.sliderpro .sl div ul').each(function() {
        if($(this).height() < 845)
        $('.sliderpro section .next').addClass('disabledr');
    });
	
    
});

function expandNode(css) {
	$('.' + css + '_fd').click();
}

function initOrderForm() {

   $('.order-form .close').click(function() {
       $('.order-form').css('display', 'none');
   });

   $('.order-form .add-position').click(function() {
       try {
       var html = $('.order-form .header div:first').html();

       $('.order-form .header').append('<div>' + html + '</div>');

       $('.order-form .header div:last select option').removeAttr('selected');

       $('.order-form .header div:last select option:first').attr('selected');
       $('.order-form .header div:last input').val('');
       } catch(E){}
       return false;
   });

    var opt = {success:    function(responseText, statusText, xhr, form) {
            try {
                eval('var data = ' + responseText);

                $('.order-form form .errors').html('');
                try {
                for(var i = 0; i < data.errors.length; i++) {
                    $('.order-form form .errors').append('<div>'+data.errors[i]+'</div>');
                }
                } catch(ee){}

                if(data.state == true) {
                    var href = location.href;
                    href = href.split('/');
                    if(href[3] == 'en'){
                        $('.order-form form .errors').html('Thank you for your address! Our manger will answer you in 48 hours.');
                    }else{
                        $('.order-form form .errors').html('Спасибо за Ваше обращение! Наш менеджер ответит Вам в течении 48 часов.');
                    }
                    setTimeout(location.reload(),900);
                }

                $('.order-form form .errors').removeClass('hide');
            } catch(E){}
        }
    };

    $('.order-form form').ajaxForm(opt);
    
    $('.questionBlock > a.closeOpen').click(function(){
		$(this).parent('.questionBlock').toggleClass('act');
	}); 
}

$('.questionBlock > a.closeOpen').click(function(){
		$(this).parent('.questionBlock').toggleClass('act');
}); 

$('.questionBlock a.closeOpen').click(function(){	$('.right_block').toggleClass('rba');	}); 

function init_ring_form() {
	$(".order-call .panel form").submit(function(){
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data){
				$('.order-call .panel').html(data);
				init_ring_form();
			},
			dataType: 'txt'
		});
		return false;
	});
}
init_ring_form();


$(document).ready(function(){

	$('.send-coll .sc').click(function(){
		$(this).next('.sc-form').css('display','block');
	});
	
	$('.send-coll .sc-form .sc-close').click(function(){
		$(this).parents('.sc-form').css('display','none');
	});

        $("#send_link").attr('value', document.location.href);
        $("#form_sendlink").submit(function(){
               $.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data){
				$('#form_sendlink #result').html(data);
			},
			dataType: 'txt'
		});
		return false;
        });

});






