jQuery.preloadimg = function() {
jQuery.each (arguments,function (e) {
       jQuery("<img>").attr("src", this);
  });
}
$.preloadimg("/img/p1.jpg", "/img/p2.jpg", "/img/p3.jpg", "/img/p4.jpg", "/img/p5.jpg");
var animate = new Array(
'<img src="/img/p1.jpg" alt="" />', '<img src="/img/p2.jpg" alt="" />','<img src="/img/p3.jpg" alt="" />', '<img src="/img/p4.jpg" alt="" />', '<img src="/img/p5.jpg" alt="" />');
			function reimg(id, colimg, count, timeload, timehide, timeshow)
			{					
				$("#"+id).fadeTo(timeload,1, function(){ //Время ожидания
					$("#"+id).fadeTo(timehide,0, function(){ //Время затухания
						count++;
						if (count == colimg){
							count=0;
						}
						$("#"+id).html(animate[count]);
						$("#"+id).fadeTo(timeshow,1, function(){ //Время оттухания
							reimg(id, colimg, count, timeload, timehide, timeshow);
						});							
					});
				});	
			}


$(function(){
reimg('pp',5,0,11000,1000,1000);

 
     var urltxt;
    urltxt = location.href;
    var ar=urltxt.split('/');
    var newurl=ar.slice(3,ar.length).join('/');
	
    $(".navi a").each(
        function(){
            if($(this).attr("href")=="/"+newurl)
            {
				$(this).parents('.one_block').addClass('current');
                $(this).replaceWith("<span>"+ $(this).text() +"</span>");
				
				if(newurl!==''){
					$('.path span, .path i').remove(); 
					$('.path').append('<i></i><span>'+ $(this).text() +'</span>');
				}
				else{
				$('.path a').replaceWith('<span>'+ $(this).text() +'</span><i></i>')
				}
            }
        }
        );


		$('.content table tr:odd').addClass('tr_second');
		$('.galery_img').lightBox();

});

function send_mail_response(){
	$(".system_msg").html("Сообщение отправлено, и в ближайшее время будет просмотрено!");
	$("#name").attr("value","");
	$("#tel").attr("value","");
	$("#mail").attr("value","");
	$("#city").attr("value","");
	$("#company").attr("value","");
	$("#message").attr("value","");
	$("#captcha_code").attr("value","");
}

function sendMessage(){
	fio_ = $("#name").attr("value");
	email_ = $("#mail").attr("value");
	phone_ = $("#tel").attr("value");
	city_ = $("#city").attr("value");
	company_ = $("#company").attr("value");
	message_ = $("#message").attr("value");
	captcha_code_ = $("#captcha_code").attr("value");
	
	if (!fio_ || !email_ || !phone_ || !message_ || !company_ || !phone_ || !city_ || !captcha_code_)
	{
		$(".system_msg").html("<span class='err'>Пожалуйста, заполните все поля!</span>");
		$('img.captcha').attr('src','/include/module/captcha.php?rand='+Math.random());
	}
	else
	{
			
		$.ajax({
        type:'POST',
        url: "/include/module/msg.php",
        dataType : "text",
			data:"fio="+fio_+"&email="+email_+"&phone="+phone_+"&message="+message_+"&company="+company_+"&city="+city_+"&captcha_code="+captcha_code_,
	        beforeSend:function(){},
        success: function(data) {
			send_mail_response();
            $('img.captcha').attr('src','/include/module/captcha.php?rand='+Math.random());
        }
    });	
	}
	return false;
} 

function send_calc_response(){
	$(".system_msg").html("Сообщение отправлено, и в ближайшее время будет просмотрено!");
	$("#from").attr("value","");
	$("#to").attr("value","");
	$("#cargo").attr("value","");
	$("#contacts").attr("value","");
	$("#weight").attr("value","");
	$("#size").attr("value","");
	$("#count").attr("value","");
	$("#message").attr("value","");
	$("#captcha_code").attr("value","");
}

function sendCalculate(){

	from_ = $("#from").attr("value");
	to_ = $("#to").attr("value");
	cargo_ = $("#cargo").attr("value");
	weight_ = $("#weight").attr("value");
	size_ = $("#size").attr("value");
	count_ = $("#count").attr("value");
	contacts_ = $("#contacts").attr("value");
	message_ = $("#message").attr("value");
	captcha_code_ = $("#captcha_code").attr("value");
	
	if (!from_ || !to_ || !cargo_ || !contacts_ || !weight_ || !size_ || !count_ || !captcha_code_)
	{
		$(".system_msg").html("<span class='err'>Пожалуйста, заполните все поля!</span>");
		$('img.captcha').attr('src','/include/module/captcha.php?rand='+Math.random());
	}
	else
	{
			
		$.ajax({
        type:'POST',
        url: "/include/module/calcmsg.php",
        dataType : "text",
			data:"from="+from_+"&to="+to_+"&cargo="+cargo_+"&message="+message_+"&weight="+weight_+"&contacts="+contacts_+"&size="+size_+"&count="+count_+"&captcha_code="+captcha_code_,
	        beforeSend:function(){},
        success: function(data) {
			send_calc_response();
            $('img.captcha').attr('src','/include/module/captcha.php?rand='+Math.random());
        }
    });	
	}
	return false;
} 
