﻿$(document).ready(function(){
	setTimeout(function() { $('body').show(); }, 300)
if ( $.browser.msie &&$.browser.version <=8) {
	$('#center_circle_big').each(function() {
        PIE.attach(this);
    });

}
$('#main_back').css('background','url("../images/main/spot.png") no-repeat scroll center center transparent')

$('#work_place, #center_circle').mouseenter(function(){
$('.main_level_one_menu_item_air').animate({ opacity: "hide" }, "slow");
});

	var check_border=false;
/*$('.main_level_one_menu_item_name').mouseenter(function(){
	$(this).parent('.main_level_one_menu_item').find('.main_level_two_menu').animate({ opacity: "show" }, "slow");
}).mouseleave(function (){
	$(this).parent('.main_level_one_menu_item').find('.main_level_two_menu').animate({ opacity: "hide" }, "slow");
});*/

$('.main_level_one_menu_item').mouseenter(function(){

	if($(this).find('.main_level_two_menu').css('display')!='block')
		$('.main_level_one_menu_item_air').animate({ opacity: "hide" }, 500);

	$(this).find('.main_level_one_menu_item_border').animate({ opacity: "show" }, 00);
		check_border=false;
}).mouseleave(function (){
	if(!check_border){
		if($(this).find('.main_level_two_menu').css('display')!='block')
			$(this).find('.main_level_one_menu_item_border').animate({ opacity: "hide" }, 00);
	}
});


$('.main_level_one_menu_item').click(function(){

$('.main_level_one_menu_item_border').hide();

	if($(this).find('.main_level_one_menu_item_border').css('display','none')){
		$(this).find('.main_level_one_menu_item_border').animate({ opacity: "show" }, 00);
		check_border=true;
	} else
	check_border=false;

 /*	$('.main_level_two_menu').find('a img').each(function(){
	if($(this).css('height')!='0px')
		$(this).animate({ height: "0px", width: "0px"}, 0);
	});*/

			if($(this).find('.main_level_two_menu').css('display')=='none'){

				//$('.main_level_two_menu').hide();
			 /*	$('.main_level_two_menu').find('a img').each(function(){
					if($(this).css('height')!='0px')
						$(this).animate({ height: "0px", width: "0px"}, 0);
				});*/
				if($('#main_private_client_level_two_menu').css('display')!='none'){
					setTimeout(function() {$('#main_sheep').find('a img').animate({ height: "0", width: "0"}, 1000) }, 1200)
					setTimeout(function() {$('#main_medecine').find('a img').animate({ height: "0", width: "0"}, 1000) }, 900)
					setTimeout(function() {$('#main_ipoteka').find('a img').animate({ height: "0", width: "0"}, 1000) }, 600)
					setTimeout(function() { $('#main_pravo').find('a img').animate({ height: "0", width: "0"}, 1000) }, 300)
					setTimeout(function() {$('#main_dom').find('a img').animate({ height: "0", width: "0"}, 1000) }, 0)
					setTimeout(function() {$('#main_kasko').find('a img').animate({ height: "0", width: "0"}, 1000) }, 300)
					setTimeout(function() {$('#main_imushestvo').find('a img').animate({ height: "0", width: "0"}, 1000) }, 600)
					setTimeout(function() {$('#main_kvartira').find('a img').animate({ height: "0", width: "0"}, 1000) }, 900)
					setTimeout(function() {$('#main_otvetstvennost').find('a img').animate({ height: "0", width: "0"}, 1000) }, 1200)
					setTimeout(function() {$('#main_private_client_level_two_menu').hide()}, 2200)
				}
				 if($('#main_corp_client_level_two_menu').css('display')!='none'){
					setTimeout(function() {$('#main_ur_kasko').find('a img').animate({ height: "0", width: "0"}, 1000) }, 1200)
					setTimeout(function() {$('#main_personal').find('a img').animate({ height: "0", width: "0"}, 1000) }, 900)
					setTimeout(function() {$('#main_gruzoperevozki').find('a img').animate({ height: "0", width: "0"}, 1000) }, 600)
					setTimeout(function() {$('#main_ur_otvetstvennost').find('a img').animate({ height: "0", width: "0"}, 1000) }, 300)
					setTimeout(function() {$('#main_riski').find('a img').animate({ height: "0", width: "0"}, 1000) }, 0)
					setTimeout(function() {$('#main_transport').find('a img').animate({ height: "0", width: "0"}, 1000) }, 300)
					setTimeout(function() {$('#main_sh').find('a img').animate({ height: "0", width: "0"}, 1000) }, 600)
					setTimeout(function() {$('#main_zdaniya').find('a img').animate({ height: "0", width: "0"}, 1000) }, 900)
					setTimeout(function() {$('#main_obekty').find('a img').animate({ height: "0", width: "0"}, 1000) }, 1200)
					setTimeout(function() {$('#main_corp_client_level_two_menu').hide()}, 2200)
				}
				 if($('#main_about_company_level_two_menu').css('display')!='none'){
					setTimeout(function() {$('#main_newspaper').find('a img').animate({ height: "0", width: "0"}, 1000) }, 600)
					setTimeout(function() {$('#main_mission').find('a img').animate({ height: "0", width: "0"}, 1000) }, 300)
					setTimeout(function() {$('#main_partners_list').find('a img').animate({ height: "0", width: "0"}, 1000) }, 0)
					setTimeout(function() {$('#main_vacansy').find('a img').animate({ height: "0", width: "0"}, 1000) }, 300)
					setTimeout(function() {$('#main_contacts_list').find('a img').animate({ height: "0", width: "0"}, 1000) }, 600)
					setTimeout(function() {$('#main_about_company_level_two_menu').hide()}, 1600);
				}
				 if($('#main_level_two_menu_calcs').css('display')!='none'){
					setTimeout(function() {$('#main_calc_kasko').find('a img').animate({ height: "0", width: "0"}, 1000) }, 300)
					setTimeout(function() {$('#main_calc_osago').find('a img').animate({ height: "0", width: "0"}, 1000) }, 0)
					setTimeout(function() {$('#main_about_company_level_two_menu').hide()}, 1000);
				}
				$(this).find('.main_level_two_menu').animate({ opacity: "show" }, 3000);
				if($(this).attr('id')=='main_private_client'){
				 /*	$('#main_sheep').animate({path : new $.path.arc({center: [-180,80],radius: 250, start: 160, end: 210, dir: 1})})
					$('#main_medecine').animate({path : new $.path.arc({center: [-180,80],radius: 230, start: 140, end: 175, dir: 1})})
					$('#main_ipoteka').animate({path : new $.path.arc({center: [-180,80],radius: 250, start: 120, end: 150, dir: 1})})
					$('#main_pravo').animate({path : new $.path.arc({center: [-180,80],radius: 250, start: 100, end: 130, dir: 1})})
					$('#main_kasko').animate({path : new $.path.arc({center: [-180,80],radius: 250, start: 100, end: 87, dir: -1})})
					$('#main_imushestvo').animate({path : new $.path.arc({center: [-180,80],radius: 250, start: 90, end: 70, dir: -1})})
					$('#main_kvartira').animate({path : new $.path.arc({center: [-180,80],radius: 250, start: 80, end: 50, dir: -1})})
					$('#main_otvetstvennost').animate({path : new $.path.arc({center: [-180,80],radius: 250, start: 70, end: 30, dir: -1})})
			*/
					setTimeout(function() {$('#main_sheep').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 1200)
					setTimeout(function() {$('#main_medecine').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 900)
					setTimeout(function() {$('#main_ipoteka').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 600)
					setTimeout(function() { $('#main_pravo').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 300)
					setTimeout(function() {$('#main_dom').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 0)
					setTimeout(function() {$('#main_kasko').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 300)
					setTimeout(function() {$('#main_imushestvo').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 600)
					setTimeout(function() {$('#main_kvartira').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 900)
					setTimeout(function() {$('#main_otvetstvennost').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 1200)

				}else if($(this).attr('id')=='main_about_company'){
					setTimeout(function() {$('#main_newspaper').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 600)
					setTimeout(function() {$('#main_mission').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 300)
					setTimeout(function() {$('#main_partners_list').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 0)
					setTimeout(function() {$('#main_vacansy').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 300)
					setTimeout(function() {$('#main_contacts_list').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 600)
				}else if($(this).attr('id')=='main_corp_client'){
					setTimeout(function() {$('#main_ur_kasko').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 1200)
					setTimeout(function() {$('#main_personal').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 900)
					setTimeout(function() {$('#main_gruzoperevozki').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 600)
					setTimeout(function() {$('#main_ur_otvetstvennost').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 300)
					setTimeout(function() {$('#main_riski').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 0)
					setTimeout(function() {$('#main_transport').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 300)
					setTimeout(function() {$('#main_sh').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 600)
					setTimeout(function() {$('#main_zdaniya').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 900)
					setTimeout(function() {$('#main_obekty').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 1200)
				}else if($(this).attr('id')=='main_calcs'){
					setTimeout(function() {$('#main_calc_kasko').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 300)
					setTimeout(function() {$('#main_calc_osago').find('a img').animate({ height: "100%", width: "100%"}, 1000) }, 0)
				}

			}


});




$('.main_level_two_menu').mouseenter(function(){
	var parent_id=$(this).parent('.main_level_one_menu_item').attr('id');
	$('.main_level_one_menu_item').each(function(){
		if($(this).attr('id')!=parent_id)
		$(this).find('.main_level_one_menu_item_air').animate({ opacity: "show" }, 500);
	});
});

$('.main_level_two_menu_item').mouseenter(function(){
	$(this).find('img').animate({ opacity: "0.5" }, 0);
	$(this).find('.menu_item_title').animate({ opacity: "show" }, 0);

	//$('.main_level_one_menu_item_air').animate({ opacity: "show" }, "slow");
	//$(this).parent().parent('.main_level_one_menu_item').find('.main_level_one_menu_item_air').hide();

}).mouseleave(function (){
	$(this).find('img').animate({ opacity: "1" }, 0);
	$(this).find('.menu_item_title').animate({ opacity: "hide" }, 0);

});

/*var elements = document.getElementById('main_level_one_menu').getElementsByTagName('div');
 // получаем массив координат, основанный на количестве элементов
 var coords = getCoords(elements.length, {radius: 300});

 // с помощью margin двигаем каждый элемент в соответствующее положение
 for (var i = 0; i < elements.length; i++) {
     elements[i].style.marginLeft = coords[i][0] + 'px';
     elements[i].style.marginTop = coords[i][1] + 'px';
 }*/


function getCoords(count, options) {
    if (count) {
        // замещаем опциональными параметрами дефолтные значения
        var options = options || {};
        // положительное целое, чтоб провести расчет так,
        // будто элементов на +n больше
        options.pseudoCount = options.pseudoCount || 0;
        options.radius = options.radius || 200;
        options.angle = options.angle || 0;
        // количество «долек»
        var n       = count + options.pseudoCount;
        var posArr  = [], x, y;

        // для каждого из элементов считаем координаты
        for (var i = 0; i < count; i++) {
            x = Math.cos((i + options.angle) * (Math.PI * 2 / n)) * options.radius;
            y = Math.sin((i + options.angle) * (Math.PI * 2 / n)) * options.radius;

            // вставляем в массив
            posArr.push([x, y]);
        }

        return posArr;
    // возвращаем ошибку если не передано кол-во элементов
    } else {return false;}
}

});


var x,y,obj,corner;
var pi=Math.PI; // считаем число пи

function init_move_round(alfa,dalfa,beta,ro,centrX,centrY,Radius,obid,timeout) {
    var obj=document.getElementById(obid);
    x=obj.offsetLeft;
    y=obj.offsetTop;
    moveR(alfa,dalfa,beta,ro,x,y,centrX,centrY,Radius,obid,timeout);
}
function moveR(alfa,dalfa,beta,ro,x,y,centrX,centrY,Radius,obid,timeout){
/*
alfa - начальный угол
beta - на какой угол повернуть
dalfa - шаг угловой
ro - направление вращения 0 по часовой 1 против часовой
x - координаты точки по оси х
y - координаты точки по оси у
centrX - координата центра по оси х
centrY - координата центра по оси у
Radius - радиус
obid - id объекта
timeout - временной интервал
*/
    if(alfa==360||alfa==-360) alfa=0;
    obj=document.getElementById(obid);
    obj.style.left=x+"px";
    obj.style.top=y+"px";
    corner=2*pi-alfa/180*pi; // переводим градусы в радианы с учетом периода в 2 пи
    x = parseInt(Radius*Math.cos(corner) + centrX);  // считаем новые координаты точки по оси х
    y = parseInt(Radius*Math.sin(corner) + centrY);  // считаем новые координаты по оси у
    if(ro==1) alfa+=dalfa; else alfa-=dalfa; // определяем куда нам откладывать угол
    beta-=dalfa;
    if(beta>0) setTimeout("moveR("+alfa+","+dalfa+","+beta+","+ro+","+x+","+y+","+centrX+","+centrY+","+Radius+",'"+obid+"',"+timeout+")" , timeout); else return true; // рекурсивно замыкаем нашу функцию для эфекта вращения
}
