$(document).ready(function(){
	$("#count").click(function(event){
		source = 	$("#source :selected").val()
		destination = $("#destination :selected").val()
		if (source == destination) {
			price = 1500 //1 district
		} else if (source < 20 && destination < 20) {
			price = 1500 //center
		} else if (Math.abs(Math.floor(source / 10) - Math.floor(destination / 10)) == 1 && source < 30 && destination < 30) {
			price = 1500 //from 1 to 2 circle
		} else if (Math.floor(source / 10) == 2 && Math.floor(destination / 10) == 2) {
			if (Math.abs(source  - destination) == 1) {
				price = 1500	//2 circle near																															
			} else {
				price = 1500 //2 circle far		
			}
		} else if (Math.floor(source / 10) == 3 && Math.floor(destination / 10) == 3) {
			if (Math.abs(source  - destination) == 1) {
				price = 1500	//3 circle near																																		
			} else {
				price = 1500  //3 circle far	
			}
		} else if (Math.floor(source / 10) == 3 || Math.floor(destination / 10) == 3){
			if (source / 10 == 1 || destination / 10 == 1) {
				price = 1500 //from 1 to 3 circle	
			} else {
				if (Math.abs(source  - destination) - 10 < 2) {
					price = 1500 //from 2 to 3 circle	near
				} else {
					price = 1500 //from 2 to 3 circle	far
				}
			}
		}
		if ($("#gruz1").is(":checked")) {price = price + 0}
		if ($("#gruz2").is(":checked")) {price = price + 0}
		if ($("#lift1").is(":checked")) {price = price + 0}
		if ($("#lift2").is(":checked")) {price = price + 0}
		if ($("#bath").is(":checked")) {price = price + 0}
		$("#result").html('Стоимость: от ' + price + 'р');
		event.preventDefault()
	})
	
	$("#fly").mouseenter(function(event){
		var $fly = $("#fly")
		if(!$fly.hasClass('in_action')) {
			$fly.addClass('in_action').animate({right:'0px', opacity: '1'}, 500,function(){$fly.removeClass('in_action')});
		}
		})
	
	$("#fly").mouseleave(function(event){
		var $fly = $("#fly")
		if(!$fly.hasClass('in_action')) {
			$fly.addClass('in_action').animate({right:'-154px', opacity: '0.8' }, 500,function(){$fly.removeClass('in_action')});
		}
		})
	
	$("#order_phone").click(function(event){
		num = $("#number").val();
		$.getJSON("/sms.php",{'number': num},function(data){
			alert('Мы Вам обязательно перезвоним!');
			$("#fly").mouseleave();
		})
	})
	
	$("#link").click(function(event){
		if ($("#fly").css('right') == '-154px') {$("#fly").mouseenter()} else {$("#fly").mouseleave()}
	})
	
	$(function(){
			$(".blinkingText").hide();
			setTimeout(function(){$(".blinkingText").show();setInterval(function(){$(".blinkingText").toggle();},500)},300);			
		});
	
});
function checkMsg()
        {
            if (document.msender.phone.value.length<1||document.msender.person.value.length<1) {
                document.getElementById('alert').innerHTML="Заполните, пожалуйста, все обязательные поля";
                return false; }
            if (document.msender.kapcha.value!=numbers[document.getElementById('number').innerHTML]) {
                document.getElementById('alert').innerHTML="Неверно введено число";
                return false;}
            return true;
        }
    function kapcha()
{
	rand = Math.floor(Math.random()*6);
	words = new Array ("Два", "Пять", "Десять", "Сто тридцать семь", "Пятьдесят три", "Тридцать шесть");
	numbers = new Array ();
	numbers["Два"] = 2; 
	numbers["Пять"] = 5;
	numbers["Десять"] = 10;
	numbers["Сто тридцать семь"] = 137;
	numbers["Пятьдесят три"] = 53;
	numbers["Тридцать шесть"] = 36;
	document.getElementById('number2').innerHTML=words[rand];
}
